批量检测账号订阅状态
(request: BatchCheckSubscriptionRequest)
| 3263 | |
| 3264 | @router.post("/accounts/batch-check-subscription") |
| 3265 | def batch_check_subscription(request: BatchCheckSubscriptionRequest): |
| 3266 | """批量检测账号订阅状态""" |
| 3267 | explicit_proxy = _normalize_proxy_value(request.proxy) |
| 3268 | |
| 3269 | results = {"success_count": 0, "failed_count": 0, "details": []} |
| 3270 | |
| 3271 | with get_db() as db: |
| 3272 | ids = resolve_account_ids( |
| 3273 | db, request.ids, request.select_all, |
| 3274 | request.status_filter, request.email_service_filter, request.search_filter |
| 3275 | ) |
| 3276 | for account_id in ids: |
| 3277 | account = db.query(Account).filter(Account.id == account_id).first() |
| 3278 | if not account: |
| 3279 | results["failed_count"] += 1 |
| 3280 | results["details"].append( |
| 3281 | {"id": account_id, "email": None, "success": False, "error": "账号不存在"} |
| 3282 | ) |
| 3283 | continue |
| 3284 | |
| 3285 | try: |
| 3286 | runtime_proxy = _resolve_runtime_proxy(explicit_proxy, account) |
| 3287 | detail, refreshed = _check_subscription_detail_with_retry( |
| 3288 | db=db, |
| 3289 | account=account, |
| 3290 | proxy=runtime_proxy, |
| 3291 | allow_token_refresh=True, |
| 3292 | ) |
| 3293 | status = str(detail.get("status") or "free").lower() |
| 3294 | confidence = str(detail.get("confidence") or "low").lower() |
| 3295 | |
| 3296 | if status in ("plus", "team"): |
| 3297 | account.subscription_type = status |
| 3298 | account.subscription_at = utcnow_naive() |
| 3299 | elif status == "free" and confidence == "high": |
| 3300 | account.subscription_type = None |
| 3301 | account.subscription_at = None |
| 3302 | |
| 3303 | db.commit() |
| 3304 | results["success_count"] += 1 |
| 3305 | results["details"].append( |
| 3306 | { |
| 3307 | "id": account_id, |
| 3308 | "email": account.email, |
| 3309 | "success": True, |
| 3310 | "subscription_type": status, |
| 3311 | "confidence": confidence, |
| 3312 | "source": detail.get("source"), |
| 3313 | "token_refreshed": refreshed, |
| 3314 | } |
| 3315 | ) |
| 3316 | except Exception as e: |
| 3317 | results["failed_count"] += 1 |
| 3318 | results["details"].append( |
| 3319 | {"id": account_id, "email": account.email, "success": False, "error": str(e)} |
| 3320 | ) |
| 3321 | |
| 3322 | return results |
nothing calls this directly
no test coverage detected