Spaces:
Running
Running
fix(pdf-jobs): download端点补Content-Length——66.9MB取件事故随行修正——createReadStream().pipe()默认chunked无总长,客户端拿不到大小无法做下载预算/进度,chunked对部分idle型中间盒也不友好;statSync设置CL,stat失败退回chunked流式语义不变(2026-11-01瑞士PRO 44.2MB payload/66.9MB成品取件被客户端30s旧表误杀事故的配套修正,客户端侧stall-watchdog修复在XWXExporter仓库)
Browse files- lib/pdf-jobs.js +7 -0
lib/pdf-jobs.js
CHANGED
|
@@ -320,6 +320,13 @@ function createPdfJobService(cfg) {
|
|
| 320 |
res.setHeader('Content-Type', 'application/pdf');
|
| 321 |
res.setHeader('Content-Disposition', 'attachment; filename=export.pdf');
|
| 322 |
res.setHeader('Cache-Control', 'private, no-store');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
// 流式:首字节立刻出发,链路上任何 idle 型中间盒都不会再掐这条连接
|
| 324 |
const stream = fs.createReadStream(job.file);
|
| 325 |
stream.on('error', () => { if (!res.headersSent) res.status(410).json({ error: 'result_expired' }); else res.destroy(); });
|
|
|
|
| 320 |
res.setHeader('Content-Type', 'application/pdf');
|
| 321 |
res.setHeader('Content-Disposition', 'attachment; filename=export.pdf');
|
| 322 |
res.setHeader('Cache-Control', 'private, no-store');
|
| 323 |
+
// 显式 Content-Length:createReadStream().pipe() 默认 chunked 无总长,
|
| 324 |
+
// 客户端拿不到大小就无法做下载预算/进度,chunked 对部分中间盒也不友好
|
| 325 |
+
// (2026-11-01 66.9MB 取件事故随行修正)。
|
| 326 |
+
try {
|
| 327 |
+
const { size } = fs.statSync(job.file);
|
| 328 |
+
if (Number.isFinite(size) && size > 0) res.setHeader('Content-Length', String(size));
|
| 329 |
+
} catch { /* stat 失败退回 chunked,流式语义不变 */ }
|
| 330 |
// 流式:首字节立刻出发,链路上任何 idle 型中间盒都不会再掐这条连接
|
| 331 |
const stream = fs.createReadStream(job.file);
|
| 332 |
stream.on('error', () => { if (!res.headersSent) res.status(410).json({ error: 'result_expired' }); else res.destroy(); });
|