diff --git a/modules/stuff.js b/modules/stuff.js index b7732a4..d890ac2 100644 --- a/modules/stuff.js +++ b/modules/stuff.js @@ -53,10 +53,14 @@ app.use(bodyParser.json({ function appGetFileType (app, wildcard, contentType, pageToRender) { app.get(wildcard, function (req, res) { let p = req.url.replace(/%20/g, ' ') - let fp = p.split('?') - fp.pop() - const fpath = './public/files' + fp.join('/') - if (req.query.stream) { + let fp = p + if (p.includes('?')) { + fp = p.split('?') + fp.pop() + fp = fp.join('/') + } + const fpath = './public/files' + fp + if (req.query.stream || !pageToRender) { const stat = fs.statSync(fpath) const fileSize = stat.size const range = req.headers.range @@ -98,8 +102,15 @@ function appGetFileType (app, wildcard, contentType, pageToRender) { }) } -appGetFileType(app, '/*.mp4', 'video/mp4', 'stuff/video') -appGetFileType(app, '/*.mp3', 'audio/mpeg', 'stuff/audio') +const fileTypes = [ + ['/*.mp4', 'video/mp4', 'stuff/video'], + ['/*.mp3', 'audio/mpeg', 'stuff/audio'], + ['/*.zip', 'application/zip'] +] + +fileTypes.forEach((t) => { + appGetFileType(app, t[0], t[1], t[2]) +}) app.get('/*', function (req, res) { let parsedUrl = req.url.replace(/%20/g, ' ')