diff --git a/src/pages/api/random-sekai-picture.js b/src/pages/api/random-sekai-picture.js index 1da93fd..7776c6f 100644 --- a/src/pages/api/random-sekai-picture.js +++ b/src/pages/api/random-sekai-picture.js @@ -2,9 +2,20 @@ import path from "path"; import fs from "fs"; export default function handler(req, res) { + if (req.method !== "GET") { + res.status(405).json({ message: "Method Not Allowed" }); + return; + } + const random = Math.floor(Math.random() * 3) + 1; // Generate random number 1-3 const imagePath = path.join(process.cwd(), "public", "sekai", `${random}.jpeg`); + // Check if the image file exists + if (!fs.existsSync(imagePath)) { + res.status(404).json({ message: "Image Not Found" }); + return; + } + // Read the image file from the filesystem const image = fs.readFileSync(imagePath);