forked from realdadfish/sparkleshare-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
103 lines (87 loc) · 3.04 KB
/
api.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
var deviceProvider = null;
var folderProvider = null;
var middleware = null;
var utils = require('./utils');
Api = function(app, dp, fp, mw) {
deviceProvider = dp;
folderProvider = fp;
middleware = mw;
app.post('/api/getAuthCode', middleware.validateLinkCode, function(req, res) {
deviceProvider.createNew(req.param('name'), req.linkCodeForUid, function(error, dev) {
res.json({
ident: dev.ident,
authCode: dev.authCode
});
});
});
app.get('/api/getFolderList', middleware.validateAuthCode, function(req, res, next) {
folderProvider.findAll(function(error, folders) {
if (error) { return next(error); }
utils.aclFilterFolderList(folders, req.currentUser);
var f = [];
for (var id in folders) {
if (folders.hasOwnProperty(id)) {
f.push({
name: folders[id].name,
id: folders[id].id,
type: folders[id].type
});
}
}
res.json(f);
});
});
app.get('/api/getFile/:folderId', [middleware.validateAuthCode, middleware.checkFolderAcl, middleware.loadFolder], function(req, res, next) {
var filename = req.param('name');
if (!filename) {
filename = 'file';
}
res.attachment(filename);
req.loadedFolder.getRawData(req,
function(error, data) {
if (error) { return next(error); }
res.write(data);
},
function(error, data) {
if (error) { return next(error); }
res.end();
}
);
});
app.get('/api/getFolderContent/:folderId', [middleware.validateAuthCode, middleware.checkFolderAcl, middleware.loadFolder], function(req, res, next) {
console.log(req.deviceAcl);
req.loadedFolder.getItems(req, function(error, list) {
if (error) { return next(error); }
res.json(list);
});
});
app.get('/api/getFolderRevision/:folderId', [middleware.validateAuthCode, middleware.checkFolderAcl, middleware.loadFolder], function(req, res, next) {
req.loadedFolder.getCurrentRevision(req, function(error, revision) {
if (error) { return next(error); }
res.json(revision);
});
});
app.get('/api/getAllItemCount/:folderId', [middleware.validateAuthCode, middleware.checkFolderAcl, middleware.loadFolder], function(req, res, next) {
req.loadedFolder.getAllItemCount(req, function(error, count) {
if (error) { return next(error); }
res.json(count);
});
});
app.get('/api/getFolderItemCount/:folderId', [middleware.validateAuthCode, middleware.checkFolderAcl, middleware.loadFolder], function(req, res, next) {
req.loadedFolder.getFolderItemCount(req, function(error, count) {
if (error) { return next(error); }
res.json(count);
});
});
app.get('/api/whoami', middleware.validateAuthCode, function(req, res, next) {
res.json({
login: req.currentUser.login,
name: req.currentUser.name,
deviceName: req.currentDevice.name
});
});
app.get('/api/ping', middleware.validateAuthCode, function(req, res, next) {
res.json("pong");
});
};
module.exports = Api;