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

This commit is contained in:
Gan, Jimmy
2026-04-09 22:55:44 +08:00
parent 0420b0eb13
commit 1ff48ab86d
2 changed files with 26 additions and 4 deletions
+22
View File
@@ -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);
}