import cors from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import Elysia from "elysia";
import { existsSync } from "fs";
import fs from "fs/promises";
const UPLOAD_DIR = "./uploads";

const Api = new Elysia({ prefix: "/api/v2" })
   .onError(({ error }) => {
     
   })
   .post("/test", async ({ request }) => {
      const formData = await request.formData()
      const file = formData.get("file") as File;
      const buffer = Buffer.from(await file.arrayBuffer());
      await fs.writeFile("./test2.png", buffer);

      return {
         status: "success",
         message: "File uploaded successfully",
         data: {
         }
      };

   });

const ApiServer = new Elysia()
   .use(cors({
      origin: "*",
      methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
   }))
   .use(swagger({ path: "/api/v2/docs" }))
   .use(Api);

export const GET = ApiServer.handle;
export const POST = ApiServer.handle;
