Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
2 : import { isMediaUploadComboInput } from '@comfyorg/object-info-parser'
3 : import type { ComfyNodeDef, InputSpec } from '@comfyorg/object-info-parser'
4 : import type { ComfyExtension } from '@/types/comfy'
5 :
6 : // Adds an upload button to the nodes
7 :
8 2355 : const createUploadInput = (
9 : imageInputName: string,
10 : imageInputOptions: InputSpec
11 : ): InputSpec => [
12 : 'IMAGEUPLOAD',
13 : {
14 : ...imageInputOptions[1],
15 : imageInputName
16 : }
17 : ]
18 :
19 2355 : export const uploadImageExtension: ComfyExtension = {
20 : name: 'Comfy.UploadImage',
21 : beforeRegisterNodeDef(_nodeType: typeof LGraphNode, nodeData: ComfyNodeDef) {
22 2439372 : const { input } = nodeData
23 2439372 : const { required } = input ?? {}
24 2439372 : if (!required) return
25 :
26 2432274 : const found = Object.entries(required).find(([_, input]) =>
27 : isMediaUploadComboInput(input)
28 : )
29 :
30 : // If media combo input found, attach upload input
31 2439372 : if (found) {
32 14196 : const [inputName, inputSpec] = found
33 14196 : required.upload = createUploadInput(inputName, inputSpec)
34 : }
35 : }
36 : }
|