Added zip type to stream, simplified filetypes to stream

This commit is contained in:
MrFry 2019-11-10 09:43:32 +01:00
parent 7b9a0af287
commit 227fa36e6c

View file

@ -53,10 +53,14 @@ app.use(bodyParser.json({
function appGetFileType (app, wildcard, contentType, pageToRender) { function appGetFileType (app, wildcard, contentType, pageToRender) {
app.get(wildcard, function (req, res) { app.get(wildcard, function (req, res) {
let p = req.url.replace(/%20/g, ' ') let p = req.url.replace(/%20/g, ' ')
let fp = p.split('?') let fp = p
fp.pop() if (p.includes('?')) {
const fpath = './public/files' + fp.join('/') fp = p.split('?')
if (req.query.stream) { fp.pop()
fp = fp.join('/')
}
const fpath = './public/files' + fp
if (req.query.stream || !pageToRender) {
const stat = fs.statSync(fpath) const stat = fs.statSync(fpath)
const fileSize = stat.size const fileSize = stat.size
const range = req.headers.range const range = req.headers.range
@ -98,8 +102,15 @@ function appGetFileType (app, wildcard, contentType, pageToRender) {
}) })
} }
appGetFileType(app, '/*.mp4', 'video/mp4', 'stuff/video') const fileTypes = [
appGetFileType(app, '/*.mp3', 'audio/mpeg', 'stuff/audio') ['/*.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) { app.get('/*', function (req, res) {
let parsedUrl = req.url.replace(/%20/g, ' ') let parsedUrl = req.url.replace(/%20/g, ' ')