Update server.js
Browse files
server.js
CHANGED
|
@@ -46,11 +46,6 @@ app.all('/track/:id', async (req, res) => {
|
|
| 46 |
const { id } = req.params
|
| 47 |
if (!id) return res.json({ status: false, error: 'Track ID is not valid.' })
|
| 48 |
|
| 49 |
-
const search = await Spotify.search(id, 'track', 10)
|
| 50 |
-
const track = Array.isArray(search) ? search.find(v => v.id === id) : null
|
| 51 |
-
if (!track) return res.json({ status: false, error: 'not found' })
|
| 52 |
-
|
| 53 |
-
const title = track.title?.replace(/[\\/:*?"<>|]/g, '') || 'spotify_track'
|
| 54 |
const dl = await Spotify.download(`https://open.spotify.com/track/${id}`)
|
| 55 |
const url = dl?.download
|
| 56 |
if (!url) return res.json({ status: false, error: 'cant find download url!' })
|
|
@@ -61,7 +56,7 @@ app.all('/track/:id', async (req, res) => {
|
|
| 61 |
responseType: 'stream'
|
| 62 |
})
|
| 63 |
|
| 64 |
-
res.setHeader('Content-Disposition', `attachment; filename="${
|
| 65 |
res.setHeader('Content-Type', 'audio/mpeg')
|
| 66 |
response.data.pipe(res)
|
| 67 |
} catch (e) {
|
|
|
|
| 46 |
const { id } = req.params
|
| 47 |
if (!id) return res.json({ status: false, error: 'Track ID is not valid.' })
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
const dl = await Spotify.download(`https://open.spotify.com/track/${id}`)
|
| 50 |
const url = dl?.download
|
| 51 |
if (!url) return res.json({ status: false, error: 'cant find download url!' })
|
|
|
|
| 56 |
responseType: 'stream'
|
| 57 |
})
|
| 58 |
|
| 59 |
+
res.setHeader('Content-Disposition', `attachment; filename="${id}.mp3"`)
|
| 60 |
res.setHeader('Content-Type', 'audio/mpeg')
|
| 61 |
response.data.pipe(res)
|
| 62 |
} catch (e) {
|