자료관 앱을 원앤올 공통 패키지 기준으로 최신화

This commit is contained in:
2026-12-05 10:57:47 +09:00
parent 9497b9c7db
commit 3ef863e329
270 changed files with 38735 additions and 2256 deletions
@@ -0,0 +1,90 @@
import { NextRequest } from "next/server";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { middleware } from "../../../../middleware";
import { GET, POST } from "./route";
import { GET as legacyPreview } from "../legacy-preview/route";
import { DC_PREVIEW_RELAY_HEADER } from "@/shared/api/dc-service-request";
const gateway = "https://gateway.invalid";
const frontend = "https://frontend.invalid";
const dc = "/dc-service/api/v1";
const current = dc + "/general-search/current-source";
const files = dc + "/general-search/files";
const imageQuery = "?fileSn=f&previewRevisionId=r&previewPage=2";
beforeEach(() => {
vi.stubEnv("NEXT_PUBLIC_DC_SERVICE_API_URL", gateway);
vi.stubEnv("RAG_V2_INGESTION_INTERNAL_API_KEY", "server-only");
});
afterEach(() => vi.unstubAllEnvs());
describe("general search gateway routing", () => {
it.each([
["GET", dc + "/fileprcs?fileSn=f"],
["GET", dc + "/fileDownload?filePath=uploads%2Fdoc.pdf&fileSn=f"],
["GET", dc + "/fileDownload?fileSn=f&revisionId=r"],
["POST", current],
["GET", current + imageQuery],
["GET", files + "/f/image-list"],
["GET", files + "/f/image-preview/report%20A.PNG"],
])("forwards %s %s to the DC gateway with the signed-in user", async (method, path) => {
const body = method === "POST" ? JSON.stringify({ fileSn: "f", previewMode: true }) : undefined;
const req = new NextRequest(frontend + path, {
method, body,
headers: {
Cookie: "Authorization=session.fixture.token", Authorization: "untrusted",
Accept: path.includes("preview") ? "image/png" : "application/json",
...(body ? { "Content-Type": "application/json" } : {}),
"X-Rag-V2-Internal-Key": "untrusted",
},
});
const response = middleware(req);
expect(response.headers.get("x-middleware-rewrite")).toBe(gateway + path);
expect(response.headers.has("Location")).toBe(false);
expect(response.headers.get("x-middleware-request-authorization")).toBe("session.fixture.token");
if (path.startsWith(dc + "/general-search/") || path.includes("revisionId=")) {
expect(response.headers.has("x-middleware-request-x-rag-v2-internal-key")).toBe(false);
}
if (path.includes("preview")) expect(response.headers.get("x-middleware-request-accept")).toBe("image/png");
if (body) {
expect(response.headers.get("x-middleware-request-content-type")).toBe("application/json");
expect(await req.text()).toBe(body);
}
});
it("stops a preview accidentally routed back to this frontend", () => {
const req = new NextRequest(frontend + current, { headers: { [DC_PREVIEW_RELAY_HEADER]: "1" } });
expect(middleware(req).status).toBe(502);
});
it("keeps the existing general search results GET in the connection-reusing handler", () => {
const response = middleware(new NextRequest(frontend + dc + "/data?searchText=f"));
expect(response.headers.get("x-middleware-next")).toBe("1");
expect(response.headers.has("x-middleware-rewrite")).toBe(false);
});
});
describe("previously published preview URLs", () => {
it.each([["GET", imageQuery], ["POST", ""]])("preserves the %s method in the redirect to DC", (method, query) => {
const req = new NextRequest(frontend + "/api/general-search/current-source" + query, { method });
const response = method === "POST" ? POST(req) : GET(req);
expect(response.status).toBe(307);
expect(response.headers.get("Location")).toBe(current + query);
});
it.each([
["fileSn=f", files + "/f/image-list"],
["fileSn=f&imageName=report%20A.png", files + "/f/image-preview/report%20A.png"],
])("keeps older image links usable (%s)", (query, expected) => {
const response = legacyPreview(new NextRequest(frontend + "/api/general-search/legacy-preview?" + query));
expect(response.status).toBe(307);
expect(response.headers.get("Location")).toBe(expected);
});
it.each(["fileSn=..", "fileSn=f&fileSn=g", "fileSn=f&imageName=..%2Fother.png", "fileSn=f&imageName=other.svg"])(
"rejects an invalid legacy link before redirecting (%s)", query => {
const response = legacyPreview(new NextRequest(frontend + "/api/general-search/legacy-preview?" + query));
expect(response.status).toBe(400);
expect(response.headers.has("Location")).toBe(false);
});
});
@@ -0,0 +1,14 @@
import type { NextRequest } from "next/server";
import { currentSourceUrl } from "@/entities/datalibrary/api/preview-routes";
export const dynamic = "force-dynamic";
// Older clients used this URL for both JSON lookups and inline page images.
function redirectToDc(request: NextRequest): Response {
return new Response(null, {
status: 307,
headers: { Location: currentSourceUrl("general-search") + request.nextUrl.search, "Cache-Control": "no-store" },
});
}
export { redirectToDc as GET, redirectToDc as POST };