From c73cda97987c8ebf042bfc2f6a45e079ff8ff682 Mon Sep 17 00:00:00 2001 From: Koshi Date: Wed, 1 Apr 2026 22:34:16 +0200 Subject: [PATCH] refactor: extract shared parsing helper and export DropIndicatorData type --- src/components/builder/dropIndicatorUtil.ts | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/builder/dropIndicatorUtil.ts b/src/components/builder/dropIndicatorUtil.ts index 0b1f1a0efc..46cd2fafc0 100644 --- a/src/components/builder/dropIndicatorUtil.ts +++ b/src/components/builder/dropIndicatorUtil.ts @@ -6,7 +6,7 @@ import { api } from '@/scripts/api' import { app } from '@/scripts/app' import { parseImageWidgetValue } from '@/utils/imageUtil' -interface DropIndicatorData { +export interface DropIndicatorData { iconClass: string imageUrl?: string videoUrl?: string @@ -17,6 +17,13 @@ interface DropIndicatorData { onRemove?: () => void } +function parseNodeMediaValue(node: LGraphNode) { + const stringValue = extractWidgetStringValue(node.widgets?.[0]?.value) + return stringValue + ? parseImageWidgetValue(stringValue) + : { filename: '', subfolder: '', type: 'input' } +} + /** * Build a DropZone indicator for LoadImage or LoadVideo nodes. * Returns undefined for other node types. @@ -49,11 +56,7 @@ function buildImageDropIndicator( openMaskEditor?: (node: LGraphNode) => void } ): DropIndicatorData { - const stringValue = extractWidgetStringValue(node.widgets?.[0]?.value) - - const { filename, subfolder, type } = stringValue - ? parseImageWidgetValue(stringValue) - : { filename: '', subfolder: '', type: 'input' } + const { filename, subfolder, type } = parseNodeMediaValue(node) const rawParams = filename ? new URLSearchParams({ filename, subfolder, type }) @@ -67,7 +70,9 @@ function buildImageDropIndicator( })() : undefined - const originalUrl = rawParams ? api.apiURL(`/view?${rawParams}`) : undefined + const originalUrl = rawParams + ? api.apiURL(`/view?${rawParams}`) + : undefined return { iconClass: 'icon-[lucide--image]', @@ -97,11 +102,7 @@ function buildVideoDropIndicator( node: LGraphNode, options: { videoLabel?: string } ): DropIndicatorData { - const stringValue = extractWidgetStringValue(node.widgets?.[0]?.value) - - const { filename, subfolder, type } = stringValue - ? parseImageWidgetValue(stringValue) - : { filename: '', subfolder: '', type: 'input' } + const { filename, subfolder, type } = parseNodeMediaValue(node) const videoUrl = filename ? api.apiURL(`/view?${new URLSearchParams({ filename, subfolder, type })}`)