mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: add download retry
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -210,7 +210,7 @@ class RemoteStorageService {
|
|||||||
ResponseContentDisposition: filename ? `attachment; filename="${encodeRFC5987ValueChars(filename)}"` : '',
|
ResponseContentDisposition: filename ? `attachment; filename="${encodeRFC5987ValueChars(filename)}"` : '',
|
||||||
}), {
|
}), {
|
||||||
// aliyun s3 will reject download if expires >= 7 days
|
// aliyun s3 will reject download if expires >= 7 days
|
||||||
expiresIn: noExpire ? 24 * 60 * 60 * 7 - 1 : 10 * 60,
|
expiresIn: noExpire ? 24 * 60 * 60 * 7 - 1 : 30 * 60,
|
||||||
});
|
});
|
||||||
// using something like /fs/
|
// using something like /fs/
|
||||||
if (useAlternativeEndpointFor && this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor]) {
|
if (useAlternativeEndpointFor && this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor]) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { sleep } from '@hydrooj/utils/lib/common';
|
||||||
import { dump } from 'js-yaml';
|
import { dump } from 'js-yaml';
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
import streamsaver from 'streamsaver';
|
import streamsaver from 'streamsaver';
|
||||||
@@ -31,7 +32,7 @@ export default async function download(filename, targets) {
|
|||||||
const abortCallbackReceiver: any = {};
|
const abortCallbackReceiver: any = {};
|
||||||
function stopDownload() { abortCallbackReceiver.abort?.(); }
|
function stopDownload() { abortCallbackReceiver.abort?.(); }
|
||||||
let i = 0;
|
let i = 0;
|
||||||
async function downloadFile(target) {
|
async function downloadFile(target, retry = 5) {
|
||||||
try {
|
try {
|
||||||
let stream;
|
let stream;
|
||||||
if (target.url) {
|
if (target.url) {
|
||||||
@@ -46,6 +47,11 @@ export default async function download(filename, targets) {
|
|||||||
stream,
|
stream,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (retry) {
|
||||||
|
Notification.warn(i18n('Download Error: {0} {1}, retry in 3 secs...', [target.filename, e.toString()]));
|
||||||
|
await sleep(3000);
|
||||||
|
return await downloadFile(target, retry - 1);
|
||||||
|
}
|
||||||
window.captureException?.(e);
|
window.captureException?.(e);
|
||||||
stopDownload();
|
stopDownload();
|
||||||
Notification.error(i18n('Download Error: {0} {1}', [target.filename, e.toString()]));
|
Notification.error(i18n('Download Error: {0} {1}', [target.filename, e.toString()]));
|
||||||
|
|||||||
Reference in new issue
Block a user