更新系统页面和更新功能
- 更新 admin-frontend 系统页面和更新 API - 更新 routes 和 services 中的更新逻辑 - 重新构建前端静态资源
This commit is contained in:
@@ -43,6 +43,28 @@ def _has_pending_request() -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _parse_bool_field(data: dict, key: str) -> bool | None:
|
||||
if not isinstance(data, dict) or key not in data:
|
||||
return None
|
||||
value = data.get(key)
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, int):
|
||||
if value in (0, 1):
|
||||
return bool(value)
|
||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
||||
if isinstance(value, str):
|
||||
text = value.strip().lower()
|
||||
if text in ("1", "true", "yes", "y", "on"):
|
||||
return True
|
||||
if text in ("0", "false", "no", "n", "off", ""):
|
||||
return False
|
||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
||||
if value is None:
|
||||
return None
|
||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
||||
|
||||
|
||||
@admin_api_bp.route("/update/status", methods=["GET"])
|
||||
@admin_required
|
||||
def get_update_status_api():
|
||||
@@ -127,6 +149,17 @@ def request_update_run_api():
|
||||
if _has_pending_request():
|
||||
return jsonify({"error": "已有更新请求正在处理中,请稍后再试"}), 409
|
||||
|
||||
data = request.json or {}
|
||||
try:
|
||||
build_no_cache = _parse_bool_field(data, "build_no_cache")
|
||||
if build_no_cache is None:
|
||||
build_no_cache = _parse_bool_field(data, "no_cache")
|
||||
build_pull = _parse_bool_field(data, "build_pull")
|
||||
if build_pull is None:
|
||||
build_pull = _parse_bool_field(data, "pull")
|
||||
except ValueError as e:
|
||||
return jsonify({"error": str(e)}), 400
|
||||
|
||||
job_id = _make_job_id(prefix="upd")
|
||||
payload = {
|
||||
"job_id": job_id,
|
||||
@@ -134,6 +167,8 @@ def request_update_run_api():
|
||||
"requested_at": get_beijing_now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"requested_by": session.get("admin_username") or "",
|
||||
"requested_ip": _request_ip(),
|
||||
"build_no_cache": bool(build_no_cache) if build_no_cache is not None else False,
|
||||
"build_pull": bool(build_pull) if build_pull is not None else False,
|
||||
}
|
||||
write_json_atomic(get_update_request_path(), payload)
|
||||
return jsonify(
|
||||
@@ -143,4 +178,3 @@ def request_update_run_api():
|
||||
"message": "已提交更新请求,服务将重启(页面可能短暂不可用),请等待1-2分钟后刷新",
|
||||
}
|
||||
), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user