261027_02_ENH: kric-internal에 project-list 추가
This commit is contained in:
@@ -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<string, string> = {};
|
||||
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<unknown>(target.path, options)
|
||||
: await api.post<unknown>(target.path, body, options);
|
||||
let result: unknown;
|
||||
if (target.kind === "list") {
|
||||
result = await api.get<unknown>(target.path, options);
|
||||
} else if (target.kind === "projects") {
|
||||
result = await api.get<unknown>(target.path, { ...options, query });
|
||||
} else {
|
||||
result = await api.post<unknown>(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<string, string> = {
|
||||
...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");
|
||||
|
||||
Reference in New Issue
Block a user