Skip to content

Commit

Permalink
feat: 代理增加超时重试
Browse files Browse the repository at this point in the history
  • Loading branch information
huayemao committed Jun 28, 2024
1 parent ed07190 commit 20ab9fe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/api/files/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ export async function GET(request: Request) {
const searchParams = new URL(request.url).searchParams;
const href = searchParams.get("href");
if (href) {
const res = await fetch(decodeURIComponent(href));
return new Response(await res.arrayBuffer());
try {
const res = await fetch(decodeURIComponent(href));
return new Response(await res.arrayBuffer());
} catch (error) {
if (error.cause?.code == "UND_ERR_CONNECT_TIMEOUT") {
const newHref = href
.replace("//", "//47.114.89.18:8993/suburl/")
.replaceAll("https", "http");
const res = await fetch(decodeURIComponent(newHref));
return new Response(await res.arrayBuffer());
}
}
}

return new Response(``, {
Expand Down

0 comments on commit 20ab9fe

Please sign in to comment.