fix: harden file previews and downloads

This commit is contained in:
Bohdan Triapitsyn
2026-06-13 01:44:03 +03:00
parent 823cefd4b5
commit ca87428216
7 changed files with 305 additions and 59 deletions
+10 -1
View File
@@ -243,12 +243,21 @@ export const createWebFilesAPI = ({ urls }: WebFilesAPIOptions): FilesAPI => ({
async downloadFile(path: string): Promise<void> {
const target = normalizePath(path);
const url = urls.rawFile(target, { download: true });
const response = await runtimeFetch('/api/fs/raw', {
query: { path: target, download: true },
});
if (!response.ok) {
throw new Error(`Download failed (${response.status})`);
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = target.split('/').pop() || 'file';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 100);
},
});