import {NextRequest, NextResponse} from "next/server"; import {RouteContext} from "@/types/common"; import {createContactApi} from "@/lib/http-server"; import {errorToResponse} from "@kri/common/http"; import type { KkoSenderProfile } from "@/types/message"; import type { KkoTemplateDetail, KkoTemplateListResponse, Template, TemplateSummary } from "@kri/common/noti-hub"; // 외부 알림톡 템플릿 목록·상세 조회. JSON 본문을 contact-back에 그대로 전달한다. export const POST = async (req: NextRequest, context: RouteContext) => { try{ const {slug = []} = await context.params; const [channel, action] = slug; if (channel !== "kko" || slug.length !== 2 || (action !== "list" && action !== "detail")) { return NextResponse.json({ message: "Not found" }, { status: 404 }); } const body = await req.json().catch(() => null); if (!body || typeof body !== "object") { return NextResponse.json({ message: "요청 바디가 없습니다." }, { status: 400 }); } const contactApi = await createContactApi(); const result = action === "list" ? await contactApi.post(`/message-template/kko/list`, body) : await contactApi.post(`/message-template/kko/detail`, body); return NextResponse.json(result, { status: 200 }); } catch (error: unknown) { return errorToResponse(error); } } export const GET = async (req: NextRequest, context: RouteContext) => { try{ const { searchParams } = new URL(req.url); const {slug = []} = await context.params; const [action] = slug; const contactApi = await createContactApi(); if (slug.length === 2 && action === "kko" && slug[1] === "profiles") { const result = await contactApi.get(`/message-template/kko/profiles`); return NextResponse.json(result, { status: 200 }); } if(slug.length === 2 && slug[1] === "attachment"){ const fileName = searchParams.get("fileName"); if (!fileName) { return NextResponse.json({ message: "fileName은 필수입니다." }, { status: 400 }); } const result = await contactApi.get( `/message-template/${slug[0]}/attachment?fileName=${encodeURIComponent(fileName)}`, { expectBinary: true }, ); return new NextResponse(result, { status: 200, headers: { "Content-Type": "application/octet-stream" } }); } if(slug.length === 1){ const result = await contactApi.get