@yuanchuan/aivo 0.14.0 → 0.14.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/aivo.js +5 -10
- package/package.json +1 -1
- package/scripts/postinstall.js +22 -7
package/bin/aivo.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { spawn } = require("node:child_process");
|
|
4
|
-
const
|
|
4
|
+
const os = require("node:os");
|
|
5
5
|
const { getInstalledBinaryPath } = require("../lib/paths");
|
|
6
6
|
|
|
7
7
|
const binaryPath = getInstalledBinaryPath();
|
|
8
8
|
|
|
9
|
-
if (!fs.existsSync(binaryPath)) {
|
|
10
|
-
console.error("aivo binary is not installed.");
|
|
11
|
-
console.error("Reinstall with: npm install -g @yuanchuan/aivo");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
16
10
|
stdio: "inherit"
|
|
17
11
|
});
|
|
18
12
|
|
|
19
13
|
child.on("exit", (code, signal) => {
|
|
20
14
|
if (signal) {
|
|
21
|
-
process.
|
|
15
|
+
process.exitCode = 128 + (os.constants.signals[signal] || 1);
|
|
22
16
|
return;
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
process.exit(code ?? 1);
|
|
26
20
|
});
|
|
27
21
|
|
|
28
|
-
child.on("error", (
|
|
29
|
-
console.error(
|
|
22
|
+
child.on("error", () => {
|
|
23
|
+
console.error("aivo binary is not installed.");
|
|
24
|
+
console.error("Reinstall with: npm install -g @yuanchuan/aivo");
|
|
30
25
|
process.exit(1);
|
|
31
26
|
});
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -10,6 +10,8 @@ const { resolvePlatformAsset } = require("../lib/platform");
|
|
|
10
10
|
|
|
11
11
|
const pkg = require(path.join(getPackageRoot(), "package.json"));
|
|
12
12
|
|
|
13
|
+
const MAX_REDIRECTS = 5;
|
|
14
|
+
|
|
13
15
|
async function main() {
|
|
14
16
|
if (process.env.AIVO_SKIP_POSTINSTALL === "1") {
|
|
15
17
|
return;
|
|
@@ -23,14 +25,16 @@ async function main() {
|
|
|
23
25
|
const checksumUrl = `${baseUrl}/${assetName}.sha256`;
|
|
24
26
|
const binaryUrl = `${baseUrl}/${assetName}`;
|
|
25
27
|
|
|
26
|
-
const checksumText = await
|
|
27
|
-
|
|
28
|
+
const [checksumText, binary] = await Promise.all([
|
|
29
|
+
downloadText(checksumUrl),
|
|
30
|
+
downloadBuffer(binaryUrl)
|
|
31
|
+
]);
|
|
28
32
|
|
|
33
|
+
const expectedSha = parseChecksumText(checksumText, assetName);
|
|
29
34
|
if (!expectedSha) {
|
|
30
35
|
throw new Error(`Checksum asset for ${assetName} could not be parsed.`);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
const binary = await downloadBuffer(binaryUrl);
|
|
34
38
|
const actualSha = sha256(binary);
|
|
35
39
|
if (actualSha !== expectedSha) {
|
|
36
40
|
throw new Error(`Checksum verification failed for ${assetName}.`);
|
|
@@ -54,12 +58,14 @@ function downloadText(url) {
|
|
|
54
58
|
|
|
55
59
|
function downloadBuffer(url, redirectCount = 0) {
|
|
56
60
|
return new Promise((resolve, reject) => {
|
|
57
|
-
const
|
|
61
|
+
const proto = url.startsWith("https://") ? https : require("node:http");
|
|
62
|
+
const request = proto.get(
|
|
58
63
|
url,
|
|
59
64
|
{
|
|
60
65
|
headers: {
|
|
61
66
|
"User-Agent": "@yuanchuan/aivo-installer"
|
|
62
|
-
}
|
|
67
|
+
},
|
|
68
|
+
timeout: 30_000
|
|
63
69
|
},
|
|
64
70
|
(response) => {
|
|
65
71
|
const status = response.statusCode || 0;
|
|
@@ -68,10 +74,15 @@ function downloadBuffer(url, redirectCount = 0) {
|
|
|
68
74
|
status >= 300 &&
|
|
69
75
|
status < 400 &&
|
|
70
76
|
response.headers.location &&
|
|
71
|
-
redirectCount <
|
|
77
|
+
redirectCount < MAX_REDIRECTS
|
|
72
78
|
) {
|
|
73
79
|
response.resume();
|
|
74
|
-
|
|
80
|
+
const location = response.headers.location;
|
|
81
|
+
if (!location.startsWith("https://") && !location.startsWith("http://")) {
|
|
82
|
+
reject(new Error(`Invalid redirect URL: ${location}`));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
resolve(downloadBuffer(location, redirectCount + 1));
|
|
75
86
|
return;
|
|
76
87
|
}
|
|
77
88
|
|
|
@@ -87,6 +98,10 @@ function downloadBuffer(url, redirectCount = 0) {
|
|
|
87
98
|
}
|
|
88
99
|
);
|
|
89
100
|
|
|
101
|
+
request.on("timeout", () => {
|
|
102
|
+
request.destroy();
|
|
103
|
+
reject(new Error(`Download timed out: ${url}`));
|
|
104
|
+
});
|
|
90
105
|
request.on("error", reject);
|
|
91
106
|
});
|
|
92
107
|
}
|