Download exists now

This commit is contained in:
bingus_violet 2024-04-23 13:15:38 -05:00
parent c66f324b20
commit f9ca0c8adf

View file

@ -101,6 +101,21 @@ app.get("/video/*", (req, res) => {
stream.pipe(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) => { app.get("/*", (req, res) => {
var file = req.params[0] var file = req.params[0]
var absPath = path.join(pubDir, file) var absPath = path.join(pubDir, file)