18 lines
609 B
TypeScript
18 lines
609 B
TypeScript
export async function getImage(req: Bun.BunRequest<"/api/cards/:id">) {
|
|
const { id } = req.params;
|
|
let file = Bun.file(`images/cards/${id}.png`);
|
|
let type = "png";
|
|
|
|
if (!(await file.exists())) {
|
|
file = Bun.file(`images/cards/${id}.jpg`);
|
|
type = "jpg";
|
|
|
|
if (!(await file.exists())) {
|
|
file = Bun.file("images/cards/placeholder.png");
|
|
type = "png";
|
|
console.error(`File for image ${id} does not exist, serving placeholder`);
|
|
}
|
|
}
|
|
|
|
return new Response(file, { headers: { "Content-Type": `image/${type}` }, status: 200 });
|
|
} |