Skip to content

Commit d5ecfb2

Browse files
authored
Revert "[refactor] Refactor and type image upload options" (#4190)
1 parent 3211875 commit d5ecfb2

File tree

6 files changed

+17
-40
lines changed

6 files changed

+17
-40
lines changed

src/composables/node/useNodeImageUpload.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,15 @@ import type { LGraphNode } from '@comfyorg/litegraph'
33
import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
44
import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
55
import { useNodePaste } from '@/composables/node/useNodePaste'
6-
import type { ResultItemType } from '@/schemas/apiSchema'
76
import { api } from '@/scripts/api'
87
import { useToastStore } from '@/stores/toastStore'
98

109
const PASTED_IMAGE_EXPIRY_MS = 2000
1110

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-
) => {
11+
const uploadFile = async (file: File, isPasted: boolean) => {
2512
const body = new FormData()
2613
body.append('image', file)
2714
if (isPasted) body.append('subfolder', 'pasted')
28-
if (formFields.type) body.append('type', formFields.type)
2915

3016
const resp = await api.fetchApi('/upload/image', {
3117
method: 'POST',
@@ -67,7 +53,7 @@ export const useNodeImageUpload = (
6753

6854
const handleUpload = async (file: File) => {
6955
try {
70-
const path = await uploadFile(file, isPastedFile(file), {})
56+
const path = await uploadFile(file, isPastedFile(file))
7157
if (!path) return
7258
return path
7359
} catch (error) {

src/composables/widgets/useImageUploadWidget.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useNodeImageUpload } from '@/composables/node/useNodeImageUpload'
66
import { useValueTransform } from '@/composables/useValueTransform'
77
import { t } from '@/i18n'
88
import type { ResultItem } from '@/schemas/apiSchema'
9-
import type { ComboInputOptions, InputSpec } from '@/schemas/nodeDefSchema'
9+
import type { InputSpec } from '@/schemas/nodeDefSchema'
1010
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
1111
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
1212
import { createAnnotatedPath } from '@/utils/formatUtil'
@@ -33,7 +33,7 @@ export const useImageUploadWidget = () => {
3333
inputName: string,
3434
inputData: InputSpec
3535
) => {
36-
const inputOptions = (inputData[1] ?? {}) as ComboInputOptions
36+
const inputOptions = inputData[1] ?? {}
3737
const { imageInputName, allow_batch, image_folder = 'input' } = inputOptions
3838
const nodeOutputStore = useNodeOutputStore()
3939

@@ -43,9 +43,11 @@ export const useImageUploadWidget = () => {
4343
const { showPreview } = isVideo ? useNodeVideo(node) : useNodeImage(node)
4444

4545
const fileFilter = isVideo ? isVideoFile : isImageFile
46-
const fileComboWidget = findFileComboWidget(node, imageInputName ?? '')
46+
// @ts-expect-error InputSpec is not typed correctly
47+
const fileComboWidget = findFileComboWidget(node, imageInputName)
4748
const initialFile = `${fileComboWidget.value}`
4849
const formatPath = (value: InternalFile) =>
50+
// @ts-expect-error InputSpec is not typed correctly
4951
createAnnotatedPath(value, { rootFolder: image_folder })
5052

5153
const transform = (internalValue: InternalValue): ExposedValue => {
@@ -65,6 +67,7 @@ export const useImageUploadWidget = () => {
6567

6668
// Setup file upload handling
6769
const { openFileSelection } = useNodeImageUpload(node, {
70+
// @ts-expect-error InputSpec is not typed correctly
6871
allow_batch,
6972
fileFilter,
7073
accept,

src/extensions/core/uploadAudio.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
55
import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
66
import { useNodePaste } from '@/composables/node/useNodePaste'
77
import { t } from '@/i18n'
8-
import type { ResultItemType } from '@/schemas/apiSchema'
98
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
109
import type { DOMWidget } from '@/scripts/domWidget'
1110
import { useToastStore } from '@/stores/toastStore'
1211

1312
import { api } from '../../scripts/api'
1413
import { app } from '../../scripts/app'
1514

15+
type FolderType = 'input' | 'output' | 'temp'
16+
1617
function splitFilePath(path: string): [string, string] {
1718
const folder_separator = path.lastIndexOf('/')
1819
if (folder_separator === -1) {
@@ -27,7 +28,7 @@ function splitFilePath(path: string): [string, string] {
2728
function getResourceURL(
2829
subfolder: string,
2930
filename: string,
30-
type: ResultItemType = 'input'
31+
type: FolderType = 'input'
3132
): string {
3233
const params = [
3334
'filename=' + encodeURIComponent(filename),

src/schemas/apiSchema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import { zKeybinding } from '@/schemas/keyBindingSchema'
88
import { NodeBadgeMode } from '@/types/nodeSource'
99
import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes'
1010

11-
export const resultItemType = z.enum(['input', 'output', 'temp'])
1211
const zNodeType = z.string()
1312
const zQueueIndex = z.number()
1413
const zPromptId = z.string()
1514
const zResultItem = z.object({
1615
filename: z.string().optional(),
1716
subfolder: z.string().optional(),
18-
type: resultItemType.optional()
17+
type: z.string().optional()
1918
})
20-
export type ResultItemType = z.infer<typeof resultItemType>
2119
export type ResultItem = z.infer<typeof zResultItem>
2220
const zOutputs = z
2321
.object({

src/schemas/nodeDefSchema.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { z } from 'zod'
22
import { fromZodError } from 'zod-validation-error'
33

4-
import { resultItemType } from './apiSchema'
5-
64
const zComboOption = z.union([z.string(), z.number()])
75
const zRemoteWidgetConfig = z.object({
86
route: z.string().url().or(z.string().startsWith('/')),
@@ -74,19 +72,14 @@ export const zStringInputOptions = zBaseInputOptions.extend({
7472
export const zComboInputOptions = zBaseInputOptions.extend({
7573
control_after_generate: z.boolean().optional(),
7674
image_upload: z.boolean().optional(),
77-
image_folder: resultItemType.optional(),
75+
image_folder: z.enum(['input', 'output', 'temp']).optional(),
7876
allow_batch: z.boolean().optional(),
7977
video_upload: z.boolean().optional(),
8078
animated_image_upload: z.boolean().optional(),
8179
options: z.array(zComboOption).optional(),
8280
remote: zRemoteWidgetConfig.optional(),
8381
/** Whether the widget is a multi-select widget. */
84-
multi_select: zMultiSelectOption.optional(),
85-
/**
86-
* The name of the image upload input (filename combo) if it exists
87-
* @example 'image'
88-
*/
89-
imageInputName: z.string().optional()
82+
multi_select: zMultiSelectOption.optional()
9083
})
9184

9285
const zIntInputSpec = z.tuple([z.literal('INT'), zIntInputOptions.optional()])

src/stores/imagePreviewStore.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import { LGraphNode } from '@comfyorg/litegraph'
22
import { defineStore } from 'pinia'
33

4-
import {
5-
ExecutedWsMessage,
6-
ResultItem,
7-
ResultItemType
8-
} from '@/schemas/apiSchema'
4+
import { ExecutedWsMessage, ResultItem } from '@/schemas/apiSchema'
95
import { api } from '@/scripts/api'
106
import { app } from '@/scripts/app'
117
import { parseFilePath } from '@/utils/formatUtil'
128
import { isVideoNode } from '@/utils/litegraphUtil'
139

1410
const createOutputs = (
1511
filenames: string[],
16-
type: ResultItemType,
12+
type: string,
1713
isAnimated: boolean
1814
): ExecutedWsMessage['output'] => {
1915
return {
@@ -92,7 +88,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
9288
{
9389
folder = 'input',
9490
isAnimated = false
95-
}: { folder?: ResultItemType; isAnimated?: boolean } = {}
91+
}: { folder?: string; isAnimated?: boolean } = {}
9692
) {
9793
if (!filenames || !node) return
9894

0 commit comments

Comments
 (0)