mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
Stream file without loading to memory in /download-user-file (#172)
This commit is contained in:
@@ -313,17 +313,8 @@ app.get('/download-user-file', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
let buffer;
|
||||
try {
|
||||
buffer = await fs.readFile(getPathForUserFile(fileId));
|
||||
} catch (e) {
|
||||
console.log(`Error: file does not exist: ${getPathForUserFile(fileId)}`);
|
||||
res.status(500).send('File does not exist on server');
|
||||
return;
|
||||
}
|
||||
|
||||
res.setHeader('Content-Disposition', `attachment;filename=${fileId}`);
|
||||
res.send(buffer);
|
||||
res.sendFile(getPathForUserFile(fileId));
|
||||
});
|
||||
|
||||
app.post('/update-user-filename', (req, res) => {
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('/download-user-file', () => {
|
||||
.set('x-actual-token', 'valid-token')
|
||||
.set('x-actual-file-id', 'missing-fs-file');
|
||||
|
||||
expect(res.statusCode).toEqual(500);
|
||||
expect(res.statusCode).toEqual(404);
|
||||
});
|
||||
|
||||
it('returns an attachment file', async () => {
|
||||
|
||||
6
upcoming-release-notes/172.md
Normal file
6
upcoming-release-notes/172.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [Jackenmen]
|
||||
---
|
||||
|
||||
Changed budget file download endpoint to use less memory by using streams
|
||||
Reference in New Issue
Block a user