From 088d9abee3d8a9fb7b4e13b82e629ebe4b8a3def Mon Sep 17 00:00:00 2001 From: Alistair Hughes Date: Sun, 12 May 2024 17:15:48 +0100 Subject: [PATCH] add missing file --- src/app/api/clip/route.ts | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/app/api/clip/route.ts diff --git a/src/app/api/clip/route.ts b/src/app/api/clip/route.ts new file mode 100644 index 0000000..9e00478 --- /dev/null +++ b/src/app/api/clip/route.ts @@ -0,0 +1,48 @@ +import { NextResponse, NextRequest } from "next/server"; +import { sunoApi } from "@/lib/SunoApi"; +import { corsHeaders } from "@/lib/utils"; + +export const dynamic = "force-dynamic"; + +export async function GET(req: NextRequest) { + if (req.method === 'GET') { + try { + const url = new URL(req.url); + const clipId = url.searchParams.get('id'); + const audioInfo = await (await sunoApi).getClip(clipId); + + return new NextResponse(JSON.stringify(audioInfo), { + status: 200, + headers: { + 'Content-Type': 'application/json', + ...corsHeaders + } + }); + } catch (error) { + console.error('Error fetching audio:', error); + + return new NextResponse(JSON.stringify({ error: 'Internal server error' }), { + status: 500, + headers: { + 'Content-Type': 'application/json', + ...corsHeaders + } + }); + } + } else { + return new NextResponse('Method Not Allowed', { + headers: { + Allow: 'GET', + ...corsHeaders + }, + status: 405 + }); + } +} + +export async function OPTIONS(request: Request) { + return new Response(null, { + status: 200, + headers: corsHeaders + }); +}