fast72 commited on
Commit
f5299ac
·
verified ·
1 Parent(s): 1e0117f

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile (1) +7 -0
  2. package (2).json +11 -0
  3. server.js +61 -0
Dockerfile (1) 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 (2).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,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ let totalRequest = 0
14
+
15
+ app.use((req, res, next) => {
16
+ totalRequest++;
17
+ next();
18
+ });
19
+
20
+ app.all('/', async(req, res) => {
21
+ res.json({ uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4], totalRequest })
22
+ })
23
+
24
+ app.all('/search', async(req, res) => {
25
+ try {
26
+ const { q, type = "track", limit = 10 } = req.query || req.body
27
+ if(!q) return res.json({ status: false, error: '"q" parameter is undefined!'})
28
+
29
+ const search = await Spotify.search(q, type, limit)
30
+ //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
31
+ res.json(search);
32
+ } catch(e) {
33
+ res.json({ status: false, error: e || e.message })
34
+ }
35
+ })
36
+
37
+ app.all('/play', async(req, res) => {
38
+ try {
39
+ const { q } = req.query || req.body
40
+ if(!q) return res.json({ status: false, error: '"q" parameter is undefined!'})
41
+
42
+ const search = await Spotify.search(q, "track", 1)
43
+ //if(!Array.isArray(search)) return res.json({ status: false, error: 'Result is not array.'})
44
+ res.json({ status: true, result: Array.isArray(search) ? search[0] : search, download: `https://${req.hostname}/track/${search[0]?.id}` });
45
+ } catch(e) {
46
+ res.json({ status: false, error: e || e.message })
47
+ }
48
+ })
49
+
50
+ app.all('/track/:id', async(req, res) => {
51
+ try {
52
+ const { id } = req.params || res.params
53
+ if(!id) return res.json({ status: false, error: "Track ID is not valid." })
54
+ const spotify = await Spotify.download(`https://open.spotify.com/track/${id}`)
55
+ res.redirect(spotify?.download)
56
+ } catch(e) {
57
+ res.json({ status: false, error: e || e.message })
58
+ }
59
+ })
60
+
61
+ app.listen(PORT)