260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성

This commit is contained in:
2026-06-23 09:54:25 +09:00
parent 28da30b865
commit 08ea4d5420
23 changed files with 1202 additions and 349 deletions

View File

@@ -0,0 +1,55 @@
import {NextRequest, NextResponse} from "next/server";
import {RouteContext} from "@/types/common";
import {errorToResponse} from "@/lib/http-util";
import {createBackApi} from "@/lib/server-api";
import {serverEnv} from "@/lib/env.server";
const contentTypeByExt = (fileName: string) => {
const ext = fileName.split(".").pop()?.toLowerCase();
if (ext === "jpg" || ext === "jpeg") return "image/jpeg";
if (ext === "png") return "image/png";
if (ext === "gif") return "image/gif";
if (ext === "webp") return "image/webp";
if (ext === "pdf") return "application/pdf";
return "application/octet-stream";
};
export const GET = async (
_req: NextRequest,
context: RouteContext
) => {
try {
const {slug = []} = await context.params;
const [type, first, second, ...rest] = slug;
const fileName = rest.join("/");
if (!type || !first || !second || !fileName || rest.length === 0) {
return NextResponse.json({message: "Not found"}, {status: 404});
}
const backApi = await createBackApi();
const basePath = type === "visit"
? `/visit-file/${encodeURIComponent(first)}/${encodeURIComponent(second)}`
: type === "review"
? `/review-file/${encodeURIComponent(first)}/${encodeURIComponent(second)}`
: "";
if (!basePath) {
return NextResponse.json({message: "Not found"}, {status: 404});
}
const encodedFileName = fileName.split("/").map((part) => encodeURIComponent(part)).join("/");
const backOrigin = new URL(serverEnv.API_BACK_SERVER).origin;
const result = await backApi.get<ArrayBuffer>(`${backOrigin}${basePath}/${encodedFileName}`, {expectBinary: true});
return new NextResponse(result, {
status: 200,
headers: {
"Content-Type": contentTypeByExt(fileName),
"Content-Disposition": `inline; filename="${encodeURIComponent(fileName)}"`,
},
});
} catch (error: unknown) {
return errorToResponse(error);
}
};