download
This commit is contained in:
parent
6e8dc3a9fb
commit
53cf8c5744
@ -178,6 +178,8 @@
|
||||
queue.push(ctxState)
|
||||
break
|
||||
case 'download':
|
||||
audio.pause()
|
||||
window.open('/api/serve/by-id/' + ctxState + '?dl=1', '_blank')
|
||||
break
|
||||
}
|
||||
ctxHide()
|
||||
|
10
server.js
10
server.js
@ -111,6 +111,7 @@ router.get('/track/:id', async (req, res, next) => {
|
||||
router.get('/playlists', async (req, res, next) => {
|
||||
let db = await dbPromise
|
||||
let playlists = await db.all('SELECT * FROM Playlist')
|
||||
|
||||
res.jsonp(playlists)
|
||||
})
|
||||
|
||||
@ -123,6 +124,7 @@ router.get('/playlist/:id', async (req, res, next) => {
|
||||
|
||||
let tracks = await db.all('SELECT trackId FROM PlaylistEntry WHERE playlistId = ?', id)
|
||||
playlist.tracks = tracks
|
||||
|
||||
res.jsonp(playlist)
|
||||
})
|
||||
|
||||
@ -132,8 +134,14 @@ router.get('/serve/by-id/:id', async (req, res, next) => {
|
||||
let track = await db.get('SELECT file FROM Track WHERE id = ?', id)
|
||||
if (!track) return next(new Error('404 file not found'))
|
||||
|
||||
let fpath = path.resolve(track.file)
|
||||
|
||||
res.set('Cache-Control', 'public, max-age=31557600')
|
||||
res.sendFile(path.resolve(track.file))
|
||||
if (req.query.dl && parseInt(req.query.dl) === 1) {
|
||||
return res.download(fpath)
|
||||
}
|
||||
|
||||
res.sendFile(fpath)
|
||||
})
|
||||
|
||||
router.use((err, req, res, next) => {
|
||||
|
Loading…
Reference in New Issue
Block a user