@@ -3,15 +3,29 @@ import type { LGraphNode } from '@comfyorg/litegraph'
33import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
44import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
55import { useNodePaste } from '@/composables/node/useNodePaste'
6+ import type { ResultItemType } from '@/schemas/apiSchema'
67import { api } from '@/scripts/api'
78import { useToastStore } from '@/stores/toastStore'
89
910const PASTED_IMAGE_EXPIRY_MS = 2000
1011
11- const uploadFile = async ( file : File , isPasted : boolean ) => {
12+ interface ImageUploadFormFields {
13+ /**
14+ * The folder to upload the file to.
15+ * @example 'input', 'output', 'temp'
16+ */
17+ type : ResultItemType
18+ }
19+
20+ const uploadFile = async (
21+ file : File ,
22+ isPasted : boolean ,
23+ formFields : Partial < ImageUploadFormFields > = { }
24+ ) => {
1225 const body = new FormData ( )
1326 body . append ( 'image' , file )
1427 if ( isPasted ) body . append ( 'subfolder' , 'pasted' )
28+ if ( formFields . type ) body . append ( 'type' , formFields . type )
1529
1630 const resp = await api . fetchApi ( '/upload/image' , {
1731 method : 'POST' ,
@@ -36,6 +50,11 @@ interface ImageUploadOptions {
3650 * @example 'image/png,image/jpeg,image/webp,video/webm,video/mp4'
3751 */
3852 accept ?: string
53+ /**
54+ * The folder to upload the file to.
55+ * @example 'input', 'output', 'temp'
56+ */
57+ folder ?: ResultItemType
3958}
4059
4160/**
@@ -53,7 +72,9 @@ export const useNodeImageUpload = (
5372
5473 const handleUpload = async ( file : File ) => {
5574 try {
56- const path = await uploadFile ( file , isPastedFile ( file ) )
75+ const path = await uploadFile ( file , isPastedFile ( file ) , {
76+ type : options . folder
77+ } )
5778 if ( ! path ) return
5879 return path
5980 } catch ( error ) {
0 commit comments