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
+13
View File
@@ -357,6 +357,19 @@ const server = http.createServer(async (req, res) => {
return send(200, true, data);
}
// 附件下载(带原始文件名的 Content-Disposition,浏览器直接落盘)
if (req.method === 'POST' && route === '/api/attachment_download') {
const body = await readJson(req);
const data = commandsFor(auth.user_id).handleCommand('attachment_read', { id: Number(body.id) });
const buf = Buffer.from(data.data_b64, 'base64');
res.writeHead(200, {
'Content-Type': data.mime || 'application/octet-stream',
'Content-Length': buf.length,
'Content-Disposition': "attachment; filename*=UTF-8''" + encodeURIComponent(data.file_name || 'file')
});
return res.end(buf);
}
// 附件删除:本地清理 + 图床异步清理
if (req.method === 'POST' && route === '/api/attachment_delete') {
const body = await readJson(req);