Merge pull request #823 from Jasonzhu1207/main

fix(perf): prevent memory growth in chat and export flows
This commit is contained in:
cc
2026-04-23 18:41:04 +08:00
committed by GitHub
6 changed files with 243 additions and 70 deletions

View File

@@ -496,11 +496,20 @@ class HttpService {
const contentType = mimeTypes[ext] || 'application/octet-stream'
try {
const fileBuffer = fs.readFileSync(fullPath)
const stat = fs.statSync(fullPath)
res.setHeader('Content-Type', contentType)
res.setHeader('Content-Length', fileBuffer.length)
res.setHeader('Content-Length', stat.size)
res.writeHead(200)
res.end(fileBuffer)
const stream = fs.createReadStream(fullPath)
stream.on('error', () => {
if (!res.headersSent) {
this.sendError(res, 500, 'Failed to read media file')
} else {
try { res.destroy() } catch {}
}
})
stream.pipe(res)
} catch (e) {
this.sendError(res, 500, 'Failed to read media file')
}