@0dai-dev/cli 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/0dai.js +33 -4
- package/package.json +1 -1
package/bin/0dai.js
CHANGED
|
@@ -27,16 +27,37 @@ const PROBE_DIRS = [
|
|
|
27
27
|
"android", "ios", "linux", "macos", "windows",
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
+
function deviceFingerprint() {
|
|
31
|
+
const crypto = require("crypto");
|
|
32
|
+
const parts = [
|
|
33
|
+
os.hostname(),
|
|
34
|
+
os.userInfo().username,
|
|
35
|
+
os.platform(),
|
|
36
|
+
os.arch(),
|
|
37
|
+
os.cpus().length.toString(),
|
|
38
|
+
os.totalmem().toString(),
|
|
39
|
+
];
|
|
40
|
+
// Try machine-id
|
|
41
|
+
try {
|
|
42
|
+
if (os.platform() === "linux") parts.push(fs.readFileSync("/etc/machine-id", "utf8").trim());
|
|
43
|
+
else if (os.platform() === "darwin") {
|
|
44
|
+
const { execSync } = require("child_process");
|
|
45
|
+
parts.push(execSync("ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/'", { encoding: "utf8" }).trim());
|
|
46
|
+
}
|
|
47
|
+
} catch {}
|
|
48
|
+
return crypto.createHash("sha256").update(parts.join(":")).digest("hex").slice(0, 32);
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
function apiCall(endpoint, data) {
|
|
31
52
|
return new Promise((resolve, reject) => {
|
|
32
53
|
const url = new URL(endpoint, API_URL);
|
|
33
54
|
const mod = url.protocol === "https:" ? https : http;
|
|
34
55
|
const body = data ? JSON.stringify(data) : null;
|
|
35
|
-
const headers = { "Content-Type": "application/json" };
|
|
56
|
+
const headers = { "Content-Type": "application/json", "X-Device-ID": deviceFingerprint() };
|
|
36
57
|
|
|
37
58
|
try {
|
|
38
59
|
const auth = JSON.parse(fs.readFileSync(AUTH_FILE, "utf8"));
|
|
39
|
-
const token = auth.api_key || auth.token;
|
|
60
|
+
const token = auth.api_key || auth.access_token || auth.token;
|
|
40
61
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
41
62
|
} catch {}
|
|
42
63
|
|
|
@@ -46,7 +67,7 @@ function apiCall(endpoint, data) {
|
|
|
46
67
|
path: url.pathname,
|
|
47
68
|
method: body ? "POST" : "GET",
|
|
48
69
|
headers,
|
|
49
|
-
timeout:
|
|
70
|
+
timeout: 60000,
|
|
50
71
|
};
|
|
51
72
|
if (body) opts.headers["Content-Length"] = Buffer.byteLength(body);
|
|
52
73
|
|
|
@@ -136,7 +157,15 @@ async function cmdInit(target) {
|
|
|
136
157
|
available_clis: clis,
|
|
137
158
|
});
|
|
138
159
|
|
|
139
|
-
if (result.error) {
|
|
160
|
+
if (result.error) {
|
|
161
|
+
if (result.hint) {
|
|
162
|
+
console.log(`\n[0dai] ${result.message || result.error}`);
|
|
163
|
+
console.log(` ${result.hint}\n`);
|
|
164
|
+
} else {
|
|
165
|
+
console.error(`[0dai] error: ${result.error}`);
|
|
166
|
+
}
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
140
169
|
|
|
141
170
|
console.log(`[0dai] detected: ${result.stack || "?"}`);
|
|
142
171
|
writeFiles(target, result.files || {});
|