mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-29 21:13:33 +08:00
Merge a258d23ff7 into fc1fdf3389
This commit is contained in:
commit
2134e05b0a
@ -223,11 +223,13 @@ def get_outputs_summary(outputs: dict) -> tuple[int, Optional[dict]]:
|
||||
|
||||
Preview priority (matching frontend):
|
||||
1. type="output" with previewable media
|
||||
2. Any previewable media
|
||||
2. Any non-text previewable media
|
||||
3. Text preview fallback
|
||||
"""
|
||||
count = 0
|
||||
preview_output = None
|
||||
fallback_preview = None
|
||||
text_fallback_preview = None
|
||||
|
||||
for node_id, node_outputs in outputs.items():
|
||||
if not isinstance(node_outputs, dict):
|
||||
@ -245,7 +247,13 @@ def get_outputs_summary(outputs: dict) -> tuple[int, Optional[dict]]:
|
||||
# Not a 3D file string — check for text preview
|
||||
if media_type == 'text':
|
||||
count += 1
|
||||
if preview_output is None:
|
||||
# Only create/store a text fallback when we don't yet
|
||||
# have a primary preview or a non-text fallback.
|
||||
if (
|
||||
preview_output is None
|
||||
and fallback_preview is None
|
||||
and text_fallback_preview is None
|
||||
):
|
||||
if isinstance(item, tuple):
|
||||
text_value = item[0] if item else ''
|
||||
else:
|
||||
@ -256,8 +264,7 @@ def get_outputs_summary(outputs: dict) -> tuple[int, Optional[dict]]:
|
||||
'nodeId': node_id,
|
||||
'mediaType': media_type
|
||||
}
|
||||
if fallback_preview is None:
|
||||
fallback_preview = enriched
|
||||
text_fallback_preview = enriched
|
||||
continue
|
||||
# normalize_output_item returned a dict (e.g. 3D file)
|
||||
item = normalized
|
||||
@ -276,10 +283,14 @@ def get_outputs_summary(outputs: dict) -> tuple[int, Optional[dict]]:
|
||||
enriched['mediaType'] = media_type
|
||||
if item.get('type') == 'output':
|
||||
preview_output = enriched
|
||||
elif fallback_preview is None:
|
||||
fallback_preview = enriched
|
||||
elif media_type != 'text':
|
||||
# Prefer non-text media (images/video/audio/3d) over text fallback.
|
||||
if fallback_preview is None:
|
||||
fallback_preview = enriched
|
||||
elif fallback_preview is None and text_fallback_preview is None:
|
||||
text_fallback_preview = enriched
|
||||
|
||||
return count, preview_output or fallback_preview
|
||||
return count, preview_output or fallback_preview or text_fallback_preview
|
||||
|
||||
|
||||
def apply_sorting(jobs: list[dict], sort_by: str, sort_order: str) -> list[dict]:
|
||||
|
||||
@ -136,6 +136,37 @@ class TestGetOutputsSummary:
|
||||
count, preview = get_outputs_summary(outputs)
|
||||
assert preview['filename'] == 'temp1.png'
|
||||
|
||||
def test_text_preview_does_not_override_image_fallback(self):
|
||||
"""Text output should not take precedence over image fallback previews."""
|
||||
outputs = {
|
||||
'node1': {
|
||||
'text': ['debug text from PreviewAny']
|
||||
},
|
||||
'node2': {
|
||||
'images': [
|
||||
{'filename': 'temp1.png', 'type': 'temp'}
|
||||
]
|
||||
}
|
||||
}
|
||||
count, preview = get_outputs_summary(outputs)
|
||||
assert count == 2
|
||||
assert preview is not None
|
||||
assert preview['mediaType'] == 'images'
|
||||
assert preview['filename'] == 'temp1.png'
|
||||
|
||||
def test_text_fallback_used_when_only_text_exists(self):
|
||||
"""Text preview should still be used when no non-text previewable outputs exist."""
|
||||
outputs = {
|
||||
'node1': {
|
||||
'text': ['debug text from PreviewAny']
|
||||
}
|
||||
}
|
||||
count, preview = get_outputs_summary(outputs)
|
||||
assert count == 1
|
||||
assert preview is not None
|
||||
assert preview['mediaType'] == 'text'
|
||||
assert preview['content'] == 'debug text from PreviewAny'
|
||||
|
||||
def test_non_previewable_media_types_counted_but_no_preview(self):
|
||||
"""Non-previewable media types should be counted but not used as preview."""
|
||||
outputs = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user