-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
50 lines (39 loc) · 1.07 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
/*
* Fake CDN
*/
var express = require("express");
var compression = require("compression");
var app = express();
app.use(compression());
app.get("/kurjun/rest/raw/id", function (req, res) {
var name = req.query["name"];
res.type("text/plain");
res.sendFile("id/" + name, {root: "./"});
});
app.get("/kurjun/rest/raw/info", function (req, res) {
var name = req.query["name"];
var id = req.query["id"];
res.type("text/plain");
if (name) {
res.sendFile("info/" + name, {root: "./"});
} else {
res.sendFile("info/" + id, {root: "./"});
}
});
app.get("/kurjun/rest/raw/download", function (req, res) {
var name = req.query["name"];
var id = req.query["id"];
if (name) {
res.download("download/" + name);
} else if (id) {
var fs = require('fs');
var json = JSON.parse(fs.readFileSync('./info/' + id, 'utf8'));
res.download("download/" + json.name);
} else {
res.status(404).send('Not found');
}
});
app.listen(18338);
/*
* vim: ts=4 et nowrap autoindent
*/