restructure backend
This commit is contained in:
18
src/api.ts
Normal file
18
src/api.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user