This repository has been archived by the owner on May 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
62 lines (61 loc) · 2.03 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
let http = require("http");
let api = require("./api");
let port;
if (!process.argv[2]){
port = 8888;
}else{
port = process.argv[2].match(/--port=(\d*)/gi)[0] ? parseInt(process.argv[2].replace(/--port=(\d+)/gi,"$1")) : 8888;
}
http.createServer((req,res)=>{
const CALLBACK = data=>{
data = JSON.stringify(data);
if(url.query.callback) data = url.query.callback + "(" + data + ")";
res.end(data);
};
res.writeHead(200,{
"Content-Type":"text/json;charset=utf-8"
});
let url = require("url").parse(req.url,true);
url.pathname = decodeURI(url.pathname);
if(url.pathname.substring(0,13)=="/search/song/"){
api.search(url.pathname.substring(13),CALLBACK,{type:"1"});
}else
if(url.pathname.substring(0,14)=="/search/album/"){
api.search(url.pathname.substring(14),CALLBACK,{type:"10"});
}else
if(url.pathname.substring(0,17)=="/search/playlist/"){
api.search(url.pathname.substring(17),CALLBACK,{type:"1000"});
}else
if(url.pathname.substring(0,15)=="/search/artist/"){
api.search(url.pathname.substring(15),CALLBACK,{type:"100"});
}else
if(url.pathname.substring(0,13)=="/search/user/"){
api.search(url.pathname.substring(13),CALLBACK,{type:"1002"});
}else
if(url.pathname.substring(0,11)=="/search/fm/"){
api.search(url.pathname.substring(11),CALLBACK,{type:"1009"});
}else
if(url.pathname.substring(0,7)=="/album/"){
api.getAlbum(url.pathname.substring(7),CALLBACK);
}else
if(url.pathname.substring(0,8)=="/detail/"){
api.getDetail(url.pathname.substring(8),CALLBACK);
}else
if(url.pathname.substring(0,10)=="/playlist/"){
api.getPlaylist(url.pathname.substring(10),CALLBACK);
}else
if(url.pathname.substring(0,6)=="/song/"){
api.getURL(url.pathname.substring(6),CALLBACK);
}else
if(url.pathname.substring(0,7)=="/lyric/"){
api.getLyric(url.pathname.substring(7),CALLBACK);
}else
if(url.pathname.substring(0,4)=="/mv/"){
api.getMV(url.pathname.substring(4),CALLBACK);
}else
{
res.end("汪汪汪???");
}
//以上是搜索信息的可能(1.0.0)
}).listen(port).on("error", (j)=>{console.error(j)});