This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
forked from carcabot/tiktok-signature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listen.js
71 lines (61 loc) · 1.98 KB
/
listen.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
const Signer = require("./index");
const http = require("http");
(async function main() {
try {
const signer = new Signer();
const server = http
.createServer()
.listen(8081)
.on("listening", function () {
console.log("TikTok Signature server started");
});
// Uncomment if you want to auto-exit this application after a period of time
// If you use PM2 or Supervisord, it will attempt to open it ( in this way tac token will be refreshed)
// setTimeout(function () {
// server.close(() => {
// console.log("Server shutdown completed.");
// process.exit(1);
// });
// }, 1 * 60 * 60 * 1000);
signer.init(); // !?
server.on("request", (request, response) => {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Headers', '*');
if (request.method === 'OPTIONS' ) {
response.writeHead(200);
response.end();
return;
}
if (request.method === "POST" && request.url === "/signature") {
var url = "";
request.on("data", function (chunk) {
url += chunk;
});
request.on("end", async function () {
console.log("Received url: " + url);
try {
const verifyFp = await signer.getVerifyFp();
const token = await signer.sign(url);
const cookies = await signer.getCookies();
let output = JSON.stringify({
signature: token,
verifyFp: verifyFp,
cookies: cookies
});
response.writeHead(200, { "Content-Type": "application/json" });
response.end(output);
console.log("Sent result: " + output);
} catch (err) {
console.log(err);
}
});
} else {
response.statusCode = 404;
response.end();
}
});
await signer.close();
} catch (err) {
console.error(err);
}
})();