-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (32 loc) · 1.09 KB
/
index.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
var express = require('express'),
path = require('path'),
fs = require('fs'),
busboy = require('connect-busboy'),
config = require('./config.json'),
app = express(),
dir = path.join(__dirname, 'public'),
domain = config.domain,
password = config.password,
port = config.port;
app.use('/', express.static(dir));
app.use(busboy());
app.get("/", (req, res) => {
res.send("server is works!")
});
app.post("/post", (req, res) => {
let pass = req.query.password;
if (!pass) return res.status(403).end();
if (pass !== password) return res.status(403).end();
var fstream;
req.pipe(req.busboy);
req.busboy.on('file', (fieldname, file, filename) => {
let namefile = filename.filename.replace(/ /g, "_");
console.log("Uploading: " + namefile + "\nFrom: " + req.ip);
fstream = fs.createWriteStream(`${process.cwd()}/public/${namefile}`);
file.pipe(fstream);
fstream.on('finish', () => {
res.status(200).send(`${domain}/${namefile}`)
})
})
});
app.listen(port, () => console.log("Ready!"));