260629_01_ENH: PDF 미리보기 파일명 노출될 수 있도록 수정 및 KON용 code 조회 추가

This commit is contained in:
2026-06-29 11:33:29 +09:00
parent a09dded4ca
commit 1234d16db4
5 changed files with 137 additions and 23 deletions

View File

@@ -2,7 +2,7 @@ import {NextRequest, NextResponse} from "next/server";
import {RouteContext} from "@/types/common";
import {errorToResponse} from "@/lib/http-util";
import {createBackApi} from "@/lib/server-api";
import {PerformanceCompact, PerformanceFull} from "@/types/gwcf";
import {Code, PerformanceCompact, PerformanceFull} from "@/types/gwcf";
const ALLOWED_ORIGIN = "https://kon.kric.com";
@@ -66,6 +66,11 @@ export const POST = async (
const [action] = slug;
const backApi = await createBackApi();
if(action === "code" && slug.length === 2) {
const result = await backApi.get<Code[]>(`/code/${encodeURIComponent(slug[1])}`)
return withCors(NextResponse.json(result, { status: 200 }));
}
if(action === "assign-confirm" && slug.length === 3) {
const result = await backApi.post<string>(
`/assign/confirm/${encodeURIComponent(slug[1])}/${encodeURIComponent(slug[2])}`

View File

@@ -10,6 +10,17 @@ import {CookieKeys} from "@/store/cookie/cookie-keys";
const reviewFileName = (prefix: string, performanceId: string, reviewType: string) =>
`${prefix}-${performanceId}-${reviewType}`;
const replaceContentDispositionType = (
contentDisposition: string | null,
disposition: "inline" | "attachment",
fallbackFileName: string
) => {
const fileNamePart = contentDisposition?.split(";").slice(1).join(";");
return fileNamePart
? `${disposition};${fileNamePart}`
: `${disposition}; filename="${fallbackFileName}"`;
};
export const GET = async (
req: NextRequest,
context: RouteContext
@@ -44,16 +55,28 @@ export const GET = async (
}
if (action === "template" && second === "pdf" && third && fourth && slug.length === 4) {
const result = await backApi.get<ArrayBuffer>(
`/review/template/pdf/${encodeURIComponent(third)}/${encodeURIComponent(fourth)}`,
{ expectBinary: true }
);
const cookieStore = await cookies();
const accessToken = cookieStore.get(CookieKeys.AuthToken)?.value;
const response = await fetch(`${serverEnv.API_BACK_SERVER.replace(/\/+$/, "")}/review/template/pdf/${encodeURIComponent(third)}/${encodeURIComponent(fourth)}`, {
headers: accessToken ? {authorization: `Bearer ${accessToken}`} : undefined,
cache: "no-store",
});
if (!response.ok) {
return new NextResponse(await response.text().catch(() => ""), {status: response.status});
}
const result = await response.arrayBuffer();
const disposition = req.nextUrl.searchParams.get("disposition") === "inline" ? "inline" : "attachment";
return new NextResponse(result, {
status: 200,
headers: {
"Content-Type": "application/pdf",
"Content-Disposition": `${disposition}; filename="review-template-${third}-${fourth}.pdf"`,
"Content-Disposition": replaceContentDispositionType(
response.headers.get("content-disposition"),
disposition,
`review-template-${third}-${fourth}.pdf`
),
},
});
}