Skip to content

Commit

Permalink
Add drag and drop audio files onto LoadAudio nodes (#2710)
Browse files Browse the repository at this point in the history
Co-authored-by: Chenlei Hu <huchenlei@proton.me>
  • Loading branch information
christian-byrne and huchenlei authored Feb 24, 2025
1 parent d340e63 commit 15785fe
Showing 1 changed file with 14 additions and 5 deletions.
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/node/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

0 comments on commit 15785fe

Please sign in to comment.