@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user