Checking if file exists before streaming

This commit is contained in:
MrFry 2019-11-10 15:56:43 +01:00
parent 3a7818b403
commit a16b950ab1

View file

@ -60,6 +60,13 @@ function appGetFileType (app, wildcard, contentType, pageToRender) {
fp = fp.join('/') fp = fp.join('/')
} }
const fpath = './public/files' + fp const fpath = './public/files' + fp
if (!fs.existsSync(fpath)) {
res.render('stuff/nofile', {
missingFile: fpath,
url
})
return
}
if (req.query.stream || !pageToRender) { if (req.query.stream || !pageToRender) {
const stat = fs.statSync(fpath) const stat = fs.statSync(fpath)
const fileSize = stat.size const fileSize = stat.size