fix: Replace `fs.createReadStream` with `res.sendFile`

Some [local installs (non-docker)](https://canary.discord.com/channels/848274994375294986/848313252009869312/1027077979580416050) may have issues with the filesystem calls used by `fs.createReadStream`. Discord user `Ryan#7385` showed that this fixed *something* (though not what we were actually troubleshooting)
pull/159/head
tycrek 2 years ago
parent 9055cfeaff
commit a36f944eba
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -83,11 +83,12 @@ router.get('/direct*', (req: Request, res: Response, next) => data().get(req.ass
.then((stream) => stream.pipe(res))
.then(() => SkynetDelete(fileData)),
local: () => fs.pathExists(path(fileData.path))
.then((exists) => {
if (!exists) throw new Error('File does not exist');
res.header('Accept-Ranges', 'bytes').header('Content-Length', `${fileData.size}`).type(fileData.mimetype);
fs.createReadStream(fileData.path).pipe(res);
})
.then((exists) => new Promise((resolve, reject) => !exists
? reject(new Error('File does not exist'))
: res.header('Accept-Ranges', 'bytes')
.header('Content-Length', `${fileData.size}`)
.type(fileData.mimetype)
.sendFile(path(fileData.path), (err) => err ? reject(err) : resolve(void 0))))
};
return uploaders[fileData.randomId.startsWith('sia://') ? 'sia' : s3enabled ? 's3' : 'local']();

Loading…
Cancel
Save