@bloret-crew/blora-agent 0.1.0-beta.1 → 0.1.0-beta.3
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/install.js +33 -4
- package/package.json +1 -1
package/bin/install.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { createWriteStream, existsSync, mkdirSync,
|
|
3
|
+
const { chmodSync, copyFileSync, createWriteStream, existsSync, mkdirSync, rmSync, unlinkSync } = require("node:fs");
|
|
4
4
|
const { tmpdir } = require("node:os");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
+
const { execFile } = require("node:child_process");
|
|
7
|
+
const { promisify } = require("node:util");
|
|
6
8
|
const { pipeline } = require("node:stream/promises");
|
|
7
9
|
const { request } = require("node:https");
|
|
8
10
|
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
|
|
9
13
|
const version = require("../package.json").version;
|
|
10
14
|
const repo = "BloretCrew/Blora-Agent";
|
|
11
15
|
const installDir = path.join(__dirname);
|
|
@@ -67,6 +71,7 @@ async function downloadWithRetry(url, destinationPath) {
|
|
|
67
71
|
return;
|
|
68
72
|
} catch (error) {
|
|
69
73
|
lastError = error;
|
|
74
|
+
if (error.code === "ECONNRESET" || error.message === "socket hang up") throw error;
|
|
70
75
|
if (attempt < MAX_ATTEMPTS) {
|
|
71
76
|
const delay = 1_000 * 2 ** (attempt - 1);
|
|
72
77
|
console.error(`Download attempt ${attempt} failed (${error.message}); retrying in ${delay / 1000}s…`);
|
|
@@ -77,6 +82,19 @@ async function downloadWithRetry(url, destinationPath) {
|
|
|
77
82
|
throw lastError;
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
async function downloadWithCurl(url, destinationPath) {
|
|
86
|
+
await execFileAsync("curl", [
|
|
87
|
+
"--fail",
|
|
88
|
+
"--location",
|
|
89
|
+
"--retry", String(MAX_ATTEMPTS - 1),
|
|
90
|
+
"--retry-delay", "2",
|
|
91
|
+
"--connect-timeout", "20",
|
|
92
|
+
"--max-time", String(DOWNLOAD_TIMEOUT_MS / 1000),
|
|
93
|
+
"--output", destinationPath,
|
|
94
|
+
url,
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
async function extract(archive, target) {
|
|
81
99
|
if (process.platform === "win32") {
|
|
82
100
|
const { execFile } = require("node:child_process");
|
|
@@ -109,12 +127,23 @@ async function main() {
|
|
|
109
127
|
const url = `https://github.com/${repo}/releases/download/v${version}/${asset}`;
|
|
110
128
|
try {
|
|
111
129
|
console.log(`Downloading Blora ${version} for ${process.platform}/${process.arch}…`);
|
|
112
|
-
|
|
130
|
+
try {
|
|
131
|
+
await downloadWithRetry(url, archive);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error.code !== "ECONNRESET" && error.message !== "socket hang up") throw error;
|
|
134
|
+
console.error(`Node download failed (${error.message}); retrying with curl…`);
|
|
135
|
+
await downloadWithCurl(url, archive);
|
|
136
|
+
}
|
|
113
137
|
await extract(archive, target);
|
|
114
138
|
const extracted = path.join(target, executable);
|
|
115
139
|
if (!existsSync(extracted)) throw new Error(`release archive does not contain ${executable}`);
|
|
116
|
-
|
|
117
|
-
|
|
140
|
+
try {
|
|
141
|
+
copyFileSync(extracted, destination);
|
|
142
|
+
unlinkSync(extracted);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new Error(`could not install binary: ${error.message}`);
|
|
145
|
+
}
|
|
146
|
+
if (process.platform !== "win32") chmodSync(destination, 0o755);
|
|
118
147
|
console.log("Blora installed.");
|
|
119
148
|
} catch (error) {
|
|
120
149
|
console.error(`Blora binary download failed: ${error.message}`);
|