mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added zip type to stream, simplified filetypes to stream
This commit is contained in:
parent
7b9a0af287
commit
227fa36e6c
1 changed files with 17 additions and 6 deletions
|
@ -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
|
||||||
|
if (p.includes('?')) {
|
||||||
|
fp = p.split('?')
|
||||||
fp.pop()
|
fp.pop()
|
||||||
const fpath = './public/files' + fp.join('/')
|
fp = fp.join('/')
|
||||||
if (req.query.stream) {
|
}
|
||||||
|
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, ' ')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue