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