Files
jaengseung-made/app/api/tools/naver-blog/generate/route.ts
gahusb 3537862c99 feat: 도구 쇼케이스 페이지 + 네이버 블로그 AI 자동화 툴
- 사이드바 "이베이 부품 검색" → "여긴 뭐 만들어요?" (DEMO 배지, /tools)
- /tools 쇼케이스: 완성형 레퍼런스 데모 카드 그리드 + 상담 CTA
- /tools/naver-blog: 주제·키워드·형식·톤·분량 선택 → AI 블로그 글 자동 생성
- 결과 3탭 (글 미리보기·SEO 정보·이미지 가이드) + 전체 복사
- Claude API 연동 SEO 최적화 프롬프트 + fallback 지원

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 00:59:00 +09:00

66 lines
2.5 KiB
TypeScript

import { NextResponse } from 'next/server';
import { generateBlogPost } from '@/lib/blog-tools/generator';
import type { BlogStyle, BlogTone, BlogLength } from '@/lib/blog-tools/types';
export const maxDuration = 60;
const VALID_STYLES: BlogStyle[] = ['informational', 'review', 'howto', 'listicle', 'comparison', 'story'];
const VALID_TONES: BlogTone[] = ['professional', 'friendly', 'casual', 'formal'];
const VALID_LENGTHS: BlogLength[] = ['short', 'medium', 'long'];
export async function POST(request: Request) {
try {
const body = await request.json();
const { topic, keywords, style, tone, length, imageGuide, sections } = body;
// 유효성 검증
if (!topic || typeof topic !== 'string' || topic.trim().length === 0) {
return NextResponse.json({ success: false, error: '주제를 입력해주세요.' }, { status: 400 });
}
if (topic.trim().length > 100) {
return NextResponse.json({ success: false, error: '주제는 100자 이내로 입력해주세요.' }, { status: 400 });
}
if (!Array.isArray(keywords) || keywords.length === 0) {
return NextResponse.json({ success: false, error: '키워드를 최소 1개 입력해주세요.' }, { status: 400 });
}
if (keywords.length > 10) {
return NextResponse.json({ success: false, error: '키워드는 최대 10개까지 가능합니다.' }, { status: 400 });
}
if (!VALID_STYLES.includes(style)) {
return NextResponse.json({ success: false, error: '유효하지 않은 글 형식입니다.' }, { status: 400 });
}
if (!VALID_TONES.includes(tone)) {
return NextResponse.json({ success: false, error: '유효하지 않은 톤입니다.' }, { status: 400 });
}
if (!VALID_LENGTHS.includes(length)) {
return NextResponse.json({ success: false, error: '유효하지 않은 분량입니다.' }, { status: 400 });
}
const sectionCount = Math.min(Math.max(Number(sections) || 4, 3), 8);
const result = await generateBlogPost({
topic: topic.trim(),
keywords: keywords.map((k: string) => k.trim()).filter(Boolean),
style,
tone,
length,
imageGuide: Boolean(imageGuide),
sections: sectionCount,
});
return NextResponse.json(result, { status: 200 });
} catch (error) {
console.error('[NaverBlog] Generate error:', error);
return NextResponse.json(
{ success: false, error: '블로그 글 생성 중 오류가 발생했습니다.' },
{ status: 500 }
);
}
}