scnario commited on
Commit
5f44f17
·
verified ·
1 Parent(s): a7b1cd8

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +9 -2
server.js CHANGED
@@ -12,11 +12,18 @@ const stringify = (value) => {
12
 
13
  app.all('/play', async(req, res) => {
14
  const { q } = req.query || req.body
15
- if(!q) return res.json(stringify({ status: false, error: '"q" parameter is undefined!'}))
16
 
17
  const search = await Spotify.search(q, "track", 1)
18
  //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
19
- res.json({ result: Array.isArray(search) ? search[0] : search, download: `https://${req.hostname}/track/${search[0]?.id}` });
 
 
 
 
 
 
 
20
  })
21
 
22
  app.listen(PORT)
 
12
 
13
  app.all('/play', async(req, res) => {
14
  const { q } = req.query || req.body
15
+ if(!q) return res.json({ status: false, error: '"q" parameter is undefined!'})
16
 
17
  const search = await Spotify.search(q, "track", 1)
18
  //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
19
+ res.json({ status: true, result: Array.isArray(search) ? search[0] : search, download: `https://${req.hostname}/track/${search[0]?.id}` });
20
+ })
21
+
22
+ app.all('/track/:id', async(req, res) => {
23
+ const { id } = req.params || res.params
24
+ if(!id) return res.json({ status: false, error: "Track ID is not valid." })
25
+ const spotify = await Spotify.download(`https://open.spotify.com/track/${id}`)
26
+ res.direct(spotify?.download)
27
  })
28
 
29
  app.listen(PORT)