-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
80 lines (69 loc) · 1.49 KB
/
upload.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
var http = require("http");
var fs = require("fs");
http.createServer(function(req,res){
var imaps = req.url.split("/");
var maps = [];
imaps.forEach(function(m){
if(m){
maps.push(m);
}
});
switch(maps[0]){
case "index":
var str = fs.readFileSync("./index.html");
res.writeHead(200,{"Content-Type":"text/html"});
res.end(str,"utf-8");
break;
case "upl":
var str = fs.readFileSync("./upload.html");
res.writeHead(200,{"Content-Type":"text/html"});
res.end(str,"utf-8");
break;
case "upload":
break;
default:
var path = maps.join("/");
var value = "";
var filename = maps[maps.length - 1];
var checkReg = /^.+.(gif|png|jpg|css|js)+$/;
if(maps[0]=="databox"){
checkReg = /.*/;
}
if(checkReg.test(filename)){
try{
value = fs.readFileSync(path);
}catch(e){}
}
if(value){
res.end(value);
}else {
res.writeHead(404);
res.end("404 Not Found");
}
break;
}
var chunks = [];
var size = 0;
req.on("data",function(chunk){
chunks.push(chunk);
size+=chunk.length;
});
req.on("end",function(){
var buffer = Buffer.concat(chunks,size);
if(!size){
res.writeHead(404);
res.end("");
return;
}
var rems = [];
for(var i = 0,l = buffer.length;i<l;i++){
var v = buffer[i];
var v2 = buffer[i+1];
if(v==13 && v2==10 ){
rems.push(i);
}
}
var picmsg_1 = buffer.slice(rems[0]+2,rems[1]).toString();
var filename = picmsg_1.match(/filename=".*"/g)[0].split
});
}).listen(8000);