You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
var fs = require("fs");
|
|
var syncRequest = require("sync-request");
|
|
const app = express()
|
|
const port = 5243
|
|
|
|
app.get('/', (req, res) => {
|
|
res.send('Hello!!!')
|
|
})
|
|
|
|
|
|
app.post("/track", function (req, res) {
|
|
var updateFile = function (response, body, path) {
|
|
if (body.status == 2)
|
|
{
|
|
var file = syncRequest("GET", body.url);
|
|
fs.writeFileSync(path, file.getBody());
|
|
}
|
|
response.write("{\"error\":0}");
|
|
response.end();
|
|
}
|
|
var readbody = function (request, response, path) {
|
|
var content = "";
|
|
request.on("data", function (data) {
|
|
content += data;
|
|
});
|
|
request.on("end", function () {
|
|
var body = JSON.parse(content);
|
|
updateFile(response, body, path);
|
|
});
|
|
}
|
|
if (req.body.hasOwnProperty("status")) {
|
|
updateFile(res, req.body, req.query.path);
|
|
} else {
|
|
readbody(req, res, req.query.path)
|
|
}
|
|
});
|
|
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`)
|
|
}) |