feat: filename-aware attachment download endpoint (Content-Disposition), preview download uses it (no popup flash)
This commit is contained in:
@@ -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 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user