21 lines
878 B
TypeScript
21 lines
878 B
TypeScript
import { getAssetByStoragePath } from "@/lib/server/data-store";
|
|
import { requireAppUser } from "@/lib/server/auth/current-user";
|
|
import { readLocalServedFile } from "@/lib/server/storage";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
export async function GET(_request: Request, context: { params: Promise<{ path: string[] }> }) {
|
|
const user = await requireAppUser();
|
|
const { path } = await context.params;
|
|
const asset = await getAssetByStoragePath(["uploads", ...path].join("/"));
|
|
if (!asset || asset.ownerId !== user.id) return new Response("Not found", { status: 404 });
|
|
const file = await readLocalServedFile("uploads", path);
|
|
if (!file) return new Response("Not found", { status: 404 });
|
|
return new Response(new Uint8Array(file.bytes), {
|
|
headers: {
|
|
"Content-Type": file.contentType,
|
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
}
|
|
});
|
|
}
|