always fallback to uri

This commit is contained in:
bymyself
2025-06-01 07:31:42 -07:00
parent 54055e7707
commit 27eb7cade4
2 changed files with 53 additions and 14 deletions

View File

@@ -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(

View File

@@ -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<File> {
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
}