From c6cc7edfc762b3a4dba20a1bef195784128b15cd Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 27 Oct 2026 14:55:05 +0900 Subject: [PATCH] =?UTF-8?q?261027=5F02=5FENH:=20kric-internal=EC=97=90=20p?= =?UTF-8?q?roject-list=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/kric-internal/[[...slug]]/route.ts | 76 +++++++++++-------- src/lib/kric-internal-policy.ts | 17 ++++- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/app/api/kric-internal/[[...slug]]/route.ts b/src/app/api/kric-internal/[[...slug]]/route.ts index a402756..63071d7 100644 --- a/src/app/api/kric-internal/[[...slug]]/route.ts +++ b/src/app/api/kric-internal/[[...slug]]/route.ts @@ -3,6 +3,7 @@ import { errorToResponse } from "@kri/common/http"; import { createServerApiWithApiKey } from "@/lib/http-server"; import { internalTarget, + readInternalProjectListQuery, readInternalQuotaRequest, readInternalReportBatch, readInternalShareRequest, @@ -25,26 +26,33 @@ async function handle(request: NextRequest, context: RouteContext) { if (!apiKey) return jsonError("X-API-Key는 필수입니다.", 401); let body: unknown; - if (target.kind !== "list" && target.kind !== "respondent") { + let query: Record = {}; + if (target.kind === "projects") { + try { + query = readInternalProjectListQuery(request.nextUrl.searchParams); + } catch (error) { + return jsonError(error instanceof Error ? error.message : "조회 조건을 확인해 주세요.", 400); + } + } else if (target.kind !== "list" && target.kind !== "respondent") { try { const input: unknown = await request.json(); - body = - target.kind === "report" - ? readInternalReportBatch(input) - : target.kind === "quota" - ? readInternalQuotaRequest(input) - : target.kind === "share" - ? readInternalShareRequest(input) - : readExcelRequest(input); + if (target.kind === "report") { + body = readInternalReportBatch(input); + } else if (target.kind === "quota") { + body = readInternalQuotaRequest(input); + } else if (target.kind === "share") { + body = readInternalShareRequest(input); + } else { + body = readExcelRequest(input); + } } catch (error) { - return jsonError( - error instanceof SyntaxError - ? "요청 JSON을 확인해 주세요." - : error instanceof Error - ? error.message - : "요청 내용을 확인해 주세요.", - 400, - ); + let message = "요청 내용을 확인해 주세요."; + if (error instanceof SyntaxError) { + message = "요청 JSON을 확인해 주세요."; + } else if (error instanceof Error) { + message = error.message; + } + return jsonError(message, 400); } } @@ -53,14 +61,19 @@ async function handle(request: NextRequest, context: RouteContext) { const options = { signal: request.signal, cache: "no-store" as const }; if ( target.kind === "list" || + target.kind === "projects" || target.kind === "quota" || target.kind === "respondent" || target.kind === "share" ) { - const result = - target.kind === "list" - ? await api.get(target.path, options) - : await api.post(target.path, body, options); + let result: unknown; + if (target.kind === "list") { + result = await api.get(target.path, options); + } else if (target.kind === "projects") { + result = await api.get(target.path, { ...options, query }); + } else { + result = await api.post(target.path, body, options); + } if ( target.kind === "share" && (!isShareLink(result) || @@ -93,17 +106,16 @@ async function handle(request: NextRequest, context: RouteContext) { await upstream.body?.cancel(); return jsonError("서버 응답 형식을 확인해 주세요.", 502); } - return new Response(upstream.body, { - headers: { - ...noStore, - "Content-Type": contentType, - ...(target.kind === "report" - ? { "X-Accel-Buffering": "no" } - : disposition - ? { "Content-Disposition": disposition } - : {}), - }, - }); + const headers: Record = { + ...noStore, + "Content-Type": contentType, + }; + if (target.kind === "report") { + headers["X-Accel-Buffering"] = "no"; + } else if (disposition) { + headers["Content-Disposition"] = disposition; + } + return new Response(upstream.body, { headers }); } catch (error: unknown) { const response = errorToResponse(error); response.headers.set("Cache-Control", "no-store"); diff --git a/src/lib/kric-internal-policy.ts b/src/lib/kric-internal-policy.ts index 8943fc4..7a55cf7 100644 --- a/src/lib/kric-internal-policy.ts +++ b/src/lib/kric-internal-policy.ts @@ -4,6 +4,7 @@ import { isQuotaResultPath, isReportStreamPath, isProjectReadPath, + projectReadQuery, } from "@/lib/project-proxy-policy"; import { isRecord, validDateRange } from "@/types/kart"; import { readReportBatch } from "@/lib/report-contract"; @@ -12,9 +13,21 @@ import { reportUrl } from "@/types/share"; type Target = { path: string; - kind: "list" | "quota" | "report" | "excel" | "respondent" | "share"; + kind: "list" | "projects" | "quota" | "report" | "excel" | "respondent" | "share"; }; +/** Linked lookup only: without all three keys the server would list the API key owner's projects. */ +export function readInternalProjectListQuery(search: URLSearchParams) { + const query = projectReadQuery(["list"], search); + if ( + !["0", "1"].includes(query.projectType ?? "") || + !query.intranetCode?.trim() || + !query.userTeam?.trim() + ) + throw new Error("projectType(0|1), intranetCode, userTeam을 함께 입력해 주세요."); + return query; +} + /** URL Copy only: the server resolves the project from the authenticated path. */ export function readInternalShareRequest(value: unknown) { if (!isRecord(value) || value.mode !== "U") @@ -39,6 +52,8 @@ export function internalTarget(method: string, slug: string[]): Target | null { const path = "/" + slug.map(encodeURIComponent).join("/"); if (method === "GET" && area === "quota" && isQuotaListPath(parts)) return { path, kind: "list" }; + if (method === "GET" && area === "project" && parts.length === 1 && parts[0] === "list") + return { path, kind: "projects" }; if (method !== "POST") return null; if ( area === "project" &&