fix: restore api_key from local key_value when syncing upstream models for apikey accounts

This commit is contained in:
SmartUp Developer
2026-07-02 23:38:57 +08:00
parent a0c96ed5da
commit 9997b9d56a
2 changed files with 105 additions and 14 deletions
+20
View File
@@ -1433,6 +1433,26 @@ def _sync_upstream_models_generator(wid: int, db: Session):
}
current_creds["base_url"] = upstream_base_url
# 对 SmartUp 导入的 apikey 类型账号,必须从本地 key_value 补回 api_key
# 若 key_value 为空则禁止继续写回,避免写坏账号。
db_key = cand.get("db_key")
acc_type = remote_acc.get("type", "")
if acc_type == "apikey":
local_key_value = (db_key.key_value or "").strip() if db_key else ""
if not local_key_value:
item = SyncUpstreamModelsItem(
account_id=aid,
account_name=acc_name,
model_count=0,
models=[],
status="failed",
message="本地 key_value 为空,跳过处理避免写坏账号 api_key"
)
items.append(item)
yield "item", item.model_dump()
continue
current_creds["api_key"] = local_key_value
try:
c.update_account(aid, {"credentials": current_creds})
except Exception as e: