feat: 스튜디오 페이지 + Suno API 프록시 + 팩 상세 가격 최상단 재구성
- TopNav: 홈/샘플/팩 상세/스튜디오 4개 링크 구조 - /services/music: 컴팩트 헤더 + PRICING 최상단 배치 (상세 포맷) - /studio: Suno Generate UI (simple/custom 모드, 태그 프리셋, 폴링) - /api/studio/generate, /api/studio/status: Suno API 프록시
This commit is contained in:
76
app/api/studio/generate/route.ts
Normal file
76
app/api/studio/generate/route.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
type GenerateBody = {
|
||||
mode: 'simple' | 'custom';
|
||||
prompt?: string;
|
||||
title?: string;
|
||||
lyrics?: string;
|
||||
tags?: string;
|
||||
make_instrumental?: boolean;
|
||||
model?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const apiUrl = process.env.SUNO_API_URL;
|
||||
const apiKey = process.env.SUNO_API_KEY;
|
||||
|
||||
if (!apiUrl || !apiKey) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Suno API 미설정 (SUNO_API_URL / SUNO_API_KEY 환경변수 필요)' },
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
let body: GenerateBody;
|
||||
try {
|
||||
body = (await request.json()) as GenerateBody;
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
||||
}
|
||||
|
||||
const endpoint = body.mode === 'custom' ? '/api/custom_generate' : '/api/generate';
|
||||
|
||||
const payload =
|
||||
body.mode === 'custom'
|
||||
? {
|
||||
prompt: body.lyrics ?? '',
|
||||
tags: body.tags ?? '',
|
||||
title: body.title ?? '',
|
||||
make_instrumental: !!body.make_instrumental,
|
||||
model: body.model ?? 'chirp-v3-5',
|
||||
wait_audio: false,
|
||||
}
|
||||
: {
|
||||
prompt: body.prompt ?? '',
|
||||
make_instrumental: !!body.make_instrumental,
|
||||
model: body.model ?? 'chirp-v3-5',
|
||||
wait_audio: false,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch(`${apiUrl.replace(/\/$/, '')}${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => null);
|
||||
if (!res.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: '생성 실패', detail: data ?? (await res.text().catch(() => '')) },
|
||||
{ status: res.status },
|
||||
);
|
||||
}
|
||||
return NextResponse.json({ ok: true, data });
|
||||
} catch (e) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Suno API 호출 오류', detail: e instanceof Error ? e.message : String(e) },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user