feat: publish approved RF4 media catalog
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { APIRoute } from "astro";
|
||||
|
||||
const apiBase = process.env.API_INTERNAL_URL || import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
|
||||
|
||||
export const GET: APIRoute = async ({ params }) => {
|
||||
const digest = params.digest ?? "";
|
||||
if (!/^[a-f0-9]{64}$/.test(digest)) return new Response("Not found", { status: 404 });
|
||||
|
||||
try {
|
||||
const upstream = await fetch(`${apiBase}/api/v1/media/assets/${digest}`);
|
||||
if (!upstream.ok || !upstream.body) return new Response("Not found", { status: upstream.status === 404 ? 404 : 502 });
|
||||
const headers = new Headers();
|
||||
for (const name of ["content-type", "content-length", "cache-control", "etag"]) {
|
||||
const value = upstream.headers.get(name);
|
||||
if (value) headers.set(name, value);
|
||||
}
|
||||
return new Response(upstream.body, { status: 200, headers });
|
||||
} catch {
|
||||
return new Response("Media service unavailable", { status: 502 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user