Fix crash if file is missing from`uploads/` (closes #103) (#112)

pull/104/head^2
Josh Moore 2 years ago committed by GitHub
parent a2aa4d58bc
commit fc82a6d6b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -74,10 +74,12 @@ router.get('/direct*', (req: AssRequest, res: AssResponse, next) => data.get(req
sia: () => SkynetDownload(fileData)
.then((stream) => stream.pipe(res))
.then(() => SkynetDelete(fileData)),
local: () => {
res.header('Accept-Ranges', 'bytes').header('Content-Length', `${fileData.size}`).type(fileData.mimetype);
fs.createReadStream(fileData.path).pipe(res);
}
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);
})
};
return uploaders[fileData.randomId.startsWith('sia://') ? 'sia' : s3enabled ? 's3' : 'local']();

Loading…
Cancel
Save