-
Notifications
You must be signed in to change notification settings - Fork 2
/
rest.js
63 lines (55 loc) · 1.8 KB
/
rest.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
(function() {
var api = require('./api');
module.exports = {
fileGet: function (req, res) {
var revisionNumber = parseInt(req.query.revisionNumber, 10);
api.fileGet(revisionNumber, req.params.fileid, function (err, code, file) {
if (err) {
res.send(code, err);
} else {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.send(code, JSON.stringify(file));
}
});
},
fileUpdate: function (req, res) {
var revisionNumber = parseInt(req.query.revisionNumber, 10);
var sessionId = req.query.sessionId;
api.fileUpdate(sessionId, revisionNumber, req.params.fileid, function (err, code, patches) {
if (err) {
res.send(code, err);
} else {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
if (patches) {
res.send(code, JSON.stringify(patches));
} else {
res.send(code);
}
}
});
},
filePatch: function (req, res) {
api.filePatch(req.params.fileid, req.body, function (err, code) {
if (err) {
res.send(code, err);
} else {
res.send(code);
}
});
},
fileJoin: function (req, res) {
var clientAlgorithms = req.query.algorithm;
if (!(clientAlgorithms instanceof Array)) {
clientAlgorithms = [clientAlgorithms];
}
api.fileJoin(req.params.fileid, req.user._id.toString(), clientAlgorithms, req.query.protocolVersion, function (err, code, join) {
if (err) {
res.send(code, err);
} else {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.send(code, JSON.stringify(join));
}
});
}
};
}).call(this);