Files
jaengseung-made/app/api/admin/services/route.ts
gahusb 5fd7ab8872 feat(phase2): 사주 공개 전환 + analyze 로그인·일일제한(서버 강제)
- app/work/saju/layout.tsx: isServiceVisible 가드 제거, 사주 서비스 공개 전환
- lib/service-visibility.ts: HideableService에서 saju 제거
- app/api/admin/services/route.ts: DEFAULT_SERVICES에서 saju 행 제거
- app/api/saju/analyze/route.ts: saju_detail 결제 게이트(403) 제거,
  로그인(401) + 서버측 일일 1회 제한(429, ai_usage_log 기반)으로 교체.
  recordUsage는 실제 Gemini 해석 성공 반환 직전에만 호출(MOCK 폴백 제외)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 21:28:24 +09:00

58 lines
1.9 KiB
TypeScript

import { NextResponse } from 'next/server';
import { createAdminClient } from '@/lib/supabase/admin';
import { verifyAdminTokenNode } from '@/lib/admin-auth';
import { cookies } from 'next/headers';
export const runtime = 'nodejs';
async function checkAuth() {
const cookieStore = await cookies();
const token = cookieStore.get('admin_token')?.value;
return token && verifyAdminTokenNode(token);
}
export async function GET() {
if (!(await checkAuth())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const supabase = createAdminClient();
const { data, error } = await supabase
.from('service_settings')
.select('*')
.order('order_index');
if (error) {
// 테이블이 없으면 기본값 반환
return NextResponse.json({ services: DEFAULT_SERVICES });
}
return NextResponse.json({ services: data?.length ? data : DEFAULT_SERVICES });
}
export async function PATCH(request: Request) {
if (!(await checkAuth())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { id, is_active } = await request.json();
const supabase = createAdminClient();
const { error } = await supabase
.from('service_settings')
.upsert({ id, is_active, updated_at: new Date().toISOString() });
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
return NextResponse.json({ success: true });
}
const DEFAULT_SERVICES = [
{ id: 'music', name: 'AI 음악 팩', description: '음악 가이드 패키지·샘플·스튜디오', is_active: false, order_index: 102 },
{ id: 'gyeol', name: 'CONTOUR 설문', description: '/gyeol PMF 설문', is_active: false, order_index: 103 },
{ id: 'lotto', name: '로또 추천', description: '로또 번호 추천 노출', is_active: false, order_index: 105 },
];