@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.cjs
CHANGED
|
@@ -219,42 +219,59 @@ var Downloader = class {
|
|
|
219
219
|
text: import_chalk.default.blue("Descargando binarios necesarios..."),
|
|
220
220
|
spinner: "dots12"
|
|
221
221
|
}).start();
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
222
|
+
const binariesToDownload = [];
|
|
223
|
+
let existingCount = 0;
|
|
224
|
+
for (const prefix of binaries) {
|
|
225
|
+
const binaryInfo = this.get(prefix);
|
|
226
|
+
if (!binaryInfo.name || !binaryInfo.url) {
|
|
227
|
+
throw new Error(`Plataforma o arquitectura no soportada para ${prefix}`);
|
|
228
|
+
}
|
|
229
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
230
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
231
|
+
existingCount++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
binariesToDownload.push({
|
|
235
|
+
prefix,
|
|
236
|
+
binaryInfo,
|
|
237
|
+
tempZipPath: path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`),
|
|
238
|
+
finalBinaryPath
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (binariesToDownload.length === 0) {
|
|
242
|
+
this.mainSpinner.succeed(import_chalk.default.green("Todos los binarios ya est\xE1n descargados"));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.updateMainProgress("paralelo", existingCount, binaries.length, "downloading");
|
|
246
|
+
try {
|
|
247
|
+
await Promise.all(binariesToDownload.map(async (binary, index) => {
|
|
248
|
+
const maxRetries = 3;
|
|
249
|
+
let attempt = 0;
|
|
250
|
+
while (attempt <= maxRetries) {
|
|
251
|
+
try {
|
|
252
|
+
await this.downloadFileWithProgress(binary.binaryInfo.url, binary.tempZipPath, binary.prefix);
|
|
253
|
+
await this.extractBinary(binary.tempZipPath, binary.finalBinaryPath, binary.prefix);
|
|
254
|
+
const completed = existingCount + index + 1;
|
|
255
|
+
this.updateMainProgress(binary.prefix, completed, binaries.length, "completed");
|
|
236
256
|
break;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
247
|
-
attempt++;
|
|
248
|
-
this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
|
|
249
|
-
await new Promise((resolve5) => setTimeout(resolve5, 2e3));
|
|
250
|
-
} else {
|
|
251
|
-
this.mainSpinner.fail(import_chalk.default.red(`Error descargando ${prefix}: ${errorMessage}`));
|
|
252
|
-
throw error;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
259
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
260
|
+
attempt++;
|
|
261
|
+
this.updateMainProgress(binary.prefix, existingCount, binaries.length, "retrying", attempt);
|
|
262
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
|
|
263
|
+
} else {
|
|
264
|
+
throw new Error(`Error descargando ${binary.prefix}: ${errorMessage}`);
|
|
265
|
+
}
|
|
253
266
|
}
|
|
254
267
|
}
|
|
255
|
-
}
|
|
268
|
+
}));
|
|
269
|
+
this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
|
|
270
|
+
} catch (error) {
|
|
271
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
272
|
+
this.mainSpinner.fail(import_chalk.default.red(`Error en descarga paralela: ${errorMessage}`));
|
|
273
|
+
throw error;
|
|
256
274
|
}
|
|
257
|
-
this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
|
|
258
275
|
}
|
|
259
276
|
static updateMainProgress(binary, current, total, status, attempt) {
|
|
260
277
|
const progressBar = this.createProgressBar(current, total);
|
|
@@ -286,7 +303,7 @@ var Downloader = class {
|
|
|
286
303
|
}
|
|
287
304
|
static downloadFileWithProgress(url, outputPath, prefix) {
|
|
288
305
|
return new Promise((resolve5, reject) => {
|
|
289
|
-
const request = import_follow_redirects.https.get(url, { timeout:
|
|
306
|
+
const request = import_follow_redirects.https.get(url, { timeout: 0 }, (response) => {
|
|
290
307
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
291
308
|
const redirectUrl = response.headers.location;
|
|
292
309
|
if (redirectUrl) {
|
|
@@ -768,7 +785,13 @@ var SqliteExecutor = class {
|
|
|
768
785
|
return path4.join(possibleDirs[0], binaryName);
|
|
769
786
|
}
|
|
770
787
|
async executeBinary(args) {
|
|
771
|
-
const
|
|
788
|
+
const escapedArgs = args.map((arg) => {
|
|
789
|
+
if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
|
|
790
|
+
return `"${arg.replace(/"/g, '\\"')}"`;
|
|
791
|
+
}
|
|
792
|
+
return arg;
|
|
793
|
+
});
|
|
794
|
+
const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
|
|
772
795
|
try {
|
|
773
796
|
const { stdout, stderr } = await execAsync(command, {
|
|
774
797
|
maxBuffer: 10 * 1024 * 1024,
|