yue2-studio / src /app /api /upload /route.ts
RalphThings's picture
Upload folder using huggingface_hub
bf68acd verified
Raw History Blame Contribute Delete
1.01 kB
import { NextResponse } from "next/server";
import { IS_MOCK, uploadAudio } from "@/lib/comfy/client";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
const MAX_BYTES = 120 * 1024 * 1024;
export async function POST(request: Request) {
const form = await request.formData().catch(() => null);
const file = form?.get("file");
if (!(file instanceof File)) {
return NextResponse.json({ error: "No file in the request" }, { status: 400 });
}
if (file.size > MAX_BYTES) {
return NextResponse.json({ error: "That file is larger than 120 MB" }, { status: 413 });
}
if (IS_MOCK) {
return NextResponse.json({ filename: file.name, name: file.name, size: file.size });
}
try {
const filename = await uploadAudio(file);
return NextResponse.json({ filename, name: file.name, size: file.size });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Upload failed" },
{ status: 502 },
);
}
}