
1. Use the model number as an optional parameter, defaulting to 3.5; 2. Improve documentation.
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { NextResponse, NextRequest } from "next/server";
|
|
import { DEFAULT_MODEL, sunoApi } from "@/lib/SunoApi";
|
|
import { corsHeaders } from "@/lib/utils";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
if (req.method === 'POST') {
|
|
try {
|
|
const body = await req.json();
|
|
const { audio_id, prompt, continue_at, tags, title, model } = body;
|
|
|
|
if (!audio_id) {
|
|
return new NextResponse(JSON.stringify({ error: 'Audio ID is required' }), {
|
|
status: 400,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...corsHeaders
|
|
}
|
|
});
|
|
}
|
|
|
|
const audioInfo = await (await sunoApi)
|
|
.extendAudio(audio_id, prompt, continue_at, tags, title, model || DEFAULT_MODEL);
|
|
|
|
return new NextResponse(JSON.stringify(audioInfo), {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...corsHeaders
|
|
}
|
|
});
|
|
} catch (error: any) {
|
|
console.error('Error extend audio:', JSON.stringify(error.response.data));
|
|
if (error.response.status === 402) {
|
|
return new NextResponse(JSON.stringify({ error: error.response.data.detail }), {
|
|
status: 402,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...corsHeaders
|
|
}
|
|
});
|
|
}
|
|
return new NextResponse(JSON.stringify({ error: 'Internal server error: ' + JSON.stringify(error.response.data.detail) }), {
|
|
status: 500,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...corsHeaders
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
return new NextResponse('Method Not Allowed', {
|
|
headers: {
|
|
Allow: 'POST',
|
|
...corsHeaders
|
|
},
|
|
status: 405
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
export async function OPTIONS(request: Request) {
|
|
return new Response(null, {
|
|
status: 200,
|
|
headers: corsHeaders
|
|
});
|
|
} |