@yuanchuan/aivo 0.14.5 → 0.16.0
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/package.json +1 -1
- package/scripts/postinstall.js +43 -11
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -26,14 +26,29 @@ async function main(options = {}) {
|
|
|
26
26
|
|
|
27
27
|
const { assetName } = resolvePlatformAsset(platform, arch);
|
|
28
28
|
const version = pkg.version;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const overrideBaseUrl = env.AIVO_INSTALL_BASE_URL;
|
|
30
|
+
|
|
31
|
+
let checksumText, binary;
|
|
32
|
+
|
|
33
|
+
if (overrideBaseUrl) {
|
|
34
|
+
[checksumText, binary] = await Promise.all([
|
|
35
|
+
downloadText(`${overrideBaseUrl}/${assetName}.sha256`),
|
|
36
|
+
downloadBuffer(`${overrideBaseUrl}/${assetName}`)
|
|
37
|
+
]);
|
|
38
|
+
} else {
|
|
39
|
+
const githubBaseUrl = getReleaseBaseUrl(version);
|
|
40
|
+
const mirrorBaseUrl = getMirrorBaseUrl(version);
|
|
41
|
+
[checksumText, binary] = await Promise.all([
|
|
42
|
+
downloadTextWithFallback(
|
|
43
|
+
`${githubBaseUrl}/${assetName}.sha256`,
|
|
44
|
+
`${mirrorBaseUrl}/${assetName}.sha256`
|
|
45
|
+
),
|
|
46
|
+
downloadBufferWithFallback(
|
|
47
|
+
`${githubBaseUrl}/${assetName}`,
|
|
48
|
+
`${mirrorBaseUrl}/${assetName}`
|
|
49
|
+
)
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
37
52
|
|
|
38
53
|
const expectedSha = parseChecksumText(checksumText, assetName);
|
|
39
54
|
if (!expectedSha) {
|
|
@@ -65,10 +80,24 @@ function downloadText(url) {
|
|
|
65
80
|
return downloadBuffer(url).then((buffer) => buffer.toString("utf8"));
|
|
66
81
|
}
|
|
67
82
|
|
|
83
|
+
function downloadBufferWithFallback(primaryUrl, fallbackUrl) {
|
|
84
|
+
return downloadBuffer(primaryUrl, 0, 10_000).catch(() => {
|
|
85
|
+
return downloadBuffer(fallbackUrl);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function downloadTextWithFallback(primaryUrl, fallbackUrl) {
|
|
90
|
+
return downloadBufferWithFallback(primaryUrl, fallbackUrl).then((buffer) => buffer.toString("utf8"));
|
|
91
|
+
}
|
|
92
|
+
|
|
68
93
|
function getReleaseBaseUrl(version) {
|
|
69
94
|
return `https://github.com/yuanchuan/aivo/releases/download/v${version}`;
|
|
70
95
|
}
|
|
71
96
|
|
|
97
|
+
function getMirrorBaseUrl(version) {
|
|
98
|
+
return `https://getaivo.dev/dl/v${version}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
72
101
|
function installBinary({ binary, binaryPath, nativeDir, platform, fsImpl = fs }) {
|
|
73
102
|
const tempPath = path.join(
|
|
74
103
|
nativeDir,
|
|
@@ -110,7 +139,7 @@ function formatInstallError(error, platform = process.platform) {
|
|
|
110
139
|
return lines.join("\n");
|
|
111
140
|
}
|
|
112
141
|
|
|
113
|
-
function downloadBuffer(url, redirectCount = 0) {
|
|
142
|
+
function downloadBuffer(url, redirectCount = 0, timeout = 30_000) {
|
|
114
143
|
return new Promise((resolve, reject) => {
|
|
115
144
|
const proto = url.startsWith("https://") ? https : require("node:http");
|
|
116
145
|
const request = proto.get(
|
|
@@ -119,7 +148,7 @@ function downloadBuffer(url, redirectCount = 0) {
|
|
|
119
148
|
headers: {
|
|
120
149
|
"User-Agent": "@yuanchuan/aivo-installer"
|
|
121
150
|
},
|
|
122
|
-
timeout
|
|
151
|
+
timeout
|
|
123
152
|
},
|
|
124
153
|
(response) => {
|
|
125
154
|
const status = response.statusCode || 0;
|
|
@@ -136,7 +165,7 @@ function downloadBuffer(url, redirectCount = 0) {
|
|
|
136
165
|
reject(new Error(`Invalid redirect URL: ${location}`));
|
|
137
166
|
return;
|
|
138
167
|
}
|
|
139
|
-
resolve(downloadBuffer(location, redirectCount + 1));
|
|
168
|
+
resolve(downloadBuffer(location, redirectCount + 1, timeout));
|
|
140
169
|
return;
|
|
141
170
|
}
|
|
142
171
|
|
|
@@ -170,8 +199,11 @@ if (require.main === module) {
|
|
|
170
199
|
module.exports = {
|
|
171
200
|
REPAIR_COMMAND,
|
|
172
201
|
downloadBuffer,
|
|
202
|
+
downloadBufferWithFallback,
|
|
173
203
|
downloadText,
|
|
204
|
+
downloadTextWithFallback,
|
|
174
205
|
formatInstallError,
|
|
206
|
+
getMirrorBaseUrl,
|
|
175
207
|
getReleaseBaseUrl,
|
|
176
208
|
installBinary,
|
|
177
209
|
main
|