修改上传数据

This commit is contained in:
zhangshixiang
2025-12-25 23:07:31 +08:00
parent 546fb633ec
commit 71d57c5631
2 changed files with 39 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ HTTP客户端模块
提供与远程服务器通信的客户端功能只有host需要用
"""
from copy import deepcopy
import json
import os
import time
@@ -75,6 +76,26 @@ class HTTPClient:
Returns:
Dict[str, str]: 旧UUID到新UUID的映射关系 {old_uuid: new_uuid}
"""
# 遍历 resources 及其所有子节点,将 pose.position.y 全部变为 -y
def invert_x_position(resource_instance, size_y: float = 0):
# 处理当前节点
pose = getattr(resource_instance.res_content, "pose", None)
if pose and hasattr(pose, "position"):
position = getattr(pose, "position", None)
pose_size = getattr(pose, "size", None)
if position and hasattr(position, "y") and pose_size and hasattr(pose_size, "height"):
position.y = size_y - position.y - pose_size.height
# 递归处理子节点
for child in getattr(resource_instance, "children", []):
_size_y = 0
if pose and hasattr(pose, "size"):
_size_y = pose.size.height
invert_x_position(child, _size_y)
# 处理所有树的所有节点,从树的根节点递归
resources_reversed = deepcopy(resources)
for tree in getattr(resources_reversed, "trees", []):
invert_x_position(getattr(tree, "root_node", tree))
with open(os.path.join(BasicConfig.working_dir, "req_resource_tree_add.json"), "w", encoding="utf-8") as f:
payload = {"nodes": [x for xs in resources.dump() for x in xs], "mount_uuid": mount_uuid}
f.write(json.dumps(payload, indent=4))
@@ -85,14 +106,14 @@ class HTTPClient:
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
response = requests.post(
f"{self.remote_addr}/edge/material",
json={"nodes": [x for xs in resources.dump() for x in xs], "mount_uuid": mount_uuid},
json={"nodes": [x for xs in resources_reversed.dump() for x in xs], "mount_uuid": mount_uuid},
headers={"Authorization": f"Lab {self.auth}"},
timeout=60,
)
else:
response = requests.put(
f"{self.remote_addr}/edge/material",
json={"nodes": [x for xs in resources.dump() for x in xs], "mount_uuid": mount_uuid},
json={"nodes": [x for xs in resources_reversed.dump() for x in xs], "mount_uuid": mount_uuid},
headers={"Authorization": f"Lab {self.auth}"},
timeout=10,
)

View File

@@ -84,7 +84,7 @@
"class": "",
"position": {
"x": 0,
"y": 0,
"y": 288,
"z": 0
},
"config": {
@@ -123,7 +123,7 @@
"class": "",
"position": {
"x": 138,
"y": 0,
"y": 288,
"z": 0
},
"config": {
@@ -162,7 +162,7 @@
"class": "",
"position": {
"x": 276,
"y": 0,
"y": 288,
"z": 0
},
"config": {
@@ -201,7 +201,7 @@
"class": "",
"position": {
"x": 414,
"y": 0,
"y": 288,
"z": 0
},
"config": {
@@ -240,7 +240,7 @@
"class": "",
"position": {
"x": 0,
"y": 96,
"y": 192,
"z": 0
},
"config": {
@@ -279,7 +279,7 @@
"class": "",
"position": {
"x": 138,
"y": 96,
"y": 192,
"z": 0
},
"config": {
@@ -318,7 +318,7 @@
"class": "",
"position": {
"x": 276,
"y": 96,
"y": 192,
"z": 0
},
"config": {
@@ -357,7 +357,7 @@
"class": "",
"position": {
"x": 414,
"y": 96,
"y": 192,
"z": 0
},
"config": {
@@ -396,7 +396,7 @@
"class": "",
"position": {
"x": 0,
"y": 192,
"y": 96,
"z": 0
},
"config": {
@@ -435,7 +435,7 @@
"class": "",
"position": {
"x": 138,
"y": 192,
"y": 96,
"z": 0
},
"config": {
@@ -474,7 +474,7 @@
"class": "",
"position": {
"x": 276,
"y": 192,
"y": 96,
"z": 0
},
"config": {
@@ -513,7 +513,7 @@
"class": "",
"position": {
"x": 414,
"y": 192,
"y": 96,
"z": 0
},
"config": {
@@ -552,7 +552,7 @@
"class": "",
"position": {
"x": 0,
"y": 288,
"y": 0,
"z": 0
},
"config": {
@@ -591,7 +591,7 @@
"class": "",
"position": {
"x": 138,
"y": 288,
"y": 0,
"z": 0
},
"config": {
@@ -630,7 +630,7 @@
"class": "",
"position": {
"x": 276,
"y": 288,
"y": 0,
"z": 0
},
"config": {
@@ -669,7 +669,7 @@
"class": "",
"position": {
"x": 414,
"y": 288,
"y": 0,
"z": 0
},
"config": {