import { NextResponse } from "next/server";
import { uploadFile } from "@/utils/upload.file";
import fs from "fs";
import path from "path";

export async function POST(request) {
  try {
    const galleryPath = path.join(process.cwd(), "/public/media/gallery");
    fs.mkdirSync(galleryPath, { recursive: true });
    const resultUpload = await uploadFile(request, {
      destinationPath: galleryPath,
      resize: true,
    });

    // db logic

    return NextResponse.json({ resultUpload }, { status: 200 });
  } catch (error) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
