From dfec8d7ee303d6ce89ab6ea8e98566b7e25d0f6b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Apr 2026 22:49:35 +0800 Subject: [PATCH] fix: prevent psd templates leaking across brands --- app/api/psd-templates/route.ts | 2 +- .../agents/AgentGenerationWorkspaceDarkV2.tsx | 16 ++++++--- .../agents/AgentPsdTemplateEditorDialog.tsx | 34 ++++++++++++++----- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/api/psd-templates/route.ts b/app/api/psd-templates/route.ts index a2336871a..6a8407fa0 100644 --- a/app/api/psd-templates/route.ts +++ b/app/api/psd-templates/route.ts @@ -174,7 +174,7 @@ export async function GET(request: NextRequest) { } satisfies AgentPsdTemplateListResponse); response.headers.set( "Cache-Control", - "private, max-age=60, stale-while-revalidate=300" + "private, no-store, max-age=0" ); return response; } catch (error) { diff --git a/components/agents/AgentGenerationWorkspaceDarkV2.tsx b/components/agents/AgentGenerationWorkspaceDarkV2.tsx index 7528e8af5..ae2969c34 100644 --- a/components/agents/AgentGenerationWorkspaceDarkV2.tsx +++ b/components/agents/AgentGenerationWorkspaceDarkV2.tsx @@ -4585,6 +4585,12 @@ export function AgentGenerationWorkspaceDarkV2({ ); + const currentPsdWorkflowContext = getLatestWorkflowContext?.() ?? workflowContext; + const currentPsdBrandName = String(currentPsdWorkflowContext?.brand || "").trim(); + const currentPsdFifthCategory = String( + currentPsdWorkflowContext?.fifthCategory || "" + ).trim(); + return (
=> { try { - const response = await fetch(url, { cache: "default" }); + const response = await fetch(url, { cache: "no-store" }); const payload = (await response .json() .catch(() => null)) as Partial | null; @@ -511,6 +511,15 @@ function normalizeManagedBrandName(value?: string | null) { return normalized; } +function matchesTemplateBrand(template: AgentPsdTemplate, brandName?: string | null) { + const normalizedBrandName = normalizeManagedBrandName(brandName).toLowerCase(); + if (!normalizedBrandName) { + return true; + } + + return normalizeManagedBrandName(template.brandName).toLowerCase() === normalizedBrandName; +} + function getEffectiveTemplateCategoryTags( template: AgentPsdTemplate, activeCategoryTags: string[] @@ -1449,14 +1458,21 @@ export function AgentPsdTemplateEditorDialog({ ); const templates = useMemo( () => - allTemplates.filter((template) => - matchesTemplateSelectedCategories( - template, - normalizedSelectedCategoryNames, - activeCategoryTags - ) - ), - [activeCategoryTags, allTemplates, normalizedSelectedCategoryNames] + allTemplates + .filter((template) => matchesTemplateBrand(template, normalizedBrandName)) + .filter((template) => + matchesTemplateSelectedCategories( + template, + normalizedSelectedCategoryNames, + activeCategoryTags + ) + ), + [ + activeCategoryTags, + allTemplates, + normalizedBrandName, + normalizedSelectedCategoryNames, + ] ); const [selectedTemplateId, setSelectedTemplateId] = useState(""); const selectedTemplateDetailRequestUrl = useMemo(() => {