Skip to content

Split web/mod.rs (3496 lines) into route/service modules (#55) - #63

Closed
AptS-1547 wants to merge 1 commit into
IRmsk:mainfrom
AptS-1547:refactor/web-mod-split
Closed

AptS-1547 wants to merge 1 commit into
IRmsk:mainfrom
AptS-1547:refactor/web-mod-split

Conversation

@AptS-1547

Copy link
Copy Markdown
Contributor

Closes #55.

Summary

Splits src/web/mod.rs (3496 lines) into route and service modules, following the layered layout proposed in the issue:

web/
├── mod.rs            (317)  serve loop, inflight cap, panic isolation, dispatch
├── console_auth.rs   (223)  token check, loopback test, cross-site-write guard
├── http.rs           (148)  url decode, body limit, JSON response plumbing
├── assets.rs         (242)  index + frontend css/js table (#54)
├── state.rs          (481)  State/Shared, account-book restore, per-account clients
└── routes/
    ├── login.rs      ( 80)  POST /api/login
    ├── run.rs        (814)  /api/plan, /api/run (+ parse_end/input_to_bd09/alt_range/custom_path)
    ├── accounts.rs   (488)  account CRUD, switch/toggle/login, batch, /api/me, /api/logout
    ├── records.rs    (145)  records list/detail, OBS fetch, cheat self-check
    ├── map_data.rs   (223)  points, fences, blockers
    └── meta.rs       (494)  starttimes, semester, egress, device, netcheck, /api/raw

Two things worth calling out:

Equivalence

Pure code motion — the route table, auth checks, throttling, and every response body stay byte-identical:

  • Test conservation: all 27 #[test] modules move with the code they cover; 27 before, 27 after, none dropped.
  • cargo test: 526 lib tests + integration tests green. cargo clippy --all-targets: 0 warnings. cargo fmt --check: clean.
  • Smoke-tested the real binary: GET / 200, static assets (/console.css, /js/core.js) 200, /api/health and /api/accounts response envelopes byte-identical to before, unknown routes 404, POST /api/me (GET-only route) still 404.

No protocol or behavior surface changes.

Everything above the api/* client layer lived in one file: server loop,
inflight throttling, panic isolation, console auth, the route dispatch,
~30 handlers across every feature domain, state management, HTTP
helpers, static assets and 27 tests. Module boundaries existed
implicitly; they just had no file boundary.

Now, mirroring the layered layout of the other services:

- web/mod.rs (317) - serve loop, inflight cap, panic isolation, dispatch
- web/console_auth.rs - token check, loopback test, cross-site-write guard
- web/http.rs - url decode, body limits, JSON responses
- web/assets.rs - index + frontend css/js table (IRmsk#54)
- web/state.rs - State/Shared, account book restore, per-account clients
- web/routes/{login,run,accounts,records,map_data,meta}.rs - one file
  per feature domain; /api/me and /api/logout moved out of inline
  dispatch arms into accounts.rs unchanged

Pure code motion: route table, auth checks, throttling and every
response body stay byte-identical. All 27 web test modules move with
the code they cover; test count is unchanged (27 before, 27 after).
Closes IRmsk#55.
@IRmsk

IRmsk commented Nov 26, 2026

Copy link
Copy Markdown
Owner

看到了,谢谢你另外提的这版。拆分我这边先一步推了 main(b8dbeaf),结构和你这个基本一致,/api/me、/api/logout 抽成独立 handler 这点你做得比我细。

PR 你关掉没问题,这个 issue 我没动。

@AptS-1547
AptS-1547 deleted the refactor/web-mod-split branch November 26, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: split web/mod.rs (3488 lines) into route/service modules following the Aster layered layout

2 participants