-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdisbox-server.js
57 lines (46 loc) · 1.24 KB
/
disbox-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
const express = require('express');
var cors = require('cors')
var bodyParser = require('body-parser')
const disboxFile = require('./disbox-file');
const app = express();
const port = 8080;
app.use(cors())
app.use(bodyParser.json())
app.get('/files/get/:userId', (req, res) => {
disboxFile.getFileTree(req.params.userId, (err, data) => {
if (err) {
res.status(500).send(err);
}
res.send(data);
});
})
app.post('/files/update/:userId/:id', (req, res) => {
disboxFile.updateFile(req.params.userId, req.params.id, req.body, (err) => {
if (err) {
res.status(500).send(err);
}
res.send(req.params.id);
});
});
app.post('/files/create/:userId', (req, res) => {
disboxFile.createFile(req.params.userId, req.body, (err, data) => {
if (err) {
res.status(500).send(err);
} else {
console.log(data);
res.send(data.toString());
}
});
});
// TODO: Delete directory?
app.delete('/files/delete/:userId/:id', (req, res) => {
disboxFile.deleteFile(req.params.userId, req.params.id, (err) => {
if (err) {
res.status(500).send(err);
}
res.send(req.params.id);
});
});
app.listen(process.env.PORT, () => {
console.log(`Example app listening on port ${process.env.PORT}`)
})