feat: support real browser auth import
This commit is contained in:
@@ -315,6 +315,26 @@ def list_generated_keys(uid: int, db: Session = Depends(get_db), _=Depends(get_c
|
||||
_generate_key_lock = __import__("threading").Lock()
|
||||
|
||||
|
||||
def _is_sub2api_upstream(upstream: Upstream) -> bool:
|
||||
return upstream.api_prefix.strip("/") == "api/v1"
|
||||
|
||||
|
||||
def _is_new_api_user_upstream(upstream: Upstream) -> bool:
|
||||
auth_config = json.loads(upstream.auth_config_json or "{}")
|
||||
return (
|
||||
upstream.api_prefix.strip("/") == ""
|
||||
and (
|
||||
upstream.groups_endpoint == "/api/user/self/groups"
|
||||
or auth_config.get("login_path") == "/api/user/login"
|
||||
or bool(auth_config.get("new_api_user"))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _supports_key_generation(upstream: Upstream) -> bool:
|
||||
return _is_sub2api_upstream(upstream) or _is_new_api_user_upstream(upstream)
|
||||
|
||||
|
||||
def _ensure_group_key(
|
||||
db: Session,
|
||||
client: UpstreamClient,
|
||||
@@ -465,8 +485,8 @@ def generate_keys_by_groups(
|
||||
u = db.query(Upstream).filter(Upstream.id == uid).first()
|
||||
if not u:
|
||||
raise HTTPException(404, "upstream not found")
|
||||
if u.api_prefix.strip("/") != "api/v1":
|
||||
raise HTTPException(400, "首版仅支持 Sub2API 上游(API Prefix 应为 /api/v1)")
|
||||
if not _supports_key_generation(u):
|
||||
raise HTTPException(400, "仅支持 Sub2API 或 New-API 普通账号上游生成 Key")
|
||||
|
||||
# 生成前先对账,清理远端已删除的旧 Key
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user