17 lines
670 B
Python
17 lines
670 B
Python
from uuid import uuid4
|
|
|
|
|
|
def format_content_uuid(content:list[dict]):
|
|
"""替换所有由前端生成的 uuid 字段"""
|
|
uuid_mapping = {k.get('uuid', ''): uuid4().hex for k in list(filter(lambda x: "temp_" in x.get("uuid", "") , content))}
|
|
for x in content:
|
|
edge = x.get('edge')
|
|
x_uuid = x.get('uuid', '')
|
|
x["uuid"] = uuid_mapping.get(x_uuid) or x_uuid
|
|
if edge:
|
|
source_uuid = edge.get('source', '')
|
|
target_uuid = edge.get('target', '')
|
|
edge["source"] = uuid_mapping.get(source_uuid) or source_uuid
|
|
edge["target"] = uuid_mapping.get(target_uuid) or target_uuid
|
|
return content
|