fix: ignore store filter for detail references
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-04-27 21:31:10 +08:00
parent 807aba1e85
commit 47a0299090

View File

@ -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<typeof NextResponse.json>[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 }
);