diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 2ccf9611e..772caf3d8 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -52,7 +52,7 @@ import type { ComfyExtension, MissingNodeType } from '@/types/comfy' import { ExtensionManager } from '@/types/extensionTypes' import { ColorAdjustOptions, adjustColor } from '@/utils/colorUtil' import { graphToPrompt } from '@/utils/executionUtil' -import { getFileHandler } from '@/utils/fileHandlers' +import { getFileHandler, resolveDragDropFile } from '@/utils/fileHandlers' import { executeWidgetsCallback, fixLinkInputSlots, @@ -463,20 +463,11 @@ export class ComfyApp { event.dataTransfer.files.length && event.dataTransfer.files[0].type !== 'image/bmp' ) { - await this.handleFile(event.dataTransfer.files[0]) - } else { - // Try loading the first URI in the transfer list - const validTypes = ['text/uri-list', 'text/x-moz-url'] - const match = [...event.dataTransfer.types].find((t) => - validTypes.find((v) => t === v) + const resolvedFile = await resolveDragDropFile( + event.dataTransfer.files[0], + event.dataTransfer ) - if (match) { - const uri = event.dataTransfer.getData(match)?.split('\n')?.[0] - if (uri) { - const blob = await (await fetch(uri)).blob() - await this.handleFile(new File([blob], uri, { type: blob.type })) - } - } + await this.handleFile(resolvedFile) } } catch (err: any) { useToastStore().addAlert( diff --git a/src/utils/fileHandlers.ts b/src/utils/fileHandlers.ts index 01896c1ae..54cf76a3a 100644 --- a/src/utils/fileHandlers.ts +++ b/src/utils/fileHandlers.ts @@ -334,3 +334,51 @@ export function getFileHandler(file: File): WorkflowFileHandler | null { return null } + +/** + * Resolves the correct file from drag and drop events with URI fallback + * when direct file processing doesn't yield workflow data + */ +export async function resolveDragDropFile( + file: File, + dataTransfer: DataTransfer +): Promise { + const fileHandler = getFileHandler(file) + if (!fileHandler) { + return file + } + + // First try direct file processing + const directResult = await fileHandler(file) + + // If we got workflow data, return the original file + if ( + directResult.workflow || + directResult.prompt || + directResult.parameters || + directResult.jsonTemplateData + ) { + return file + } + + // No workflow data found, try URI approach as fallback + const validTypes = ['text/uri-list', 'text/x-moz-url'] + const match = [...dataTransfer.types].find((t) => + validTypes.find((v) => t === v) + ) + + if (match) { + const uri = dataTransfer.getData(match)?.split('\n')?.[0] + if (uri) { + try { + const blob = await (await fetch(uri)).blob() + return new File([blob], file.name, { type: blob.type }) + } catch (error) { + console.warn('URI fetch failed, using original file:', error) + } + } + } + + // Return original file as fallback + return file +}