Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -463,9 +463,13 @@ export class ComfyApp {
event.dataTransfer.files.length &&
event.dataTransfer.files[0].type !== 'image/bmp'
) {
await this.handleFile(event.dataTransfer.files[0])
const resolvedFile = await resolveDragDropFile(
event.dataTransfer.files[0],
event.dataTransfer
)
await this.handleFile(resolvedFile)
} else {
// Try loading the first URI in the transfer list
// Try loading the first URI in the transfer list (handles Chrome->Firefox BMP case)
const validTypes = ['text/uri-list', 'text/x-moz-url']
const match = [...event.dataTransfer.types].find((t) =>
validTypes.find((v) => t === v)
Expand Down
48 changes: 48 additions & 0 deletions src/utils/fileHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}