mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
[refactor] Add ResultItemType and improve image upload typing (#4200)
This commit is contained in:
@@ -5,6 +5,7 @@ import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
|
|||||||
import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
|
import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
|
||||||
import { useNodePaste } from '@/composables/node/useNodePaste'
|
import { useNodePaste } from '@/composables/node/useNodePaste'
|
||||||
import { t } from '@/i18n'
|
import { t } from '@/i18n'
|
||||||
|
import type { ResultItemType } from '@/schemas/apiSchema'
|
||||||
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
||||||
import type { DOMWidget } from '@/scripts/domWidget'
|
import type { DOMWidget } from '@/scripts/domWidget'
|
||||||
import { useToastStore } from '@/stores/toastStore'
|
import { useToastStore } from '@/stores/toastStore'
|
||||||
@@ -12,8 +13,6 @@ import { useToastStore } from '@/stores/toastStore'
|
|||||||
import { api } from '../../scripts/api'
|
import { api } from '../../scripts/api'
|
||||||
import { app } from '../../scripts/app'
|
import { app } from '../../scripts/app'
|
||||||
|
|
||||||
type FolderType = 'input' | 'output' | 'temp'
|
|
||||||
|
|
||||||
function splitFilePath(path: string): [string, string] {
|
function splitFilePath(path: string): [string, string] {
|
||||||
const folder_separator = path.lastIndexOf('/')
|
const folder_separator = path.lastIndexOf('/')
|
||||||
if (folder_separator === -1) {
|
if (folder_separator === -1) {
|
||||||
@@ -28,7 +27,7 @@ function splitFilePath(path: string): [string, string] {
|
|||||||
function getResourceURL(
|
function getResourceURL(
|
||||||
subfolder: string,
|
subfolder: string,
|
||||||
filename: string,
|
filename: string,
|
||||||
type: FolderType = 'input'
|
type: ResultItemType = 'input'
|
||||||
): string {
|
): string {
|
||||||
const params = [
|
const params = [
|
||||||
'filename=' + encodeURIComponent(filename),
|
'filename=' + encodeURIComponent(filename),
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes'
|
|||||||
const zNodeType = z.string()
|
const zNodeType = z.string()
|
||||||
const zQueueIndex = z.number()
|
const zQueueIndex = z.number()
|
||||||
const zPromptId = z.string()
|
const zPromptId = z.string()
|
||||||
|
export const resultItemType = z.enum(['input', 'output', 'temp'])
|
||||||
|
export type ResultItemType = z.infer<typeof resultItemType>
|
||||||
|
|
||||||
const zResultItem = z.object({
|
const zResultItem = z.object({
|
||||||
filename: z.string().optional(),
|
filename: z.string().optional(),
|
||||||
subfolder: z.string().optional(),
|
subfolder: z.string().optional(),
|
||||||
type: z.string().optional()
|
type: resultItemType.optional()
|
||||||
})
|
})
|
||||||
export type ResultItem = z.infer<typeof zResultItem>
|
export type ResultItem = z.infer<typeof zResultItem>
|
||||||
const zOutputs = z
|
const zOutputs = z
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { fromZodError } from 'zod-validation-error'
|
import { fromZodError } from 'zod-validation-error'
|
||||||
|
|
||||||
|
import { resultItemType } from '@/schemas/apiSchema'
|
||||||
|
|
||||||
const zComboOption = z.union([z.string(), z.number()])
|
const zComboOption = z.union([z.string(), z.number()])
|
||||||
const zRemoteWidgetConfig = z.object({
|
const zRemoteWidgetConfig = z.object({
|
||||||
route: z.string().url().or(z.string().startsWith('/')),
|
route: z.string().url().or(z.string().startsWith('/')),
|
||||||
@@ -72,7 +74,7 @@ export const zStringInputOptions = zBaseInputOptions.extend({
|
|||||||
export const zComboInputOptions = zBaseInputOptions.extend({
|
export const zComboInputOptions = zBaseInputOptions.extend({
|
||||||
control_after_generate: z.boolean().optional(),
|
control_after_generate: z.boolean().optional(),
|
||||||
image_upload: z.boolean().optional(),
|
image_upload: z.boolean().optional(),
|
||||||
image_folder: z.enum(['input', 'output', 'temp']).optional(),
|
image_folder: resultItemType.optional(),
|
||||||
allow_batch: z.boolean().optional(),
|
allow_batch: z.boolean().optional(),
|
||||||
video_upload: z.boolean().optional(),
|
video_upload: z.boolean().optional(),
|
||||||
animated_image_upload: z.boolean().optional(),
|
animated_image_upload: z.boolean().optional(),
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { LGraphNode } from '@comfyorg/litegraph'
|
import { LGraphNode } from '@comfyorg/litegraph'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
import { ExecutedWsMessage, ResultItem } from '@/schemas/apiSchema'
|
import {
|
||||||
|
ExecutedWsMessage,
|
||||||
|
ResultItem,
|
||||||
|
ResultItemType
|
||||||
|
} from '@/schemas/apiSchema'
|
||||||
import { api } from '@/scripts/api'
|
import { api } from '@/scripts/api'
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
import { parseFilePath } from '@/utils/formatUtil'
|
import { parseFilePath } from '@/utils/formatUtil'
|
||||||
@@ -9,7 +13,7 @@ import { isVideoNode } from '@/utils/litegraphUtil'
|
|||||||
|
|
||||||
const createOutputs = (
|
const createOutputs = (
|
||||||
filenames: string[],
|
filenames: string[],
|
||||||
type: string,
|
type: ResultItemType,
|
||||||
isAnimated: boolean
|
isAnimated: boolean
|
||||||
): ExecutedWsMessage['output'] => {
|
): ExecutedWsMessage['output'] => {
|
||||||
return {
|
return {
|
||||||
@@ -88,7 +92,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
|
|||||||
{
|
{
|
||||||
folder = 'input',
|
folder = 'input',
|
||||||
isAnimated = false
|
isAnimated = false
|
||||||
}: { folder?: string; isAnimated?: boolean } = {}
|
}: { folder?: ResultItemType; isAnimated?: boolean } = {}
|
||||||
) {
|
) {
|
||||||
if (!filenames || !node) return
|
if (!filenames || !node) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user