Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drag and drop audio files onto LoadAudio nodes #2710

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Changes from 2 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
19 changes: 14 additions & 5 deletions src/extensions/core/uploadAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { IWidget } from '@comfyorg/litegraph'
import type { IStringWidget } from '@comfyorg/litegraph/dist/types/widgets'

import { useNodeDragAndDrop } from '@/composables/useNodeDragAndDrop'
import { useNodeFileInput } from '@/composables/useNodeFileInput'
import type { DOMWidget } from '@/scripts/domWidget'
import { useToastStore } from '@/stores/toastStore'
Expand Down Expand Up @@ -180,13 +181,16 @@ app.registerExtension({
}
}

const handleUpload = async (files: File[]) => {
if (files?.length) {
uploadFile(audioWidget, audioUIWidget, files[0], true)
}
return files
}

const { openFileSelection } = useNodeFileInput(node, {
accept: 'audio/*',
onSelect: (files) => {
if (files?.length) {
uploadFile(audioWidget, audioUIWidget, files[0], true)
}
}
onSelect: handleUpload
})

// The widget to pop up the upload dialog.
Expand All @@ -199,6 +203,11 @@ app.registerExtension({
)
uploadWidget.label = 'choose file to upload'

useNodeDragAndDrop(node, {
fileFilter: (file) => file.type.startsWith('audio/'),
onDrop: handleUpload
})

node.previewMediaType = 'audio'

return { widget: uploadWidget }
Expand Down