Commit Graph
78 Commits
Author SHA1 Message Date
liumangmang fd46492012 test: 补充基于 TestClient 的路由级集成测试,锁死并验证 group_id 包含斜杠时的路径转换器匹配行为 2026-07-01 18:02:10 +08:00
liumangmang ef14382e5f fix: 后端路由 group_id 启用 path 路径匹配转换器,完美兼容带斜杠的远端分组 ID 2026-07-01 17:58:56 +08:00
liumangmang 3172ab18bf fix: 修改目标分组名称后自动同步更新本地绑定表中的名称缓存,并为前端更新分组 URL 中的 groupId 进行 Url 编码 2026-07-01 17:55:53 +08:00
liumangmang 8c2f1c13bb feat: 支持网站目标分组轻量管理(新增、编辑、描述展示),不修改和不提交倍率 2026-07-01 17:47:36 +08:00
liumangmang e5d7af8906 feat: 网站分组列表默认按倍率从小到大(升序)排序 2026-07-01 17:22:19 +08:00
liumangmang 650451c123 fix: 引入 normalizeRateBound 标准化倍率空输入,解决输入清空后过滤失效的问题 2026-07-01 17:14:28 +08:00
liumangmang 04d719b417 feat: 选择上游分组弹窗支持倍率范围(大于等于/小于等于)筛选 2026-07-01 17:06:18 +08:00
liumangmang f9b5a03330 fix: 缩小选择分组弹窗的搜索范围至分组自身信息,更新输入占位提示文案 2026-07-01 16:31:40 +08:00
liumangmang 7c7942c83b fix: 解决选择框异常压缩、新增绑定自动选择首个分组、以及弹窗自适应2K显示器比例 2026-07-01 16:13:05 +08:00
liumangmang 962614500c refactor: 隔离 Websites.vue 全局样式,仅对 Element Plus 壳层节点应用非 scoped 样式以防污染其他页面 2026-07-01 15:52:48 +08:00
liumangmang 71e0fe40a9 refactor: 按照新版 ui_redesign_prototype.html 重构新增绑定抽屉和选择上游分组弹窗 2026-07-01 15:47:51 +08:00
liumangmang 756d6e1083 style: 移除 Websites.vue 中所有尾部多余空格 2026-07-01 15:16:07 +08:00
liumangmang 02e41fa80e feat: 监听上游分组改用专用弹窗选择器,支持搜索、多选及已选Tag展示 2026-07-01 15:11:53 +08:00
liumangmang 8abfa4c5ef feat: 重构接口日志页面与接口监控看板,支持HTTP方法过滤和实时轮询 2026-07-01 15:04:32 +08:00
liumangmang 397a14c978 feat(website): 支持基于现有绑定一键整理分组,支持账号校验补齐、自愈重建与缺失 Key 提示 (含异常保守跳过及名称层级匹配) 2026-07-01 11:21:20 +08:00
liumangmang bf5470caf3 fix(sync): 优先级同步前置过滤远端失效账号防排序污染,移除 locals 隐患,并将自愈结果纳入本地日志与摘要统计 2026-07-01 10:20:13 +08:00
liumangmang efd0a88249 perf(import): 优化账号导入弹窗为秒开体验并支持批量回查校验 2026-07-01 10:00:40 +08:00
liumangmang 88c783b922 chore: remove Reasonix doc and ignore nox-api 2026-07-01 09:17:09 +08:00
liumangmang d92537688a fix(priority): keep readable priority sync details 2026-07-01 09:12:39 +08:00
liumangmang fe40fcd4c9 feat(priority): group priority changed notifications by target group and fetch remote account details 2026-07-01 09:00:29 +08:00
liumangmang 6065e824e3 fix(upstreams): add db.rollback() on exception to prevent dirty replaced status leak 2026-06-30 17:33:43 +08:00
liumangmang edc00444dc fix(nox-api): address duplicate creation risks, pending upgrading issues, cache warm error handling, test speedups, and frontend display support for pending keys 2026-06-30 17:25:18 +08:00
liumangmang 4fa6a79c5a feat(nox-api): implement batch creation rate limit resilience and pending backfilling 2026-06-30 17:00:26 +08:00
liumangmang 854a640d48 fix: shorten New-API token names 2026-06-30 16:12:46 +08:00
liumangmang 8bff1c1551 chore: remove reasonix artifacts 2026-06-30 14:36:13 +08:00
liumangmang c5bb63cf82 feat: support upstream token refresh 2026-06-30 14:34:40 +08:00
SmartUp Developer 2d1dcb8f9f fix: round website rates to two decimals 2026-06-30 11:26:48 +08:00
liumangmang a914d3d222 feat: add Nox-API upstream support 2026-06-30 11:22:38 +08:00
SmartUp Developer 9600e4ceba fix: backfill account groups before priority reorder 2026-06-03 18:39:21 +08:00
SmartUp Developer b866b387e0 feat: sync upstream keys and reorder priorities 2026-06-03 17:03:11 +08:00
liumangmang a42bcba483 Remove server remote browser support 2026-06-02 19:25:20 +08:00
liumangmang 3181a6f6cc feat: add browser extension origin save 2026-06-02 15:32:43 +08:00
liumangmang 84148f4a69 feat: support real browser auth import 2026-06-02 13:51:29 +08:00
liumangmang f4d16a4c01 fix(frontend): include cookie_count and cookie_names in AuthCaptureDialog emit 2026-06-02 10:07:32 +08:00
liumangmang 0b1daf277b fix(frontend): apply new-api-user endpoint reset to cookie_bundle capture branch 2026-06-02 09:58:18 +08:00
liumangmang b77ea21ca8 fix(frontend): support cookie_bundle candidate in AuthCaptureDialog and refreshAuth 2026-06-02 09:52:43 +08:00
liumangmang 4f9acdc99c feat(auth-capture): full cookie bundle extraction + richer refresh-auth
Problem: Meow upstream uses Cloudflare, which sets cf_clearance + session
cookies that must all be sent together. The old code only captured a single
session-named cookie via a whitelist, discarding cf_clearance entirely, and
wrote back only 'name=value' instead of the full cookie string.

Changes:

auth_capture_service.py:
  - Add _cookie_matches_hostname(): hostname suffix matching supporting
    dot-prefixed domains (.saki.lat matches api.saki.lat)
  - Add _build_cookie_bundle(): collects ALL cookies matching the current
    page's hostname, returns complete 'name1=v1; name2=v2' string
  - _curate_candidates(): new 'cookie_bundle' candidate type (type=0 in sort,
    highest priority), carries cookie_count + cookie_names in extra fields
  - extract_all(): obtain real-time page URL from session.page.url and pass
    to _curate_candidates so cookie domain filtering is accurate
  - Sort order: cookie_bundle > cookie > bearer_token/api_key > credential
  - Fix bug in original JWT dedup check (was assigning instead of checking)

custom_pages.py:
  - Add logging import + logger
  - _pick_best_candidate(): cookie preferred_auth_type now tries cookie_bundle
    first, then single cookie; bearer/api_key use existing type_map logic
  - RefreshAuthResponse: add optional 'warning' field
  - refresh_auth(): handle ctype='cookie_bundle' same as 'cookie'; always
    write full candidate.value as cookie_string (works for both types)
  - Post-write validation: attempt get_available_groups with new credentials;
    on failure, still commit (lenient mode) but set warning message explaining
    cf_clearance IP-binding as the likely cause; success logs at INFO level

Tests (test_auth_capture.py, 19 cases):
  - _cookie_matches_hostname: exact, dot-prefix subdomain, empty domain,
    different domain, evil-subdomain partial match rejection
  - _build_cookie_bundle: cf_clearance included, cross-domain excluded,
    single cookie, empty value excluded, no cookies
  - _curate_candidates: bundle ranks first, value is full string, bundle
    beats single session cookie, bearer wins when no cookies, empty case,
    cookie_count/cookie_names in extra, session fallback preserved,
    new_api_user propagation to bundle

All 46 tests pass.
2026-06-02 09:32:23 +08:00
liumangmang f17317b13c fix(priority-sync): handle missing rate data and backfill target group on re-import
P1 - Missing rate data now skips account instead of falling back to 1.0:
  In sync_account_priorities_for_upstream(), the rated list now filters
  out accounts whose upstream snapshot has no rate entry for their group_id.
  If after filtering a competitive bucket has fewer than 2 accounts with
  valid rate data, the entire bucket is silently skipped (no update_account
  call, no webhook) rather than treating missing rates as 1.0 and
  potentially triggering spurious notifications.

P2 - Re-importing an existing account now backfills imported_target_group_id:
  In the exists-is-True idempotency branch of import_upstream_keys_as_accounts(),
  if the current request supplies a target_group_id for the account's source group
  and it differs from what is stored, the field is written back and committed.
  This lets operators fix old data by simply re-running the import dialog.

Tests added:
  - test_missing_rate_skips_entire_competitive_group: all accounts in
    competitive group lack snapshot → bucket skipped, no update called
  - test_partial_missing_rate_sufficient_accounts_still_updates: 3 accounts
    in same bucket, 1 missing rate → the 2 with rates still compete normally

All 27 tests pass.
2026-06-01 19:27:35 +08:00
liumangmang e519d1804b fix(priority-sync): narrow account priority update to competitive groups only
Root cause: sync_account_priorities_for_upstream() was doing a global
priority re-rank across ALL imported accounts on a website whenever any
upstream rate changed, triggering spurious account_priority_changed
notifications for accounts in different target groups with no competition.

Fix:
- Add imported_target_group_id / imported_target_group_name to
  UpstreamGeneratedKey (nullable; old data falls back to group_id)
- Writ imported_target_group_id on account import in websites.py
- Rewrite sync_account_priorities_for_upstream():
  * bucket accounts by competition_group = imported_target_group_id or group_id
  * only process buckets with count > 1 (genuine competition)
  * each competitive bucket independently sorted by rate; priority starts at 1
  * single-account groups: completely skipped (no update_account, no notification)
  * no competitive groups at all: early return, no log, no notification
- Remove auto priority update in re-import idempotency path (was also
  incorrect; now fully delegated to sync_account_priorities_for_upstream)
- Fix Sub2ApiWebsiteClient local import in sync fn → use module-level name
  so monkeypatch works correctly in tests

Tests: rewrite test_priority_sync.py
- REMOVED: test_priority_sync_full_website_update (was asserting the buggy behavior)
- NEW: test_no_update_when_different_groups_single_account_each
- NEW: test_same_target_group_two_accounts_updated
- NEW: test_two_target_groups_independent_priority
- NEW: test_old_data_null_target_group_fallback
- NEW: test_single_account_in_mixed_website
- UPDATED: test_priority_sync_log_structure (now requires competitive group)
- KEPT: test_priority_sync_cross_upstream_group, test_import_auto_priority_by_rate

All 25 tests pass (8 priority_sync + 17 existing upstream tests).
2026-06-01 19:13:14 +08:00
liumangmang 871557e4ae feat(upstreams): add batch test-all / check-now-all endpoints
- POST /api/upstreams/test-all: batch connection test for all enabled
  upstreams (no snapshot, no webhook); updates last_status, balance
- POST /api/upstreams/check-now-all: full batch sync (snapshot, diff,
  webhook, key sync, priority sync); mirrors single check-now behavior
- Both routes are registered before /{uid} to avoid path capture
- Skips disabled upstreams (status=skipped); single failure does not
  abort subsequent upstreams (serial execution)
- Returns UpstreamBatchActionResponse with per-item detail and summary

Refactor: extract _test_upstream_core(db, u) and _check_now_core(db, u)
- All four routes (single + batch × 2) now share the same core helpers
- Eliminates duplicate logic and future divergence risk

Frontend:
- Add UpstreamBatchActionResponse / Item / Summary TS types
- Add upstreamsApi.testAll() and upstreamsApi.checkNowAll()
- Add '一键测试' and '一键同步' buttons in Upstreams.vue toolbar
  (order: 一键测试 → 一键同步 → 刷新 → 新增上游)
- Buttons disabled when list is empty or another batch op is running
- On completion: refresh list + ElMessageBox with per-item failure detail
2026-06-01 16:46:42 +08:00
liumangmang a949969c4d perf: remote browser CPU / zombie optimization
- Add tini (init: true in compose) to reap orphan Chromium processes
- Reduce screenshot push frequency (active 0.12→0.20s, idle 0.35→1.00s,
  deep idle 1.00→5.00s, backoff 0.60→2.00s)
- Add 5s timeout to screenshot in WebSocket push loop
- close() now wraps context.close() in asyncio.wait_for(10s)
  with browser.close() fallback on timeout
- Two-phase close logging (closing → closed / close_failed)
- Auth-capture sessions evicted after 10min TTL
- shutdown() with timeout protection and logging
- close_ok correctly tracks success through browser fallback path
2026-06-01 15:47:08 +08:00
liumangmang c8ba25f08e feat: live remote key list with auto-upsert and safe group name extraction
- list_generated_keys now fetches live keys from upstream API, merges with
  local DB: remote keys with plaintext values are auto-upserted (by
  group_id+managed_prefix), remote-only keys shown as unimportable
- Use _fetch_remote_managed_prefixes to support custom key prefixes
- Group remote keys by (group_id, prefix), pick latest by key_id
- Extract _remote_group_name helper for safe group name parsing
  (handles dict group field from Meow upstream)
- Frontend excludes orphaned keys from importable list
- Backend import endpoint reconciles upstream before importing
2026-06-01 14:53:40 +08:00
liumangmang bea4344bb3 fix: reconcile upstream keys on list/generate/import to prevent stale key imports
- Extract reconcile_upstream_keys() to website_sync.py (shared scheduler + on-demand)
- Add reconcile_upstream_keys_full() for on-demand reconciliation at three entry points:
  list_generated_keys, generate_keys_by_groups, import_upstream_keys_as_accounts
- Safe on failure: active_group_ids=None / remote_key_ids=None skip cleanup
- Support custom managed_prefix via _fetch_remote_managed_key_ids() helper
- Exclude orphaned keys from frontend importable list
- Remove hardcoded search='SmartUp' from scheduler path
2026-06-01 11:29:37 +08:00
liumangmang 3408795289 feat: default upstream balance config for new upstream form
defaultForm() now uses sub2api presets for balance fields:
- balance_endpoint: /auth/me
- balance_response_path: data.balance
- balance_divisor: 1.0

Platform presets in handlePlatformChange() remain unchanged.
2026-06-01 11:09:31 +08:00
liumangmang 92eb4888d1 test: replace TestClient with direct router calls to fix hang in binding tests
- Removed TestClient/FastAPI/app.main imports entirely
- Tests now call websites_router.create_binding() and
  websites_router.update_binding() directly with db_session
- Bypasses all ASGI transport and lifespan issues
- All 13 tests pass in 0.75s
2026-06-01 10:26:23 +08:00
liumangmang 830b6df587 test: fix hang in group binding regression tests by isolating sessions and mocking lifespan 2026-06-01 09:32:44 +08:00
liumangmang 518e3e8efc feat: add one-click sync for website group bindings 2026-06-01 09:06:01 +08:00
liumangmang 890432e1a5 test: fix RuntimeWarnings in multi-tab concurrency test 2026-05-30 10:21:30 +08:00
liumangmang 18c04c1f86 test: enhance multi-tab coverage for concurrency and events 2026-05-30 10:17:24 +08:00
liumangmang 5268f1119b fix: multi-tab concurrency and metadata sync improvements 2026-05-30 10:08:55 +08:00