Download exists now
This commit is contained in:
parent
c66f324b20
commit
f9ca0c8adf
1 changed files with 15 additions and 0 deletions
15
index.js
15
index.js
|
@ -101,6 +101,21 @@ app.get("/video/*", (req, res) => {
|
|||
stream.pipe(res)
|
||||
})
|
||||
|
||||
app.get("/download/*", (req, res) => {
|
||||
var download = req.params[0]
|
||||
var downloadPath = path.join(directory, download)
|
||||
var downloadName = downloadPath.substring(downloadPath.lastIndexOf("/"))
|
||||
|
||||
if (!fs.existsSync(downloadPath)) {
|
||||
downloadPath = path.join(pubDir, download)
|
||||
}
|
||||
|
||||
res.setHeader('Content-disposition', `attachment; filename=${downloadName}`);
|
||||
|
||||
var stream = fs.createReadStream(downloadPath)
|
||||
stream.pipe(res)
|
||||
})
|
||||
|
||||
app.get("/*", (req, res) => {
|
||||
var file = req.params[0]
|
||||
var absPath = path.join(pubDir, file)
|
||||
|
|
Loading…
Reference in a new issue