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) {
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, ' ')