Spaces:
Running
Running
nacho commited on
Commit ·
9ce0ead
1
Parent(s): 0ecb6f3
feat: 网页端导入新账号后自动触发后台预登录,无需等待首次请求
Browse files
main.py
CHANGED
|
@@ -363,6 +363,7 @@ async def import_accounts(request: Request, admin_key: str = Header(...)):
|
|
| 363 |
raise HTTPException(status_code=400, detail="No accounts provided")
|
| 364 |
|
| 365 |
imported = 0
|
|
|
|
| 366 |
for acc in accounts:
|
| 367 |
email = acc.get("email")
|
| 368 |
password = acc.get("password")
|
|
@@ -370,8 +371,25 @@ async def import_accounts(request: Request, admin_key: str = Header(...)):
|
|
| 370 |
proxy = acc.get("proxy")
|
| 371 |
|
| 372 |
if email and password:
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
return {"success": True, "imported": imported, "total": len(manager.accounts)}
|
| 377 |
|
|
|
|
| 363 |
raise HTTPException(status_code=400, detail="No accounts provided")
|
| 364 |
|
| 365 |
imported = 0
|
| 366 |
+
new_accounts = []
|
| 367 |
for acc in accounts:
|
| 368 |
email = acc.get("email")
|
| 369 |
password = acc.get("password")
|
|
|
|
| 371 |
proxy = acc.get("proxy")
|
| 372 |
|
| 373 |
if email and password:
|
| 374 |
+
if email not in manager.accounts:
|
| 375 |
+
manager.add_account(email, password, name, proxy)
|
| 376 |
+
new_accounts.append(manager.accounts[email])
|
| 377 |
+
imported += 1
|
| 378 |
+
|
| 379 |
+
# 异步触发新导入账号的预登录
|
| 380 |
+
async def prelogin_new_accounts():
|
| 381 |
+
for account in new_accounts:
|
| 382 |
+
try:
|
| 383 |
+
logger.info("Pre-logging in newly imported account %s...", account.email)
|
| 384 |
+
await manager.get_or_create_browser_with_retry(
|
| 385 |
+
account, headless=config.browser.headless
|
| 386 |
+
)
|
| 387 |
+
logger.info("Pre-login OK: %s", account.email)
|
| 388 |
+
except Exception as e:
|
| 389 |
+
logger.error("Pre-login FAILED for %s: %s", account.email, e)
|
| 390 |
+
|
| 391 |
+
if new_accounts:
|
| 392 |
+
asyncio.create_task(prelogin_new_accounts())
|
| 393 |
|
| 394 |
return {"success": True, "imported": imported, "total": len(manager.accounts)}
|
| 395 |
|