fix: ignore store filter for detail references
This commit is contained in:
parent
807aba1e85
commit
47a0299090
@ -19,9 +19,21 @@ const querySchema = z.object({
|
|||||||
queryType: z.enum(["sku", "spu"]).default("spu"),
|
queryType: z.enum(["sku", "spu"]).default("spu"),
|
||||||
target: z.enum(["main", "detail", "sku"]),
|
target: z.enum(["main", "detail", "sku"]),
|
||||||
brandName: z.string().trim().max(64).optional(),
|
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 = {
|
type ExternalTaskDetailCandidate = {
|
||||||
materialId?: string;
|
materialId?: string;
|
||||||
taskNo?: string;
|
taskNo?: string;
|
||||||
@ -228,7 +240,7 @@ export async function GET(request: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user?.id) {
|
if (!session?.user?.id) {
|
||||||
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
return jsonNoStore({ error: "未登录" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = querySchema.parse({
|
const parsed = querySchema.parse({
|
||||||
@ -236,19 +248,18 @@ export async function GET(request: NextRequest) {
|
|||||||
queryType: request.nextUrl.searchParams.get("queryType") || "spu",
|
queryType: request.nextUrl.searchParams.get("queryType") || "spu",
|
||||||
target: request.nextUrl.searchParams.get("target"),
|
target: request.nextUrl.searchParams.get("target"),
|
||||||
brandName: request.nextUrl.searchParams.get("brandName") || undefined,
|
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 setting = await getSystemSetting({ key: AGENT_WORKFLOW_MATERIAL_API_CONFIG_KEY });
|
||||||
const config = normalizeAgentWorkflowMaterialApiConfig(setting?.value);
|
const config = normalizeAgentWorkflowMaterialApiConfig(setting?.value);
|
||||||
if (!config.enabled) {
|
if (!config.enabled) {
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{ error: "素材搜索功能未开启,请先在系统设置中启用" },
|
{ error: "素材搜索功能未开启,请先在系统设置中启用" },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!config.apiKey) {
|
if (!config.apiKey) {
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{ error: "素材搜索 API Key 未配置,请先在系统设置中保存" },
|
{ error: "素材搜索 API Key 未配置,请先在系统设置中保存" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
@ -276,7 +287,7 @@ export async function GET(request: NextRequest) {
|
|||||||
const errorMessage =
|
const errorMessage =
|
||||||
String(upstreamResult.error?.message || "").trim() ||
|
String(upstreamResult.error?.message || "").trim() ||
|
||||||
`参考图搜索失败(${upstreamResponse.status})`;
|
`参考图搜索失败(${upstreamResponse.status})`;
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
@ -296,7 +307,7 @@ export async function GET(request: NextRequest) {
|
|||||||
.filter((candidate) => getRenderableCandidateTargetUrls(candidate, parsed.target).length > 0);
|
.filter((candidate) => getRenderableCandidateTargetUrls(candidate, parsed.target).length > 0);
|
||||||
|
|
||||||
if (normalizedCandidates.length === 0) {
|
if (normalizedCandidates.length === 0) {
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
@ -332,7 +343,7 @@ export async function GET(request: NextRequest) {
|
|||||||
target: parsed.target,
|
target: parsed.target,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return jsonNoStore({
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
query: normalizedKeyword,
|
query: normalizedKeyword,
|
||||||
@ -362,13 +373,13 @@ export async function GET(request: NextRequest) {
|
|||||||
console.error("[Agent Workflow Reference Search] Error:", error);
|
console.error("[Agent Workflow Reference Search] Error:", error);
|
||||||
|
|
||||||
if (error instanceof z.ZodError) {
|
if (error instanceof z.ZodError) {
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{ error: "搜索参数无效", details: error.errors },
|
{ error: "搜索参数无效", details: error.errors },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json(
|
return jsonNoStore(
|
||||||
{ error: "参考图搜索失败,请稍后重试" },
|
{ error: "参考图搜索失败,请稍后重试" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user