@@ -7,6 +7,7 @@ import { t } from '@/i18n'
7
7
import { useToastStore } from ' @/platform/updates/common/toastStore'
8
8
import type { ResultItemType } from ' @/schemas/apiSchema'
9
9
import { api } from ' @/scripts/api'
10
+ import { useQueueStore } from ' @/stores/queueStore'
10
11
import type { SimplifiedWidget } from ' @/types/simplifiedWidget'
11
12
import type { AssetKind } from ' @/types/widgetTypes'
12
13
import {
@@ -42,6 +43,7 @@ const { localValue, onChange } = useWidgetValue({
42
43
})
43
44
44
45
const toastStore = useToastStore ()
46
+ const queueStore = useQueueStore ()
45
47
46
48
const transformCompatProps = useTransformCompatOverlayProps ()
47
49
@@ -50,21 +52,73 @@ const combinedProps = computed(() => ({
50
52
... transformCompatProps .value
51
53
}))
52
54
55
+ const filterSelected = ref (' all' )
56
+ const filterOptions = ref <FilterOption []>([
57
+ { id: ' all' , name: ' All' },
58
+ { id: ' inputs' , name: ' Inputs' },
59
+ { id: ' outputs' , name: ' Outputs' }
60
+ ])
61
+
53
62
const selectedSet = ref <Set <SelectedKey >>(new Set ())
54
- const dropdownItems = computed <DropdownItem []>(() => {
63
+ const inputItems = computed <DropdownItem []>(() => {
55
64
const values = props .widget .options ?.values || []
56
65
57
66
if (! Array .isArray (values )) {
58
67
return []
59
68
}
60
69
61
70
return values .map ((value : string , index : number ) => ({
62
- id: index ,
63
- imageSrc: getMediaUrl (value ),
71
+ id: ` input-${ index } ` ,
72
+ imageSrc: getMediaUrl (value , ' input ' ),
64
73
name: value ,
65
74
metadata: ' '
66
75
}))
67
76
})
77
+ const outputItems = computed <DropdownItem []>(() => {
78
+ if (! [' image' , ' video' ].includes (props .assetKind ?? ' ' )) return []
79
+
80
+ const outputs = new Set <string >()
81
+
82
+ // Extract output images/videos from queue history
83
+ queueStore .historyTasks .forEach ((task ) => {
84
+ task .flatOutputs .forEach ((output ) => {
85
+ const isTargetType =
86
+ (props .assetKind === ' image' && output .mediaType === ' images' ) ||
87
+ (props .assetKind === ' video' && output .mediaType === ' video' )
88
+
89
+ if (output .type === ' output' && isTargetType ) {
90
+ const path = output .subfolder
91
+ ? ` ${output .subfolder }/${output .filename } `
92
+ : output .filename
93
+ // Add [output] annotation so the preview component knows the type
94
+ const annotatedPath = ` ${path } [output] `
95
+ outputs .add (annotatedPath )
96
+ }
97
+ })
98
+ })
99
+
100
+ return Array .from (outputs ).map ((output , index ) => ({
101
+ id: ` output-${index } ` ,
102
+ imageSrc: getMediaUrl (output .replace (' [output]' , ' ' ), ' output' ),
103
+ name: output ,
104
+ metadata: ' '
105
+ }))
106
+ })
107
+
108
+ const allItems = computed <DropdownItem []>(() => {
109
+ return [... inputItems .value , ... outputItems .value ]
110
+ })
111
+ const dropdownItems = computed <DropdownItem []>(() => {
112
+ switch (filterSelected .value ) {
113
+ case ' inputs' :
114
+ return inputItems .value
115
+ case ' outputs' :
116
+ return outputItems .value
117
+ case ' all' :
118
+ default :
119
+ return allItems .value
120
+ }
121
+ })
68
122
69
123
const mediaPlaceholder = computed (() => {
70
124
const options = props .widget .options
@@ -197,19 +251,13 @@ async function handleFilesUpdate(files: File[]) {
197
251
}
198
252
}
199
253
200
- function getMediaUrl(filename : string ): string {
201
- if (props .assetKind !== ' image' ) return ' '
202
- // TODO: This needs to be adapted based on actual ComfyUI API structure
203
- return ` /api/view?filename=${encodeURIComponent (filename )}&type=input `
254
+ function getMediaUrl(
255
+ filename : string ,
256
+ type : ' input' | ' output' = ' input'
257
+ ): string {
258
+ if (! [' image' , ' video' ].includes (props .assetKind ?? ' ' )) return ' '
259
+ return ` /api/view?filename=${encodeURIComponent (filename )}&type=${type } `
204
260
}
205
-
206
- // TODO handle filter logic
207
- const filterSelected = ref (' all' )
208
- const filterOptions = ref <FilterOption []>([
209
- { id: ' all' , name: ' All' },
210
- { id: ' image' , name: ' Inputs' },
211
- { id: ' video' , name: ' Outputs' }
212
- ])
213
261
</script >
214
262
215
263
<template >
0 commit comments