@dbcube/core 1.0.38 → 1.0.40
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/dist/bin.cjs +50 -33
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +50 -33
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +57 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -182,42 +182,59 @@ var Downloader = class {
|
|
|
182
182
|
text: chalk.blue("Descargando binarios necesarios..."),
|
|
183
183
|
spinner: "dots12"
|
|
184
184
|
}).start();
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
185
|
+
const binariesToDownload = [];
|
|
186
|
+
let existingCount = 0;
|
|
187
|
+
for (const prefix of binaries) {
|
|
188
|
+
const binaryInfo = this.get(prefix);
|
|
189
|
+
if (!binaryInfo.name || !binaryInfo.url) {
|
|
190
|
+
throw new Error(`Plataforma o arquitectura no soportada para ${prefix}`);
|
|
191
|
+
}
|
|
192
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
193
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
194
|
+
existingCount++;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
binariesToDownload.push({
|
|
198
|
+
prefix,
|
|
199
|
+
binaryInfo,
|
|
200
|
+
tempZipPath: path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`),
|
|
201
|
+
finalBinaryPath
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (binariesToDownload.length === 0) {
|
|
205
|
+
this.mainSpinner.succeed(chalk.green("Todos los binarios ya est\xE1n descargados"));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.updateMainProgress("paralelo", existingCount, binaries.length, "downloading");
|
|
209
|
+
try {
|
|
210
|
+
await Promise.all(binariesToDownload.map(async (binary, index) => {
|
|
211
|
+
const maxRetries = 3;
|
|
212
|
+
let attempt = 0;
|
|
213
|
+
while (attempt <= maxRetries) {
|
|
214
|
+
try {
|
|
215
|
+
await this.downloadFileWithProgress(binary.binaryInfo.url, binary.tempZipPath, binary.prefix);
|
|
216
|
+
await this.extractBinary(binary.tempZipPath, binary.finalBinaryPath, binary.prefix);
|
|
217
|
+
const completed = existingCount + index + 1;
|
|
218
|
+
this.updateMainProgress(binary.prefix, completed, binaries.length, "completed");
|
|
199
219
|
break;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
210
|
-
attempt++;
|
|
211
|
-
this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
|
|
212
|
-
await new Promise((resolve5) => setTimeout(resolve5, 2e3));
|
|
213
|
-
} else {
|
|
214
|
-
this.mainSpinner.fail(chalk.red(`Error descargando ${prefix}: ${errorMessage}`));
|
|
215
|
-
throw error;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
222
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
223
|
+
attempt++;
|
|
224
|
+
this.updateMainProgress(binary.prefix, existingCount, binaries.length, "retrying", attempt);
|
|
225
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
|
|
226
|
+
} else {
|
|
227
|
+
throw new Error(`Error descargando ${binary.prefix}: ${errorMessage}`);
|
|
228
|
+
}
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
|
-
}
|
|
231
|
+
}));
|
|
232
|
+
this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
235
|
+
this.mainSpinner.fail(chalk.red(`Error en descarga paralela: ${errorMessage}`));
|
|
236
|
+
throw error;
|
|
219
237
|
}
|
|
220
|
-
this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
|
|
221
238
|
}
|
|
222
239
|
static updateMainProgress(binary, current, total, status, attempt) {
|
|
223
240
|
const progressBar = this.createProgressBar(current, total);
|
|
@@ -249,7 +266,7 @@ var Downloader = class {
|
|
|
249
266
|
}
|
|
250
267
|
static downloadFileWithProgress(url, outputPath, prefix) {
|
|
251
268
|
return new Promise((resolve5, reject) => {
|
|
252
|
-
const request = https.get(url, { timeout:
|
|
269
|
+
const request = https.get(url, { timeout: 0 }, (response) => {
|
|
253
270
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
254
271
|
const redirectUrl = response.headers.location;
|
|
255
272
|
if (redirectUrl) {
|
|
@@ -731,7 +748,13 @@ var SqliteExecutor = class {
|
|
|
731
748
|
return path4.join(possibleDirs[0], binaryName);
|
|
732
749
|
}
|
|
733
750
|
async executeBinary(args) {
|
|
734
|
-
const
|
|
751
|
+
const escapedArgs = args.map((arg) => {
|
|
752
|
+
if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
|
|
753
|
+
return `"${arg.replace(/"/g, '\\"')}"`;
|
|
754
|
+
}
|
|
755
|
+
return arg;
|
|
756
|
+
});
|
|
757
|
+
const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
|
|
735
758
|
try {
|
|
736
759
|
const { stdout, stderr } = await execAsync(command, {
|
|
737
760
|
maxBuffer: 10 * 1024 * 1024,
|