termai commited on
Commit
ef8f3ef
·
verified ·
1 Parent(s): 1fef182

Delete factory.js

Browse files
Files changed (1) hide show
  1. factory.js +0 -73
factory.js DELETED
@@ -1,73 +0,0 @@
1
- require("dotenv/config");
2
- const fs = require("fs");
3
- const fetch = require("node-fetch");
4
- const { promisify } = require("util");
5
-
6
- const key = "Abr0M3fvrtOxT09MS1ZwmUq"; // kunci untuk ambil token dari endpoint CORS
7
-
8
- // Ambil daftar akun dari file ./account
9
- const accounts = fs
10
- .readFileSync("./account", "utf8")
11
- .split("\n")
12
- .map((a) => a.trim())
13
- .filter((a) => a && !a.includes("!"));
14
-
15
- // Rebuild via Hugging Face API
16
- const rebuildViaApi = async (username, token) => {
17
- const repo = process.env.REPO_NAME;
18
- console.log(`🔁 Rebuilding via API for ${username}/${repo}`);
19
-
20
- const res = await fetch(
21
- `https://huggingface.co/api/spaces/${username}/${repo}/restart?factory=true`,
22
- {
23
- method: "POST",
24
- headers: {
25
- Authorization: `Bearer ${token}`,
26
- },
27
- }
28
- );
29
-
30
- if (!res.ok) {
31
- const txt = await res.text();
32
- throw new Error(
33
- `Gagal restart ${username}/${repo} – ${res.status}: ${txt}`
34
- );
35
- }
36
-
37
- console.log(`✅ API restart success for ${username}/${repo}`);
38
- };
39
-
40
- // Ambil token dari endpoint cors akun
41
- const getToken = async (username) => {
42
- const url = `https://${username}-cors.hf.space/ev?key=${key}&q=process.env.TOKEN`;
43
- const token = await fetch(url).then((res) => res.text());
44
- return token.trim();
45
- };
46
-
47
- // Main Executor
48
- (async () => {
49
- const customAccounts = process.argv.slice(2);
50
- const targetAccounts = customAccounts.length > 0 ? customAccounts : accounts;
51
- const mode = process.env.MODE || "push";
52
-
53
- console.log(`🧩 Mode: ${mode}`);
54
- console.log(`👤 Target accounts:`, targetAccounts);
55
-
56
- for (const account of targetAccounts) {
57
- try {
58
- const token = await getToken(account);
59
-
60
- if (!token || token.length < 20) {
61
- throw new Error(`Token invalid for ${account}`);
62
- }
63
-
64
- await rebuildViaApi(account, token);
65
-
66
- console.log(`✅ Success for ${account}`);
67
- } catch (err) {
68
- console.error(`❌ Failed for ${account}:`, err.message);
69
- }
70
- }
71
-
72
- setTimeout(() => process.exit(), 3000);
73
- })();