-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathendpoints.js
60 lines (54 loc) · 1.38 KB
/
endpoints.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
var platform = require('./platform');
var fs = require('fs');
var headerTemplate = '';
exports.init = function(completion)
{
if (headerTemplate == '')
{
fs.readFile('application/include/headerTemplate.js', function (err, data)
{
if (err) throw err;
headerTemplate = data;
completion(data);
});
}
else
{
completion(headerTemplate);
}
};
exports.pu = function(req, res, parsedUrl, bodyData)
{
if (req.method=='GET')
{
res.writeHead(200);
if (bodyData.length>0)
{
res.end(platform.cleanBlip(bodyData));
}
else
{
res.end(platform.newBlip());
}
}
else if (req.method=='POST')
{
console.log('POST ' + bodyData.length);
var bodyObj = JSON.parse(bodyData);
console.log('POST parsesd');
res.writeHead(200);
if (bodyObj && bodyObj.start)
{
fs.writeFile(bodyObj.start + '_' + bodyObj.end + '.p', bodyData, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
res.end(platform.nextBlip(bodyObj));
}
else
{
console.log('else done');
res.end(JSON.stringify({status:'success'}));
}
}
};