forked from gyy888/MyActions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oneByOneExecute.js
54 lines (48 loc) · 1.66 KB
/
oneByOneExecute.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
const exec = require("child_process").execSync;
const fs = require("fs");
const download = require("download");
const smartReplace = require("./smartReplace");
// 公共变量
const JD_COOKIE = process.env.JD_COOKIE; //cokie,多个用&隔开即可
const SyncUrl = process.env.SYNCURL; //签到地址,方便随时变动
let CookieJDs = [];
async function downFile() {
await download(SyncUrl, "./", { filename: "temp.js" });
}
async function changeFiele(content, cookie) {
let newContent = await smartReplace.replaceWithSecrets(content, cookie);
await fs.writeFileSync("./execute.js", newContent, "utf8");
}
async function executeOneByOne() {
const content = await fs.readFileSync("./temp.js", "utf8");
for (var i = 0; i < CookieJDs.length; i++) {
console.log(`正在执行第${i + 1}个账号签到任务`);
await changeFiele(content, CookieJDs[i]);
console.log("替换变量完毕");
try {
await exec("node execute.js", { stdio: "inherit" });
} catch (e) {
console.log("执行异常:" + e);
}
console.log("执行完毕");
}
}
async function start() {
console.log(`当前执行时间:${new Date().toString()}`);
if (!JD_COOKIE) {
console.log("请填写 JD_COOKIE 后在继续");
return;
}
if (!SyncUrl) {
console.log("请填写 SYNCURL 后在继续");
return;
}
CookieJDs = JD_COOKIE.split("&");
console.log(`当前共${CookieJDs.length}个账号需要签到`);
// 下载最新代码
await downFile();
console.log("下载代码完毕");
await executeOneByOne();
console.log("全部执行完毕");
}
start();