mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
feat: centralize output asset resolution
This commit is contained in:
@@ -227,19 +227,11 @@ import { useAssetSelection } from '@/platform/assets/composables/useAssetSelecti
|
||||
import { useMediaAssetActions } from '@/platform/assets/composables/useMediaAssetActions'
|
||||
import { useMediaAssetFiltering } from '@/platform/assets/composables/useMediaAssetFiltering'
|
||||
import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
|
||||
import type { OutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import type { MediaKind } from '@/platform/assets/schemas/mediaAssetSchema'
|
||||
import {
|
||||
mapOutputsToAssetItems,
|
||||
shouldLoadFullOutputs
|
||||
} from '@/platform/assets/utils/outputAssetUtil'
|
||||
import { resolveOutputAssetItems } from '@/platform/assets/utils/outputAssetUtil'
|
||||
import { isCloud } from '@/platform/distribution/types'
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
import {
|
||||
getJobDetail,
|
||||
getPreviewableOutputsFromJobDetail
|
||||
} from '@/services/jobOutputCache'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
import { useDialogStore } from '@/stores/dialogStore'
|
||||
import { useExecutionStore } from '@/stores/executionStore'
|
||||
@@ -561,17 +553,6 @@ const handleZoomClick = (asset: AssetItem) => {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveFolderOutputs(metadata: OutputAssetMetadata) {
|
||||
const outputsToDisplay = metadata.allOutputs ?? []
|
||||
if (!shouldLoadFullOutputs(metadata.outputCount, outputsToDisplay.length)) {
|
||||
return outputsToDisplay
|
||||
}
|
||||
|
||||
const jobDetail = await getJobDetail(metadata.promptId)
|
||||
const previewableOutputs = getPreviewableOutputsFromJobDetail(jobDetail)
|
||||
return previewableOutputs.length ? previewableOutputs : outputsToDisplay
|
||||
}
|
||||
|
||||
const enterFolderView = async (asset: AssetItem) => {
|
||||
const metadata = getOutputAssetMetadata(asset.user_metadata)
|
||||
if (!metadata) {
|
||||
@@ -589,20 +570,16 @@ const enterFolderView = async (asset: AssetItem) => {
|
||||
folderPromptId.value = promptId
|
||||
folderExecutionTime.value = executionTimeInSeconds
|
||||
|
||||
const outputsToDisplay = await resolveFolderOutputs(metadata)
|
||||
const folderItems = await resolveOutputAssetItems(metadata, {
|
||||
createdAt: asset.created_at
|
||||
})
|
||||
|
||||
if (outputsToDisplay.length === 0) {
|
||||
if (folderItems.length === 0) {
|
||||
console.warn('No outputs available for folder view')
|
||||
return
|
||||
}
|
||||
|
||||
folderAssets.value = mapOutputsToAssetItems({
|
||||
promptId,
|
||||
outputs: outputsToDisplay,
|
||||
createdAt: asset.created_at,
|
||||
executionTimeInSeconds,
|
||||
workflow: metadata.workflow
|
||||
})
|
||||
folderAssets.value = folderItems
|
||||
}
|
||||
|
||||
const exitFolderView = () => {
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
|
||||
import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema';
|
||||
import type { OutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema';
|
||||
import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import {
|
||||
mapOutputsToAssetItems,
|
||||
shouldLoadFullOutputs
|
||||
} from '@/platform/assets/utils/outputAssetUtil'
|
||||
import {
|
||||
getJobDetail,
|
||||
getPreviewableOutputsFromJobDetail
|
||||
} from '@/services/jobOutputCache'
|
||||
import { resolveOutputAssetItems } from '@/platform/assets/utils/outputAssetUtil'
|
||||
|
||||
export type OutputStackListItem = {
|
||||
key: string
|
||||
@@ -110,41 +102,20 @@ export function useOutputStacks({ assets }: UseOutputStacksOptions) {
|
||||
expandedStackPromptIds.value = nextExpanded
|
||||
}
|
||||
|
||||
async function resolveStackOutputs(metadata: OutputAssetMetadata) {
|
||||
const outputsToDisplay = metadata.allOutputs ?? []
|
||||
if (!shouldLoadFullOutputs(metadata.outputCount, outputsToDisplay.length)) {
|
||||
return outputsToDisplay
|
||||
}
|
||||
|
||||
try {
|
||||
const jobDetail = await getJobDetail(metadata.promptId)
|
||||
const previewableOutputs = getPreviewableOutputsFromJobDetail(jobDetail)
|
||||
return previewableOutputs.length ? previewableOutputs : outputsToDisplay
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch job detail for stack children:', error)
|
||||
return outputsToDisplay
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveStackChildren(asset: AssetItem): Promise<AssetItem[]> {
|
||||
const metadata = getOutputAssetMetadata(asset.user_metadata)
|
||||
if (!metadata) {
|
||||
return []
|
||||
}
|
||||
|
||||
const outputsToDisplay = await resolveStackOutputs(metadata)
|
||||
if (!outputsToDisplay.length) {
|
||||
try {
|
||||
return await resolveOutputAssetItems(metadata, {
|
||||
createdAt: asset.created_at,
|
||||
excludeOutputKey: asset.name
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to resolve stack children:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
return mapOutputsToAssetItems({
|
||||
promptId: metadata.promptId,
|
||||
outputs: outputsToDisplay,
|
||||
createdAt: asset.created_at,
|
||||
executionTimeInSeconds: metadata.executionTimeInSeconds,
|
||||
workflow: metadata.workflow,
|
||||
excludeFilename: asset.name
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import type { OutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import {
|
||||
getJobDetail,
|
||||
getPreviewableOutputsFromJobDetail
|
||||
} from '@/services/jobOutputCache'
|
||||
import type { ResultItemImpl } from '@/stores/queueStore'
|
||||
|
||||
type OutputAssetMapOptions = {
|
||||
@@ -11,6 +15,11 @@ type OutputAssetMapOptions = {
|
||||
excludeFilename?: string
|
||||
}
|
||||
|
||||
type ResolveOutputAssetItemsOptions = {
|
||||
createdAt?: string
|
||||
excludeOutputKey?: string
|
||||
}
|
||||
|
||||
export function shouldLoadFullOutputs(
|
||||
outputCount: OutputAssetMetadata['outputCount'],
|
||||
outputsLength: number
|
||||
@@ -50,3 +59,26 @@ export function mapOutputsToAssetItems({
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
export async function resolveOutputAssetItems(
|
||||
metadata: OutputAssetMetadata,
|
||||
{ createdAt, excludeOutputKey }: ResolveOutputAssetItemsOptions = {}
|
||||
): Promise<AssetItem[]> {
|
||||
let outputsToDisplay = metadata.allOutputs ?? []
|
||||
if (shouldLoadFullOutputs(metadata.outputCount, outputsToDisplay.length)) {
|
||||
const jobDetail = await getJobDetail(metadata.promptId)
|
||||
const previewableOutputs = getPreviewableOutputsFromJobDetail(jobDetail)
|
||||
if (previewableOutputs.length) {
|
||||
outputsToDisplay = previewableOutputs
|
||||
}
|
||||
}
|
||||
|
||||
return mapOutputsToAssetItems({
|
||||
promptId: metadata.promptId,
|
||||
outputs: outputsToDisplay,
|
||||
createdAt,
|
||||
executionTimeInSeconds: metadata.executionTimeInSeconds,
|
||||
workflow: metadata.workflow,
|
||||
excludeFilename: excludeOutputKey
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user