main
forget_the_bright 1 year ago
parent 0d4e8cccb0
commit f1fc3d39c8

@ -0,0 +1,42 @@
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}`)
})

1447
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,16 @@
{
"name": "callbak",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"sync-request": "^6.1.0"
}
}
Loading…
Cancel
Save