增加反代

This commit is contained in:
dekun
2026-05-25 11:49:53 +08:00
parent 1e36086465
commit 325f12c0a7
10 changed files with 442 additions and 18 deletions
+18 -2
View File
@@ -9,9 +9,9 @@ import json
import time
from functools import wraps
from flask import current_app, get_flashed_messages, jsonify, request, session
from flask import current_app, get_flashed_messages, jsonify, redirect, request, session
from hub_auth import request_allowed
from hub_auth import request_allowed, safe_next_path, verify_hub_sso_token
def _hub_auth_required(f):
@@ -244,6 +244,22 @@ def register_hub_routes(app):
return jsonify({"ok": False, "msg": "预览不存在或已过期"}), 404
return jsonify({"ok": True, "preview": preview})
@app.route("/hub-sso")
def hub_sso_login():
"""中控签发的临时链接:写入 session 后跳转,直链访问仍走 /login。"""
auth_disabled = bool(current_app.config.get("HUB_AUTH_DISABLED"))
next_arg = request.args.get("next")
if auth_disabled:
session["logged_in"] = True
return redirect(safe_next_path(next_arg))
ex = str((_ctx().get("exchange") or "")).strip().lower()
token = (request.args.get("token") or "").strip()
ok, next_path, _err = verify_hub_sso_token(token, ex)
if ok:
session["logged_in"] = True
return redirect(next_path)
return redirect("/login")
def _latest_preview_id():
get_db = _ctx().get("get_db")