-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
117 lines (111 loc) · 3.34 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var http = require("http");
var https = require("https");
var config = require("./config");
var controller = require("./controller");
var url = require('url');
var fs = require('fs');
/*
/ #=> status
/get/md5.json
returns
{scuess:true/false
body:{
type: "mp4",
size: xxxxx,
url : "",
]
}
}
# open only
/add #=> upload and hit ++
code:
base64edjson{
type:'md5'/'uksk'
uk:xxx,
sk:xxx
or
md5:'length:smd5:md5:crc32'
}
returns
{
scuess:true/false,
body :{
md5 : ""
}
}
/delete #=> hit-- and check upload
!!WARN!! it will not delete any data!!!
code:
md5
*/
if (config.load()){
var service = config.get('ssl')?https:http;
service.createServer(function(req,res){
var path = url.parse(req.url);
/*if (path.pathname.split('/')[1]=='add'){
controller.add(req,res);
return ;
}*/
//if (path.pathname.split('/')[1]=='delete'){
/* res.write(JSON.stringify({
'error':-1,
'msg':'unsupport action'
}));
res.end; */
// controller.delete(req,res);
// return ;
//}
if (path.pathname.split('/')[1]=='get' && (path.pathname.split('/')[2] || "") != ""){
controller.get(req,res,path.pathname.split('/')[2]);
return ;
}
res.writeHead(404, {"Content-Type": "application/json"});
res.write(JSON.stringify({
'error':-1,
'msg':'unsupport action',
body : {}
}));
res.end();
}).listen(2233);
var options = {
key: fs.readFileSync('./ssl/server.key'),
cert: fs.readFileSync('./ssl/server.crt'),
ca: fs.readFileSync('./ssl/ca.crt'),
requestCert: true,
rejectUnauthorized: false
};
https.createServer(options,function (req,res){
var path = url.parse(req.url);
if (req.client.authorized) {
if (path.pathname.split('/')[1]=='get' && (path.pathname.split('/')[2] || "") != ""){
controller.get(req,res,path.pathname.split('/')[2]);
return ;
}
if (path.pathname.split('/')[1]=='add' && (path.pathname.split('/')[2] || "") != ""){
controller.add(req,res,path.pathname.split('/')[2] );
return ;
}
if (path.pathname.split('/')[1]=='delete' && (path.pathname.split('/')[2] || "") != ""){
controller._delete(req,res,path.pathname.split('/')[2]);
return ;
}
res.writeHead(404, {"Content-Type": "application/json"});
res.write(JSON.stringify({
'error':-1,
'msg':'unsupport action',
'url' : req.url,
body : {}
}));
res.end();
} else {
res.writeHead(401, {"Content-Type": "application/json"});
res.write(JSON.stringify({
'error':-1,
'msg':'access forbidden',
body : {}
}));
res.end();
}
}).listen(2234);
}
// cookies