From 47a02990902a0e03cdc2f058d1de2af0bb65337d Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Apr 2026 21:31:10 +0800 Subject: [PATCH] fix: ignore store filter for detail references --- .../agent-workflow/reference-search/route.ts | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app/api/agent-workflow/reference-search/route.ts b/app/api/agent-workflow/reference-search/route.ts index db7174cee..f119bfe4a 100644 --- a/app/api/agent-workflow/reference-search/route.ts +++ b/app/api/agent-workflow/reference-search/route.ts @@ -19,9 +19,21 @@ const querySchema = z.object({ queryType: z.enum(["sku", "spu"]).default("spu"), target: z.enum(["main", "detail", "sku"]), brandName: z.string().trim().max(64).optional(), - storeName: z.string().trim().max(64).optional(), }); +function jsonNoStore( + body: Parameters[0], + init?: ResponseInit +) { + return NextResponse.json(body, { + ...init, + headers: { + "Cache-Control": "no-store, max-age=0", + ...(init?.headers || {}), + }, + }); +} + type ExternalTaskDetailCandidate = { materialId?: string; taskNo?: string; @@ -228,7 +240,7 @@ export async function GET(request: NextRequest) { try { const session = await auth(); if (!session?.user?.id) { - return NextResponse.json({ error: "未登录" }, { status: 401 }); + return jsonNoStore({ error: "未登录" }, { status: 401 }); } const parsed = querySchema.parse({ @@ -236,19 +248,18 @@ export async function GET(request: NextRequest) { queryType: request.nextUrl.searchParams.get("queryType") || "spu", target: request.nextUrl.searchParams.get("target"), brandName: request.nextUrl.searchParams.get("brandName") || undefined, - storeName: request.nextUrl.searchParams.get("storeName") || undefined, }); const setting = await getSystemSetting({ key: AGENT_WORKFLOW_MATERIAL_API_CONFIG_KEY }); const config = normalizeAgentWorkflowMaterialApiConfig(setting?.value); if (!config.enabled) { - return NextResponse.json( + return jsonNoStore( { error: "素材搜索功能未开启,请先在系统设置中启用" }, { status: 400 } ); } if (!config.apiKey) { - return NextResponse.json( + return jsonNoStore( { error: "素材搜索 API Key 未配置,请先在系统设置中保存" }, { status: 500 } ); @@ -276,7 +287,7 @@ export async function GET(request: NextRequest) { const errorMessage = String(upstreamResult.error?.message || "").trim() || `参考图搜索失败(${upstreamResponse.status})`; - return NextResponse.json( + return jsonNoStore( { success: false, error: { @@ -296,7 +307,7 @@ export async function GET(request: NextRequest) { .filter((candidate) => getRenderableCandidateTargetUrls(candidate, parsed.target).length > 0); if (normalizedCandidates.length === 0) { - return NextResponse.json( + return jsonNoStore( { success: false, error: { @@ -332,7 +343,7 @@ export async function GET(request: NextRequest) { target: parsed.target, }); - return NextResponse.json({ + return jsonNoStore({ success: true, data: { query: normalizedKeyword, @@ -362,13 +373,13 @@ export async function GET(request: NextRequest) { console.error("[Agent Workflow Reference Search] Error:", error); if (error instanceof z.ZodError) { - return NextResponse.json( + return jsonNoStore( { error: "搜索参数无效", details: error.errors }, { status: 400 } ); } - return NextResponse.json( + return jsonNoStore( { error: "参考图搜索失败,请稍后重试" }, { status: 500 } );