feat: filename-aware attachment download endpoint (Content-Disposition), preview download uses it (no popup flash)

This commit is contained in:
root
2026-10-17 11:07:00 +08:00
parent 6d686c1d69
commit a0aa77dfda
15 changed files with 120 additions and 99 deletions
+15
View File
@@ -147,6 +147,21 @@ export async function attachmentUploadRaw(ownerId: number, file: File, thumbB64?
return item;
}
export async function attachmentDownload(id: number): Promise<{ blob: Blob; file_name: string; mime?: string }> {
const r = await fetch(getServerUrl() + '/api/attachment_download', {
method: 'POST',
headers: { 'content-type': 'application/json', authorization: 'Bearer ' + getToken() },
body: JSON.stringify({ id }),
});
if (!r.ok) {
const j = await r.json().catch(() => null);
throw new Error(j?.error || '下载失败');
}
const file_name = decodeURIComponent(r.headers.get('x-file-name') || (r.headers.get('content-disposition') || '').match(/UTF-8''([^;]+)/)?.[1] || 'file');
const mime = r.headers.get('content-type') || undefined;
return { blob: await r.blob(), file_name, mime };
}
export const attachmentThumb = (id: number) =>
call<{ data_b64: string; mime?: string; file_name: string }>('attachment_thumb', { id });