Skip to content

Commit ec9da0b

Browse files
[refactor] Add ResultItemType and improve image upload typing (#4200)
1 parent 98bb1df commit ec9da0b

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/extensions/core/uploadAudio.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ 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'
89
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
910
import type { DOMWidget } from '@/scripts/domWidget'
1011
import { useToastStore } from '@/stores/toastStore'
1112

1213
import { api } from '../../scripts/api'
1314
import { app } from '../../scripts/app'
1415

15-
type FolderType = 'input' | 'output' | 'temp'
16-
1716
function splitFilePath(path: string): [string, string] {
1817
const folder_separator = path.lastIndexOf('/')
1918
if (folder_separator === -1) {
@@ -28,7 +27,7 @@ function splitFilePath(path: string): [string, string] {
2827
function getResourceURL(
2928
subfolder: string,
3029
filename: string,
31-
type: FolderType = 'input'
30+
type: ResultItemType = 'input'
3231
): string {
3332
const params = [
3433
'filename=' + encodeURIComponent(filename),

src/schemas/apiSchema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes'
1111
const zNodeType = z.string()
1212
const zQueueIndex = z.number()
1313
const zPromptId = z.string()
14+
export const resultItemType = z.enum(['input', 'output', 'temp'])
15+
export type ResultItemType = z.infer<typeof resultItemType>
16+
1417
const zResultItem = z.object({
1518
filename: z.string().optional(),
1619
subfolder: z.string().optional(),
17-
type: z.string().optional()
20+
type: resultItemType.optional()
1821
})
1922
export type ResultItem = z.infer<typeof zResultItem>
2023
const zOutputs = z

src/schemas/nodeDefSchema.ts

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

4+
import { resultItemType } from '@/schemas/apiSchema'
5+
46
const zComboOption = z.union([z.string(), z.number()])
57
const zRemoteWidgetConfig = z.object({
68
route: z.string().url().or(z.string().startsWith('/')),
@@ -72,7 +74,7 @@ export const zStringInputOptions = zBaseInputOptions.extend({
7274
export const zComboInputOptions = zBaseInputOptions.extend({
7375
control_after_generate: z.boolean().optional(),
7476
image_upload: z.boolean().optional(),
75-
image_folder: z.enum(['input', 'output', 'temp']).optional(),
77+
image_folder: resultItemType.optional(),
7678
allow_batch: z.boolean().optional(),
7779
video_upload: z.boolean().optional(),
7880
animated_image_upload: z.boolean().optional(),

src/stores/imagePreviewStore.ts

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

4-
import { ExecutedWsMessage, ResultItem } from '@/schemas/apiSchema'
4+
import {
5+
ExecutedWsMessage,
6+
ResultItem,
7+
ResultItemType
8+
} from '@/schemas/apiSchema'
59
import { api } from '@/scripts/api'
610
import { app } from '@/scripts/app'
711
import { parseFilePath } from '@/utils/formatUtil'
812
import { isVideoNode } from '@/utils/litegraphUtil'
913

1014
const createOutputs = (
1115
filenames: string[],
12-
type: string,
16+
type: ResultItemType,
1317
isAnimated: boolean
1418
): ExecutedWsMessage['output'] => {
1519
return {
@@ -88,7 +92,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
8892
{
8993
folder = 'input',
9094
isAnimated = false
91-
}: { folder?: string; isAnimated?: boolean } = {}
95+
}: { folder?: ResultItemType; isAnimated?: boolean } = {}
9296
) {
9397
if (!filenames || !node) return
9498

0 commit comments

Comments
 (0)