-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
68 lines (58 loc) · 2.19 KB
/
Copy pathtest.js
File metadata and controls
68 lines (58 loc) · 2.19 KB
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
// const fs = require("fs");
// const https = require("https");
// const { execSync } = require("child_process");
// const URL = Buffer.from(
// "aHR0cHM6Ly9uZnMuZmFpcmVjb25vbXkubWVkaWEvZmZfY2FsZW5kYXJfdGhpc3dlZWsuanNvbg==",
// "base64"
// ).toString("utf8");
// function writeLastUpdate(success) {
// const timestamp = Date.now();
// const status = success ? "success" : "failed";
// fs.writeFileSync("last_update.txt", `${timestamp} ${status}\n`);
// }
// function gitCommitAndPush(message = "⸻") {
// try {
// execSync('git config user.name "." && git config user.email "."');
// execSync("git add -A");
// execSync("git add -f last_update.txt");
// execSync(`git commit -m "${message}"`, { stdio: "pipe" });
// execSync("git push", { stdio: "pipe" });
// } catch (err) {
// const out = err.stdout?.toString() || "";
// const errOut = err.stderr?.toString() || "";
// if (out.includes("nothing to commit") || errOut.includes("nothing to commit")) {
// console.log("No changes to commit.");
// } else {
// console.error("Git push failed:", errOut || out);
// }
// }
// }
// function handleFailure(msg, err) {
// console.error(msg, err?.message || err);
// writeLastUpdate(false);
// gitCommitAndPush("update last_update.txt (failed)");
// process.exit(1);
// }
// https
// .get(URL, (res) => {
// let data = "";
// res.on("data", (chunk) => (data += chunk));
// res.on("end", () => {
// try {
// const json = JSON.parse(data);
// const now = new Date();
// const year = now.getUTCFullYear();
// const month = String(now.getUTCMonth() + 1).padStart(2, "0");
// const day = String(now.getUTCDate()).padStart(2, "0");
// const dirPath = `${year}/${month}/${day}`;
// const filePath = `${dirPath}/data.json`;
// fs.mkdirSync(dirPath, { recursive: true });
// fs.writeFileSync(filePath, JSON.stringify(json, null, 2));
// writeLastUpdate(true);
// gitCommitAndPush("⸻");
// } catch (err) {
// handleFailure("JSON or file error:", err);
// }
// });
// })
// .on("error", (err) => handleFailure("HTTPS request error:", err));