feat(portal): Co-Lite labels only filter on Translations

On by default. The portal server sends its own label codes to the new
search; unchecking lists every label as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-02 14:55:56 +08:00
1 parent d2cbc3c227
commit 918f5fa2b2
12 files changed
+70 -8

No files matched your search

@@ -5,6 +5,7 @@ vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileAp
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
import { GET, POST, PUT } from "./route";
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
type Req = Parameters<typeof GET>[0];
const req = (url: string, init?: RequestInit) => new Request(url, init) as unknown as Req;
@@ -29,6 +30,24 @@ describe("/api/messages", () => {
`/api/admin/messages?searchKey=${encodeURIComponent("线索")}&missingLocale=zh_CN&page=0&size=20`, { token: "jwt" });
});
it("own=1 searches the portal's own label codes, built on the server", async () => {
await GET(req("http://localhost/api/messages?own=1&searchKey=lead&missingLocale=zh_CN&page=2&size=50&codes=Evil"), ctx());
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/messages/search", {
method: "POST",
body: { searchKey: "lead", missingLocale: "zh_CN", page: 2, size: 50, codes: Object.keys(DEFAULT_MESSAGES) },
token: "jwt",
});
});
it("own=1 without filters sends page defaults and no empty filters", async () => {
await GET(req("http://localhost/api/messages?own=1"), ctx());
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/messages/search", {
method: "POST",
body: { page: 0, size: 20, codes: Object.keys(DEFAULT_MESSAGES) },
token: "jwt",
});
});
it("forwards detail and export reads", async () => {
await GET(req("http://localhost/api/messages/7"), ctx(["7"]));
expect(mocks.callMobileApi).toHaveBeenLastCalledWith("/api/admin/messages/7", { token: "jwt" });
@@ -2,9 +2,10 @@ import { NextResponse, type NextRequest } from "next/server";
import { callMobileApi } from "@/app/lib/server/mobileApi";
import { getToken } from "@/app/lib/server/session";
import { badRequest, errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
// Proxy for /api/admin/messages (area A labels). mobile-api owns the BO_MESSAGES guard.
// Reads: list, /{id}, /export. Writes: PUT /{id} (content only), POST /import. No create, no delete.
// Reads: list (own=1 limits it to the portal's own label codes), /{id}, /export. Writes: PUT /{id} (content only), POST /import. No create, no delete.
type Ctx = { params: Promise<{ path?: string[] }> };
const ID = /^\d+$/;
@@ -14,6 +15,18 @@ export async function GET(req: NextRequest, { params }: Ctx) {
const { path = [] } = await params;
if (path.length === 0) {
const q = new URL(req.url).searchParams;
if (q.get("own") === "1") {
// Co-Lite labels only: the codes come from the built-in list here, never from the browser.
const body: Record<string, unknown> = {};
for (const key of ["searchKey", "missingLocale"]) {
const v = q.get(key);
if (v) body[key] = v;
}
body.page = Number(q.get("page")) || 0;
body.size = Number(q.get("size")) || 20;
body.codes = Object.keys(DEFAULT_MESSAGES);
return forward("/api/admin/messages/search", { method: "POST", body, token });
}
const out = new URLSearchParams();
for (const key of ["searchKey", "missingLocale"]) {
const v = q.get(key);