From d1c80d15ea6cf1b7176be9a3e7474006513beafa Mon Sep 17 00:00:00 2001 From: iz <2131601562@qq.com> Date: Sun, 4 Aug 2024 15:10:42 +0800 Subject: [PATCH] retry support --- setup.ts | 2 +- utils.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/setup.ts b/setup.ts index 14982c7..f4aadcc 100644 --- a/setup.ts +++ b/setup.ts @@ -39,7 +39,7 @@ for(const arch in CC){ run(`cp -r ~/alist/.git .`); // 开始编译 - const addition = `X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=${new Date().toISOString()}' + const addition = `-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=${new Date().toISOString()}' -X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=${ parseFloat(runWithOutput('go version').split('go version ')[1] || '0.1') }' diff --git a/utils.ts b/utils.ts index bb8b392..6b049b4 100644 --- a/utils.ts +++ b/utils.ts @@ -41,8 +41,14 @@ export function cd(dir: string){ } export async function wget(url: string, saveAs: string){ - const fe = await fetch(url), - file = await Deno.open(saveAs, {createNew: true, read: false, write: true}); - if(!fe.ok) throw new Error(`Failed to fetch ${url}`); - await fe.body!.pipeTo(file.writable); + for(let i = 0; i < 3; i++) try{ + const fe = await fetch(url), + file = await Deno.open(saveAs, {createNew: true, read: false, write: true}); + if(!fe.ok) throw new Error(`Failed to fetch ${url}`); + await fe.body!.pipeTo(file.writable); + }catch(e){ + if(i === 2) throw new Error(`Failed to download ${url} after 3 retries: ${e.message}`); + console.warn(`Failed to download ${url}(retry ${i+1}/3): ${e.message}`); + await new Promise(resolve => setTimeout(resolve, 5000)); + } } \ No newline at end of file