grab-url 0.9.140 → 0.9.142
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/src/grab-url-cli.js +29 -6
package/package.json
CHANGED
package/src/grab-url-cli.js
CHANGED
|
@@ -291,11 +291,17 @@ calculateBarSize(spinnerFrame, baseBarSize = 20) {
|
|
|
291
291
|
*/
|
|
292
292
|
async checkServerSupport(url) {
|
|
293
293
|
try {
|
|
294
|
+
// Create a timeout controller
|
|
295
|
+
const timeoutController = new AbortController();
|
|
296
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), 3000); // 3 second timeout
|
|
297
|
+
|
|
294
298
|
const response = await fetch(url, {
|
|
295
299
|
method: 'HEAD',
|
|
296
|
-
signal:
|
|
300
|
+
signal: timeoutController.signal
|
|
297
301
|
});
|
|
298
302
|
|
|
303
|
+
clearTimeout(timeoutId);
|
|
304
|
+
|
|
299
305
|
if (!response.ok) {
|
|
300
306
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
301
307
|
}
|
|
@@ -313,7 +319,11 @@ async checkServerSupport(url) {
|
|
|
313
319
|
headers: response.headers
|
|
314
320
|
};
|
|
315
321
|
} catch (error) {
|
|
316
|
-
|
|
322
|
+
if (error.name === 'AbortError') {
|
|
323
|
+
console.log(this.colors.warning('Server check timed out, proceeding with regular download'));
|
|
324
|
+
} else {
|
|
325
|
+
console.log(this.colors.warning('Could not check server resume support, proceeding with regular download'));
|
|
326
|
+
}
|
|
317
327
|
return {
|
|
318
328
|
supportsResume: false,
|
|
319
329
|
totalSize: 0,
|
|
@@ -960,12 +970,20 @@ async downloadSingleFileWithBar(fileBar, masterBar, totalFiles, totalTracking) {
|
|
|
960
970
|
headers['Range'] = `bytes=${startByte}-`;
|
|
961
971
|
}
|
|
962
972
|
|
|
963
|
-
// Make the fetch request
|
|
973
|
+
// Make the fetch request with timeout
|
|
974
|
+
const timeoutController = new AbortController();
|
|
975
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), 30000); // 30 second timeout
|
|
976
|
+
|
|
977
|
+
// Combine abort and timeout signals
|
|
978
|
+
const combinedSignal = abortController.signal;
|
|
979
|
+
|
|
964
980
|
const response = await fetch(url, {
|
|
965
981
|
headers,
|
|
966
|
-
signal:
|
|
982
|
+
signal: combinedSignal
|
|
967
983
|
});
|
|
968
984
|
|
|
985
|
+
clearTimeout(timeoutId);
|
|
986
|
+
|
|
969
987
|
if (!response.ok) {
|
|
970
988
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
971
989
|
}
|
|
@@ -1156,7 +1174,7 @@ async downloadFile(url, outputPath) {
|
|
|
1156
1174
|
// Start with a random ora spinner animation
|
|
1157
1175
|
const randomOraSpinner = this.getRandomOraSpinner();
|
|
1158
1176
|
this.loadingSpinner = ora({
|
|
1159
|
-
text: this.colors.primary('
|
|
1177
|
+
text: this.colors.primary('Checking server capabilities...'),
|
|
1160
1178
|
spinner: randomOraSpinner,
|
|
1161
1179
|
color: 'cyan'
|
|
1162
1180
|
}).start();
|
|
@@ -1210,12 +1228,17 @@ async downloadFile(url, outputPath) {
|
|
|
1210
1228
|
headers['Range'] = `bytes=${startByte}-`;
|
|
1211
1229
|
}
|
|
1212
1230
|
|
|
1213
|
-
// Make the fetch request
|
|
1231
|
+
// Make the fetch request with timeout
|
|
1232
|
+
const timeoutController = new AbortController();
|
|
1233
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), 30000); // 30 second timeout
|
|
1234
|
+
|
|
1214
1235
|
const response = await fetch(url, {
|
|
1215
1236
|
headers,
|
|
1216
1237
|
signal: this.abortController.signal
|
|
1217
1238
|
});
|
|
1218
1239
|
|
|
1240
|
+
clearTimeout(timeoutId);
|
|
1241
|
+
|
|
1219
1242
|
if (!response.ok) {
|
|
1220
1243
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
1221
1244
|
}
|