优化登录重试与配置清理
This commit is contained in:
@@ -24,21 +24,25 @@ def _fmt_dt(dt) -> str | None:
|
||||
router = APIRouter(prefix="/api/cookies", tags=["Cookie管理"])
|
||||
|
||||
|
||||
def _visible_cookie_tasks_query(db: Session, current: User):
|
||||
"""返回当前用户可见的成功 Cookie 任务查询。"""
|
||||
query = db.query(LoginTask).filter(LoginTask.status == "success")
|
||||
|
||||
# 无全量登录任务权限时,只能操作分配给自己的账号 Cookie。
|
||||
if not user_has_permission(current, "login:view_all"):
|
||||
query = query.join(Account, LoginTask.account_id == Account.id).filter(
|
||||
Account.assigned_to == current.id
|
||||
)
|
||||
return query
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_cookies(
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(get_current_user),
|
||||
):
|
||||
"""查看登录成功的 Cookie 列表。"""
|
||||
query = db.query(LoginTask).filter(LoginTask.status == "success")
|
||||
|
||||
# 客服只能看自己账号的
|
||||
if not user_has_permission(current, "login:view_all"):
|
||||
query = query.join(Account, LoginTask.account_id == Account.id).filter(
|
||||
Account.assigned_to == current.id
|
||||
)
|
||||
|
||||
tasks = query.order_by(LoginTask.finished_at.desc()).all()
|
||||
tasks = _visible_cookie_tasks_query(db, current).order_by(LoginTask.finished_at.desc()).all()
|
||||
|
||||
# 批量查账号,避免 N+1 查询
|
||||
account_ids = [t.account_id for t in tasks]
|
||||
@@ -81,9 +85,7 @@ def export_cookies(
|
||||
csv: 账号, Cookie, 时间
|
||||
custom: 账号----密码----ck
|
||||
"""
|
||||
tasks = db.query(LoginTask).filter(
|
||||
LoginTask.status == "success"
|
||||
).order_by(LoginTask.finished_at.desc()).all()
|
||||
tasks = _visible_cookie_tasks_query(db, current).order_by(LoginTask.finished_at.desc()).all()
|
||||
|
||||
# 批量查账号,避免 N+1
|
||||
account_ids = [t.account_id for t in tasks]
|
||||
@@ -136,7 +138,7 @@ def delete_cookies_batch(
|
||||
ids = [int(x) for x in task_ids.split(",") if x.strip().isdigit()]
|
||||
if not ids:
|
||||
raise HTTPException(status_code=400, detail="无效的ID")
|
||||
tasks = db.query(LoginTask).filter(LoginTask.id.in_(ids)).all()
|
||||
tasks = _visible_cookie_tasks_query(db, current).filter(LoginTask.id.in_(ids)).all()
|
||||
for t in tasks:
|
||||
t.cookie = ""
|
||||
t.status = "failed"
|
||||
@@ -152,7 +154,7 @@ def delete_cookie(
|
||||
current: User = Depends(require_permission("cookie:export")),
|
||||
):
|
||||
"""删除一条 Cookie 记录。"""
|
||||
task = db.query(LoginTask).filter(LoginTask.id == task_id).first()
|
||||
task = _visible_cookie_tasks_query(db, current).filter(LoginTask.id == task_id).first()
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="记录不存在")
|
||||
task.cookie = ""
|
||||
|
||||
@@ -54,7 +54,6 @@ async def create_batch(
|
||||
account_ids=valid_ids,
|
||||
created_by=current.id,
|
||||
creator_permissions=get_user_permissions(current),
|
||||
max_geetest_retries=req.max_geetest_retries,
|
||||
max_proxy_retries=req.max_proxy_retries,
|
||||
max_login_retries=req.max_login_retries,
|
||||
max_total_time=req.max_total_time,
|
||||
|
||||
Reference in New Issue
Block a user