实例页增加远程更新客户端:下发 git pull + pm2 restart,并轮询版本确认上线。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -42,7 +42,9 @@ from lib.bridge_client_lib import (
|
||||
dispatch_cond_order_to_ids,
|
||||
fetch_backup_file,
|
||||
fetch_backup_list,
|
||||
fetch_client_version,
|
||||
fetch_cond_orders,
|
||||
post_client_update,
|
||||
post_close_full,
|
||||
post_cond_cancel,
|
||||
post_cond_exit,
|
||||
@@ -524,6 +526,37 @@ def api_open_url(iid: int):
|
||||
return jsonify({"ok": True, "url": url, "base_url": inst["base_url"]})
|
||||
|
||||
|
||||
@app.route("/api/instances/<int:iid>/version", methods=["GET"])
|
||||
@login_required
|
||||
def api_instance_version(iid: int):
|
||||
inst = get_instance(iid)
|
||||
if not inst:
|
||||
return jsonify({"ok": False, "msg": "实例不存在", "online": False}), 404
|
||||
result = fetch_client_version(inst)
|
||||
code = 200 if result.get("online") else 502
|
||||
return jsonify(result), code
|
||||
|
||||
|
||||
@app.route("/api/instances/<int:iid>/update", methods=["POST"])
|
||||
@login_required
|
||||
def api_instance_update(iid: int):
|
||||
"""实例页远程快速更新:转发客户端 Bridge /api/hub/update."""
|
||||
inst = get_instance(iid)
|
||||
if not inst:
|
||||
return jsonify({"ok": False, "msg": "实例不存在"}), 404
|
||||
if not inst.get("enabled"):
|
||||
return jsonify({"ok": False, "msg": "实例未启用"}), 400
|
||||
result = post_client_update(inst)
|
||||
status = 200
|
||||
if not result.get("ok"):
|
||||
msg = str(result.get("msg") or "")
|
||||
if msg.startswith("HTTP ") or "超时" in msg or "下发失败" in msg or "缺少 URL" in msg:
|
||||
status = 502
|
||||
else:
|
||||
status = 400
|
||||
return jsonify(result), status
|
||||
|
||||
|
||||
@app.route("/api/instances/<int:iid>/options/close", methods=["POST"])
|
||||
@login_required
|
||||
def api_instance_options_close(iid: int):
|
||||
|
||||
Reference in New Issue
Block a user