261027_01_ENH: 사내 연동 API에 url copy 추가

This commit is contained in:
2026-10-27 09:03:18 +09:00
parent d4747b0ea0
commit a1f39c74de
4 changed files with 118 additions and 56 deletions

View File

@@ -5,8 +5,11 @@ import {
internalTarget,
readInternalQuotaRequest,
readInternalReportBatch,
readInternalShareRequest,
} from "@/lib/kric-internal-policy";
import { readExcelRequest } from "@/types/export";
import { isRecord } from "@/types/kart";
import { isShareLink } from "@/types/share";
import type { RouteContext } from "@/types/common";
export const maxDuration = 660;
@@ -22,7 +25,7 @@ async function handle(request: NextRequest, context: RouteContext) {
if (!apiKey) return jsonError("X-API-Key는 필수입니다.", 401);
let body: unknown;
if (target.kind !== "list") {
if (target.kind !== "list" && target.kind !== "respondent") {
try {
const input: unknown = await request.json();
body =
@@ -30,7 +33,9 @@ async function handle(request: NextRequest, context: RouteContext) {
? readInternalReportBatch(input)
: target.kind === "quota"
? readInternalQuotaRequest(input)
: readExcelRequest(input);
: target.kind === "share"
? readInternalShareRequest(input)
: readExcelRequest(input);
} catch (error) {
return jsonError(
error instanceof SyntaxError
@@ -46,11 +51,26 @@ async function handle(request: NextRequest, context: RouteContext) {
try {
const api = createServerApiWithApiKey(apiKey);
const options = { signal: request.signal, cache: "no-store" as const };
if (target.kind === "list" || target.kind === "quota") {
if (
target.kind === "list" ||
target.kind === "quota" ||
target.kind === "respondent" ||
target.kind === "share"
) {
const result =
target.kind === "list"
? await api.get<unknown>(target.path, options)
: await api.post<unknown>(target.path, body, options);
if (
target.kind === "share" &&
(!isShareLink(result) ||
result.projectType !== Number(slug[1]) ||
result.pkey !== slug[2] ||
result.pageOnly ||
!isRecord(body) ||
result.realUrl !== body.realUrl)
)
return jsonError("공유 링크 응답을 확인해 주세요.", 502);
return NextResponse.json(result, { headers: noStore });
}
const upstream = await api.streamPost(target.path, body, {