diff --git a/lib/instance/instance_settings_register.py b/lib/instance/instance_settings_register.py index 8369887..3bf6f07 100644 --- a/lib/instance/instance_settings_register.py +++ b/lib/instance/instance_settings_register.py @@ -30,8 +30,6 @@ def _api_login_required(hub_token_write_allowed: bool = False): def decorator(f): @wraps(f) def wrapped(*args, **kwargs): - from lib.hub.hub_auth import request_allowed as hub_request_allowed - logged_in = bool(session.get("logged_in")) auth_disabled = (os.getenv("APP_AUTH_DISABLED") or "").strip().lower() in ( "1", @@ -43,7 +41,20 @@ def _api_login_required(hub_token_write_allowed: bool = False): bridge = (os.getenv("HUB_BRIDGE_TOKEN") or "").strip() if hub_hdr and bridge and hub_hdr == bridge and not hub_token_write_allowed: return jsonify({"ok": False, "msg": "Hub Token 不可修改实例设置"}), 403 - if hub_request_allowed(logged_in, auth_disabled): + + # crypto_okx 可无 lib.hub;鉴权与中控 request_allowed 对齐 + allowed = bool(auth_disabled or logged_in) + if not allowed and hub_hdr and bridge and hub_hdr == bridge: + allowed = True + if not allowed: + try: + from lib.hub.hub_auth import request_allowed as hub_request_allowed + + allowed = bool(hub_request_allowed(logged_in, auth_disabled)) + except ImportError: + allowed = False + + if allowed: return f(*args, **kwargs) return jsonify({"ok": False, "msg": "未登录"}), 401