This commit is contained in:
Evert Prants 2018-10-10 13:02:56 +03:00
parent 6e8dc3a9fb
commit 53cf8c5744
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 11 additions and 1 deletions

View File

@ -178,6 +178,8 @@
queue.push(ctxState)
break
case 'download':
audio.pause()
window.open('/api/serve/by-id/' + ctxState + '?dl=1', '_blank')
break
}
ctxHide()

View File

@ -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) => {