优化后端和前端逻辑

This commit is contained in:
minghanchen
2026-09-03 10:21:01 +08:00
parent ccd64adcfe
commit 009d8ca73e
19 changed files with 3083 additions and 763 deletions
+10 -5
View File
@@ -418,7 +418,7 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
if path.startswith("/api/self-repair/"):
self._handle_self_repair_post(path)
return
if path.startswith("/api/mode-profiles/"):
if path == "/api/mode-profiles" or path.startswith("/api/mode-profiles/"):
self._handle_mode_profile_post(path)
return
supplement_match = re.fullmatch(
@@ -1506,8 +1506,9 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
self._handle_mode_profile_execute(execute_match.group("mode_id"))
return
create_mode = path == "/api/mode-profiles"
mode_id = path.removeprefix("/api/mode-profiles/").strip()
if not mode_id:
if not create_mode and not mode_id:
self._json(
{"error": "invalid_request", "message": "模式编号不能为空。"},
HTTPStatus.BAD_REQUEST,
@@ -1515,14 +1516,18 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
return
try:
payload = self._read_json_body(max_bytes=16 * 1024)
result = self.service.save_mode_profile_card(
mode_id,
arguments = (
str(payload.get("name", "")),
str(payload.get("instruction", "")),
str(payload.get("source_request_id", "")),
str(payload.get("vehicle_id", "")) or None,
)
self._json(result, HTTPStatus.OK)
result = (
self.service.create_mode_profile_card(*arguments)
if create_mode
else self.service.save_mode_profile_card(mode_id, *arguments)
)
self._json(result, HTTPStatus.CREATED if create_mode else HTTPStatus.OK)
except KeyError:
self._json(
{"error": "not_found", "message": "未找到需要编辑的模式卡片。"},