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
+5
View File
@@ -70,6 +70,11 @@ const attThumb = await api(A, 'POST', '/api/attachment_thumb', { id: attAdd.body
ok(attThumb.body?.data?.data_b64 === Buffer.from('THUMBWEBPDATA').toString('base64'), 'attachment_thumb 返回缩略图内容', attThumb.body);
const attRead2 = await api(A, 'POST', '/api/attachment_read', { id: attAdd.body?.data?.item?.id }, T);
ok(attRead2.body?.data?.data_b64 === Buffer.from('ORIGDATA').toString('base64'), 'attachment_read 原图不受影响', attRead2.body);
// 下载端点(带原始文件名)
const dlAtt = await api(A, 'POST', '/api/attachment_download', { id: attAdd.body?.data?.item?.id }, T);
const dlText = await (dlAdd0 => dlAdd0)(fetch(A + '/api/attachment_download', { method: 'POST', headers: { 'content-type': 'application/json', authorization: 'Bearer ' + T }, body: JSON.stringify({ id: attAdd.body?.data?.item?.id }) }).then(async r => ({ s: r.status, ct: r.headers.get('content-type'), cd: r.headers.get('content-disposition'), t: await r.text() })));
ok(dlText.s === 200 && dlText.t === 'ORIGDATA' && /photo\.jpg/.test(dlText.cd), 'attachment_download 端点(文件名+内容)', { s: dlText.s, cd: dlText.cd, t: dlText.t.slice(0, 40) });
// PUT 原始二进制上传(新通道)
const rawUp = await fetch(A + '/sync/attachment/raw?owner=' + fpId + '&name=raw.bin&mime=application/octet-stream', {
method: 'PUT', headers: { authorization: 'Bearer ' + T, 'content-type': 'application/octet-stream' },