From deaf27e0b6fa7d2a6cf8ee1548b4361939aee4c5 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 24 Jan 2026 08:23:29 -0800 Subject: [PATCH] fix: tighten output item guard --- src/services/jobOutputCache.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/services/jobOutputCache.ts b/src/services/jobOutputCache.ts index 4ae7140ef..4fcca2011 100644 --- a/src/services/jobOutputCache.ts +++ b/src/services/jobOutputCache.ts @@ -11,6 +11,7 @@ import QuickLRU from '@alloc/quick-lru' import type { JobDetail } from '@/platform/remote/comfyui/jobs/jobTypes' import { extractWorkflow } from '@/platform/remote/comfyui/jobs/fetchJobs' import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema' +import { resultItemType } from '@/schemas/apiSchema' import type { ResultItem, TaskOutput } from '@/schemas/apiSchema' import { api } from '@/scripts/api' import { ResultItemImpl } from '@/stores/queueStore' @@ -101,7 +102,34 @@ function getPreviewableOutputs(outputs?: TaskOutput): ResultItemImpl[] { } function isResultItem(item: unknown): item is ResultItem { - return typeof item === 'object' && item !== null + if (!item || typeof item !== 'object' || Array.isArray(item)) { + return false + } + + const candidate = item as Record + + if ( + candidate.filename !== undefined && + typeof candidate.filename !== 'string' + ) { + return false + } + + if ( + candidate.subfolder !== undefined && + typeof candidate.subfolder !== 'string' + ) { + return false + } + + if ( + candidate.type !== undefined && + !resultItemType.safeParse(candidate.type).success + ) { + return false + } + + return true } export function getPreviewableOutputsFromJobDetail(