mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
File streaming
This commit is contained in:
@@ -49,7 +49,9 @@ app.use(bodyParser.json({
|
|||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/*.mp4', function (req, res) {
|
// app, '/*.mp4', 'video/mp4', 'stuff/video'
|
||||||
|
function appGetFileType (app, wildcard, contentType, pageToRender) {
|
||||||
|
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.split('?')
|
||||||
fp.pop()
|
fp.pop()
|
||||||
@@ -70,14 +72,14 @@ app.get('/*.mp4', function (req, res) {
|
|||||||
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
|
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
|
||||||
'Accept-Ranges': 'bytes',
|
'Accept-Ranges': 'bytes',
|
||||||
'Content-Length': chunksize,
|
'Content-Length': chunksize,
|
||||||
'Content-Type': 'video/mp4'
|
'Content-Type': contentType
|
||||||
}
|
}
|
||||||
res.writeHead(206, head)
|
res.writeHead(206, head)
|
||||||
file.pipe(res)
|
file.pipe(res)
|
||||||
} else {
|
} else {
|
||||||
const head = {
|
const head = {
|
||||||
'Content-Length': fileSize,
|
'Content-Length': fileSize,
|
||||||
'Content-Type': 'video/mp4'
|
'Content-Type': contentType
|
||||||
}
|
}
|
||||||
res.writeHead(200, head)
|
res.writeHead(200, head)
|
||||||
fs.createReadStream(fpath).pipe(res)
|
fs.createReadStream(fpath).pipe(res)
|
||||||
@@ -86,13 +88,18 @@ app.get('/*.mp4', function (req, res) {
|
|||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
let fname = p.split('/')
|
let fname = p.split('/')
|
||||||
fname = fname.pop()
|
fname = fname.pop()
|
||||||
res.render('stuff/video', {
|
res.render(pageToRender, {
|
||||||
path: p,
|
path: p,
|
||||||
fname,
|
fname,
|
||||||
url
|
url,
|
||||||
|
contentType
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
appGetFileType(app, '/*.mp4', 'video/mp4', 'stuff/video')
|
||||||
|
appGetFileType(app, '/*.mp3', 'audio/mpeg', 'stuff/audio')
|
||||||
|
|
||||||
app.get('/*', function (req, res) {
|
app.get('/*', function (req, res) {
|
||||||
let parsedUrl = req.url.replace(/%20/g, ' ')
|
let parsedUrl = req.url.replace(/%20/g, ' ')
|
||||||
|
Submodule public/moodle-test-userscript updated: cbfaffa70c...fe74436ab1
@@ -21,7 +21,7 @@
|
|||||||
<%= fname %>
|
<%= fname %>
|
||||||
</h2>
|
</h2>
|
||||||
</center>
|
</center>
|
||||||
<video id="videoPlayer" controls muted="muted" autoplay>
|
<video id="videoPlayer" controls>
|
||||||
<source src="<%= url %><%= path %>?stream=true" type="video/mp4">
|
<source src="<%= url %><%= path %>?stream=true" type="video/mp4">
|
||||||
</video>
|
</video>
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user