refactor: get random image from api

This commit is contained in:
Pihkaal
2024-10-17 20:00:06 +02:00
parent 0bde85fd8f
commit 203985915c
3 changed files with 17 additions and 13 deletions

10
server/api/index.ts Normal file
View File

@@ -0,0 +1,10 @@
import { resolve } from "path";
import { readdir, readFile } from "fs/promises";
export default defineEventHandler(async () => {
const images = await readdir(resolve("public", "lilou"));
const imageName = images[Math.floor(Math.random() * images.length)];
const image = await readFile(resolve("public", "lilou", imageName));
return image;
});