@@ -47,15 +47,20 @@ export async function GET(
|
|||||||
|
|
||||||
// ── Hetzner first, local disk fallback ───────────────────────────────────
|
// ── Hetzner first, local disk fallback ───────────────────────────────────
|
||||||
// Check object storage first (all new uploads go there directly; migrated
|
// Check object storage first (all new uploads go there directly; migrated
|
||||||
// files live there too). Results are cached in process memory after the
|
// files live there too). Each try/catch is isolated so a Hetzner error
|
||||||
// first check so subsequent range requests pay no extra latency.
|
// never prevents local files from being served.
|
||||||
// Fall back to local disk only for files that haven't been migrated yet.
|
|
||||||
let stat: fs.Stats;
|
|
||||||
try {
|
try {
|
||||||
if (await hetznerKeyExists(relativePath)) {
|
if (await hetznerKeyExists(relativePath)) {
|
||||||
const hetznerUrl = await generateHetznerStreamUrl(relativePath, 3600);
|
const hetznerUrl = await generateHetznerStreamUrl(relativePath, 3600);
|
||||||
return NextResponse.redirect(hetznerUrl, 302);
|
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);
|
stat = fs.statSync(filePath);
|
||||||
} catch {
|
} catch {
|
||||||
return new NextResponse("Not found", { status: 404 });
|
return new NextResponse("Not found", { status: 404 });
|
||||||
|
|||||||
Reference in New Issue
Block a user