"use server";

import { Buffer } from "node:buffer";
import { randomUUID } from "node:crypto";
import { NextResponse } from "next/server";

const BUCKET = "media";
const DIRECTORY = "luckysheet";

export async function POST(request: Request) {
  return NextResponse.json({ code: 501, msg: "当前仅支持 Convex 模式" }, { status: 501 });

  /*
  const supabase = await createSupabaseRouteClient();
  const formData = await request.formData();
  const file = formData.get("image");

  if (!(file instanceof File)) {
    return NextResponse.json({ code: 400, msg: "缺少 image 文件" }, { status: 400 });
  }

  const arrayBuffer = await file.arrayBuffer();
  const buffer = Buffer.from(arrayBuffer);
  const extension = file.name?.split(".").pop() || "bin";
  const objectPath = `${DIRECTORY}/${randomUUID()}.${extension}`;

  const { error: uploadError } = await supabase.storage
    .from(BUCKET)
    .upload(objectPath, buffer, { contentType: file.type || "application/octet-stream", upsert: false });

  if (uploadError) {
    return NextResponse.json({ code: 500, msg: "上传失败", detail: uploadError.message }, { status: 500 });
  }

  const {
    data: { publicUrl },
  } = supabase.storage.from(BUCKET).getPublicUrl(objectPath);

  return NextResponse.json({
    code: 200,
    msg: "ok",
    url: publicUrl,
  });
  */
}
