From 384a7770ea06139b5b99c132b8eda937d6ad9c7b Mon Sep 17 00:00:00 2001 From: twotalesanimation <80506065+twotalesanimation@users.noreply.github.com> Date: Thu, 16 Jul 2026 23:12:58 +0200 Subject: [PATCH] OBJ then local 2 --- app/api/files/[...key]/route.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/api/files/[...key]/route.ts b/app/api/files/[...key]/route.ts index bb43c7b..de5d2ec 100644 --- a/app/api/files/[...key]/route.ts +++ b/app/api/files/[...key]/route.ts @@ -47,15 +47,20 @@ export async function GET( // ── Hetzner first, local disk fallback ─────────────────────────────────── // Check object storage first (all new uploads go there directly; migrated - // files live there too). Results are cached in process memory after the - // first check so subsequent range requests pay no extra latency. - // Fall back to local disk only for files that haven't been migrated yet. - let stat: fs.Stats; + // files live there too). Each try/catch is isolated so a Hetzner error + // never prevents local files from being served. try { if (await hetznerKeyExists(relativePath)) { const hetznerUrl = await generateHetznerStreamUrl(relativePath, 3600); return NextResponse.redirect(hetznerUrl, 302); } + } catch { + // Hetzner unavailable or misconfigured — fall through to local disk + } + + // Local disk fallback (unmigrated files, or if Hetzner is unreachable) + let stat: fs.Stats; + try { stat = fs.statSync(filePath); } catch { return new NextResponse("Not found", { status: 404 });