This commit is contained in:
Moritz Utcke
2025-02-22 12:03:36 +11:00
parent b5d6ba731e
commit fb706c5999
16 changed files with 79 additions and 77 deletions

View File

@@ -0,0 +1,39 @@
import { prisma } from "#lib/server/prisma.js";
import { APIRoute } from "astro";
import * as fs from "fs";
import { fileURLToPath } from "url";
export const GET: APIRoute = async (Astro) => {
const { uid } = Astro.params;
const image = await prisma.bild.findUnique({
where: {
uid,
},
});
if (!image) {
return new Response(null, {
status: 404,
});
}
const path = fileURLToPath(
new URL(`../../../persistent/images/${image.uid}.jpg`, import.meta.url)
);
if (!fs.existsSync(path)) {
return new Response(null, {
status: 404,
});
}
const buffer = fs.readFileSync(path);
return new Response(buffer, {
status: 200,
headers: {
"Content-Type": "image/jpeg",
},
});
};