格式化逻辑:保持你喜欢的 [ID] Type Value Link 格式
(self, prompt_data)
| 23 | FUNCTION = "load_image_with_metadata" |
| 24 | |
| 25 | def format_node_data(self, prompt_data): |
| 26 | """ |
| 27 | 格式化逻辑:保持你喜欢的 [ID] Type Value Link 格式 |
| 28 | """ |
| 29 | output_lines = [] |
| 30 | |
| 31 | try: |
| 32 | if isinstance(prompt_data, str): |
| 33 | prompt_data = json.loads(prompt_data) |
| 34 | |
| 35 | # 按 Node ID 排序 |
| 36 | sorted_items = sorted(prompt_data.items(), key=lambda x: int(x[0]) if x[0].isdigit() else x[0]) |
| 37 | |
| 38 | for node_id, node_data in sorted_items: |
| 39 | class_type = node_data.get("class_type", "Unknown") |
| 40 | inputs = node_data.get("inputs", {}) |
| 41 | |
| 42 | # 1. Node ID |
| 43 | output_lines.append(f"█ [ID: {node_id}]") |
| 44 | |
| 45 | # 2. Type |
| 46 | output_lines.append(f" Type: {class_type}") |
| 47 | |
| 48 | params = [] |
| 49 | links = [] |
| 50 | |
| 51 | for k, v in inputs.items(): |
| 52 | # 判断是否为连线 [node_id, slot_index] |
| 53 | if isinstance(v, list) and len(v) == 2: |
| 54 | links.append(f" ► Link ({k}): -> Node [{v[0]}]") |
| 55 | else: |
| 56 | str_v = str(v) |
| 57 | # 截断超长内容,避免文本框卡顿 |
| 58 | if len(str_v) > 100: |
| 59 | str_v = str_v[:100] + "...(truncated)" |
| 60 | params.append(f" • {k}: {str_v}") |
| 61 | |
| 62 | # 3. Values |
| 63 | if params: |
| 64 | output_lines.append(" [Values]:") |
| 65 | output_lines.extend(params) |
| 66 | |
| 67 | # 4. Links |
| 68 | if links: |
| 69 | output_lines.append(" [Links]:") |
| 70 | output_lines.extend(links) |
| 71 | |
| 72 | output_lines.append("-" * 30) |
| 73 | |
| 74 | except Exception as e: |
| 75 | return f"Error parsing metadata: {str(e)}" |
| 76 | |
| 77 | return "\n".join(output_lines) |
| 78 | |
| 79 | def load_image_with_metadata(self, image): |
| 80 | image_path = folder_paths.get_annotated_filepath(image) |
no outgoing calls
no test coverage detected