Skip to content

Commit

Permalink
ui: add download retry
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed Dec 8, 2024
1 parent ac35a6e commit 181c5cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/hydrooj/src/service/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class RemoteStorageService {
ResponseContentDisposition: filename ? `attachment; filename="${encodeRFC5987ValueChars(filename)}"` : '',
}), {
// 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/
if (useAlternativeEndpointFor && this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor]) {
Expand Down
8 changes: 7 additions & 1 deletion packages/ui-default/components/zipDownloader/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sleep } from '@hydrooj/utils/lib/common';
import { dump } from 'js-yaml';
import PQueue from 'p-queue';
import streamsaver from 'streamsaver';
Expand Down Expand Up @@ -31,7 +32,7 @@ export default async function download(filename, targets) {
const abortCallbackReceiver: any = {};
function stopDownload() { abortCallbackReceiver.abort?.(); }
let i = 0;
async function downloadFile(target) {
async function downloadFile(target, retry = 5) {
try {
let stream;
if (target.url) {
Expand All @@ -46,6 +47,11 @@ export default async function download(filename, targets) {
stream,
};
} 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);
stopDownload();
Notification.error(i18n('Download Error: {0} {1}', [target.filename, e.toString()]));
Expand Down

0 comments on commit 181c5cb

Please sign in to comment.