fix: add authentication to file downloads
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 2m24s
Run Tests / Backend Tests (push) Failing after 4m13s
Run Tests / Frontend Tests (push) Failing after 3m53s
Run Tests / Test Summary (push) Failing after 13s
Run Tests / Backend Tests (pull_request) Failing after 4m13s
Run Tests / Frontend Tests (pull_request) Failing after 2m58s
Run Tests / Test Summary (pull_request) Failing after 18s
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 2m24s
Run Tests / Backend Tests (push) Failing after 4m13s
Run Tests / Frontend Tests (push) Failing after 3m53s
Run Tests / Test Summary (push) Failing after 13s
Run Tests / Backend Tests (pull_request) Failing after 4m13s
Run Tests / Frontend Tests (pull_request) Failing after 2m58s
Run Tests / Test Summary (pull_request) Failing after 18s
This commit is contained in:
@@ -197,3 +197,25 @@ export function getInfoEngineItem(id) {
|
||||
export function put(path, data) {
|
||||
return request(path, { method: "PUT", json: data });
|
||||
}
|
||||
|
||||
export async function download(path, filename) {
|
||||
const headers = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
|
||||
const r = await fetch(`${BASE}/files/download?path=${encodeURIComponent(path)}`, {
|
||||
method: "GET",
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
|
||||
const blob = await r.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user