scnario commited on
Commit
c346db5
·
verified ·
1 Parent(s): 61021a1

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -0
  2. package.json +11 -0
  3. server.js +50 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM node:latest
2
+ WORKDIR /app
3
+ COPY package*.json ./
4
+ RUN npm install
5
+ COPY . .
6
+ EXPOSE 7860
7
+ CMD ["node", "server.js"]
package.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "main": "server.js",
3
+ "scripts": {
4
+ "start": "node server.js"
5
+ },
6
+ "dependencies": {
7
+ "express": "*",
8
+ "axios": "*",
9
+ "cheerio": "*"
10
+ }
11
+ }
server.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const axios = require('axios');
3
+ const Spotify = require('./lib/spotify.js');
4
+
5
+ const app = express()
6
+ app.set('json spaces', 2)
7
+ const PORT = 7860
8
+
9
+ const stringify = (value) => {
10
+ return JSON.stringify(value, null, 2)
11
+ }
12
+
13
+ app.all('/search', async(req, res) => {
14
+ try {
15
+ const { q, type = "track", limit = 10 } = req.query || req.body
16
+ if(!q) return res.json({ status: false, error: '"q" parameter is undefined!'})
17
+
18
+ const search = await Spotify.search(q, type, limit)
19
+ //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
20
+ res.json(search);
21
+ } catch(e) {
22
+ res.json({ status: false, error: e || e.message })
23
+ }
24
+ })
25
+
26
+ app.all('/play', async(req, res) => {
27
+ try {
28
+ const { q } = req.query || req.body
29
+ if(!q) return res.json({ status: false, error: '"q" parameter is undefined!'})
30
+
31
+ const search = await Spotify.search(q, "track", 1)
32
+ //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
33
+ res.json({ status: true, result: Array.isArray(search) ? search[0] : search, download: `https://${req.hostname}/track/${search[0]?.id}` });
34
+ } catch(e) {
35
+ res.json({ status: false, error: e || e.message })
36
+ }
37
+ })
38
+
39
+ app.all('/track/:id', async(req, res) => {
40
+ try {
41
+ const { id } = req.params || res.params
42
+ if(!id || !id.length > 21) return res.json({ status: false, error: "Track ID is not valid." })
43
+ const spotify = await Spotify.download(`https://open.spotify.com/track/${id}`)
44
+ res.redirect(spotify?.download)
45
+ } catch(e) {
46
+ res.json({ status: false, error: e || e.message })
47
+ }
48
+ })
49
+
50
+ app.listen(PORT)