From fe7f9a01ea677d578d6653047e5cd80008f15720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 24 Nov 2026 18:50:14 +0300 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20deps:=20topcoat=200.12.1:?= =?UTF-8?q?=20path=20params=20read=20through=20their=20generated=20functio?= =?UTF-8?q?ns=20(owner(cx)),=20app=5Fcontext=20is=20context,=20every=20com?= =?UTF-8?q?ponent,=20page=20and=20route=20takes=20cx:=20&Cx=20first,=20vie?= =?UTF-8?q?w!=20captures=20cx,=20cookies=20come=20from=20CookieLayer,=20co?= =?UTF-8?q?mpression=20is=20off=20through=20with(Compression::disable()),?= =?UTF-8?q?=20and=20the=20avatar=20body=20limits=20sit=20on=20their=20rout?= =?UTF-8?q?es=20=F0=9F=8E=A8=20style:=20cargo=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 141 +++++++++--------- Cargo.toml | 2 +- crates/forge-core/src/store/migrate.rs | 10 +- crates/forge-core/src/tz.rs | 6 +- crates/forge-e2e/tests/e2e/browse_e2e.rs | 6 +- .../forge-e2e/tests/e2e/community_i18n_e2e.rs | 10 +- crates/forge-e2e/tests/e2e/pulls_e2e.rs | 3 +- crates/forge-e2e/tests/e2e/repo_rename_e2e.rs | 4 +- .../forge-e2e/tests/e2e/repo_settings_e2e.rs | 21 ++- .../forge-e2e/tests/e2e/repo_transfer_e2e.rs | 12 +- crates/forge-web-base/src/accent.rs | 10 +- crates/forge-web-base/src/compression.rs | 2 +- crates/forge-web-base/src/i18n/admin.rs | 8 +- crates/forge-web-base/src/i18n/issues.rs | 4 +- crates/forge-web-base/src/render/markdown.rs | 10 +- crates/forge-web/src/api/gitea.rs | 55 +++---- crates/forge-web/src/api/packages.rs | 64 +++----- crates/forge-web/src/api/releases.rs | 62 +++----- crates/forge-web/src/api/statuses.rs | 28 +--- crates/forge-web/src/auth.rs | 10 +- crates/forge-web/src/boot.rs | 10 +- crates/forge-web/src/ci/api.rs | 38 ++--- crates/forge-web/src/client_ip.rs | 4 +- crates/forge-web/src/git_http.rs | 16 +- crates/forge-web/src/internal.rs | 14 +- crates/forge-web/src/lfs/routes.rs | 30 ++-- crates/forge-web/src/main.rs | 2 +- crates/forge-web/src/oci/auth.rs | 4 +- crates/forge-web/src/oci/mod.rs | 10 +- crates/forge-web/src/pages/activity.rs | 6 +- crates/forge-web/src/pages/admin_backups.rs | 18 ++- crates/forge-web/src/pages/admin_health.rs | 13 +- crates/forge-web/src/pages/admin_mail.rs | 11 +- .../forge-web/src/pages/admin_replication.rs | 11 +- crates/forge-web/src/pages/admin_runners.rs | 76 +++++----- crates/forge-web/src/pages/admin_server.rs | 19 +-- .../forge-web/src/pages/admin_user_detail.rs | 18 ++- crates/forge-web/src/pages/admin_users.rs | 19 ++- crates/forge-web/src/pages/archive.rs | 10 +- crates/forge-web/src/pages/assets.rs | 58 ++++--- crates/forge-web/src/pages/audit_log.rs | 37 +++-- crates/forge-web/src/pages/authoring.rs | 22 +-- crates/forge-web/src/pages/avatars.rs | 9 +- crates/forge-web/src/pages/banner.rs | 6 +- crates/forge-web/src/pages/blame.rs | 19 ++- crates/forge-web/src/pages/blob.rs | 18 ++- crates/forge-web/src/pages/branches.rs | 22 +-- crates/forge-web/src/pages/ci_badge.rs | 8 +- crates/forge-web/src/pages/ci_fail.rs | 23 ++- crates/forge-web/src/pages/ci_job.rs | 37 ++--- crates/forge-web/src/pages/ci_runs.rs | 138 ++++++++++------- crates/forge-web/src/pages/ci_tests.rs | 5 +- crates/forge-web/src/pages/code_live.rs | 8 +- crates/forge-web/src/pages/code_search.rs | 8 +- crates/forge-web/src/pages/commit.rs | 12 +- crates/forge-web/src/pages/commits.rs | 10 +- crates/forge-web/src/pages/compare.rs | 28 ++-- .../forge-web/src/pages/discussion_actions.rs | 62 ++++---- crates/forge-web/src/pages/discussion_live.rs | 14 +- .../src/pages/discussion_settings.rs | 14 +- crates/forge-web/src/pages/discussion_view.rs | 18 ++- crates/forge-web/src/pages/discussions.rs | 21 +-- crates/forge-web/src/pages/edit_history.rs | 23 ++- crates/forge-web/src/pages/explore.rs | 35 +++-- crates/forge-web/src/pages/finder.rs | 11 +- crates/forge-web/src/pages/forgot.rs | 13 +- crates/forge-web/src/pages/fork.rs | 8 +- crates/forge-web/src/pages/home.rs | 10 +- crates/forge-web/src/pages/import.rs | 74 +++++---- crates/forge-web/src/pages/invites.rs | 5 +- crates/forge-web/src/pages/issue_meta.rs | 44 +++--- crates/forge-web/src/pages/issue_parts.rs | 56 +++++-- crates/forge-web/src/pages/issue_pin.rs | 11 +- crates/forge-web/src/pages/issue_pin_tests.rs | 5 +- crates/forge-web/src/pages/issue_view.rs | 62 ++++---- crates/forge-web/src/pages/issues_list.rs | 28 ++-- crates/forge-web/src/pages/issues_live.rs | 12 +- crates/forge-web/src/pages/labels_css.rs | 8 +- crates/forge-web/src/pages/labels_page.rs | 55 +++---- crates/forge-web/src/pages/login.rs | 23 ++- crates/forge-web/src/pages/media.rs | 4 +- crates/forge-web/src/pages/merge_queue.rs | 34 ++--- crates/forge-web/src/pages/milestones_page.rs | 59 ++++---- crates/forge-web/src/pages/needs_you.rs | 8 +- crates/forge-web/src/pages/new_repo.rs | 13 +- crates/forge-web/src/pages/not_found_page.rs | 4 +- crates/forge-web/src/pages/notifications.rs | 76 ++++++---- crates/forge-web/src/pages/org_ctx.rs | 7 +- crates/forge-web/src/pages/org_live.rs | 22 +-- crates/forge-web/src/pages/org_members.rs | 31 ++-- crates/forge-web/src/pages/org_new.rs | 11 +- crates/forge-web/src/pages/org_settings.rs | 27 ++-- crates/forge-web/src/pages/org_teams.rs | 58 +++---- crates/forge-web/src/pages/packages.rs | 22 +-- crates/forge-web/src/pages/packages_oci.rs | 3 +- crates/forge-web/src/pages/palette.rs | 4 +- crates/forge-web/src/pages/passkeys.rs | 23 +-- crates/forge-web/src/pages/passkeys_tests.rs | 5 +- crates/forge-web/src/pages/profile.rs | 31 ++-- crates/forge-web/src/pages/profile_pins.rs | 11 +- crates/forge-web/src/pages/pull_branch.rs | 9 +- crates/forge-web/src/pages/pull_files.rs | 30 ++-- crates/forge-web/src/pages/pull_flow.rs | 22 +-- crates/forge-web/src/pages/pull_live.rs | 14 +- crates/forge-web/src/pages/pull_reviews.rs | 80 +++++----- crates/forge-web/src/pages/pull_view.rs | 41 ++--- crates/forge-web/src/pages/pulls_list.rs | 26 ++-- crates/forge-web/src/pages/pulls_merge.rs | 8 +- crates/forge-web/src/pages/push.rs | 24 +-- crates/forge-web/src/pages/reactions.rs | 8 +- crates/forge-web/src/pages/ref_live.rs | 8 +- crates/forge-web/src/pages/refs.rs | 10 +- crates/forge-web/src/pages/register.rs | 12 +- crates/forge-web/src/pages/releases.rs | 85 ++++++----- crates/forge-web/src/pages/releases_live.rs | 12 +- crates/forge-web/src/pages/repo.rs | 20 ++- .../forge-web/src/pages/repo_collaborators.rs | 27 ++-- crates/forge-web/src/pages/repo_ctx.rs | 9 +- crates/forge-web/src/pages/repo_mirrors.rs | 50 ++++--- crates/forge-web/src/pages/repo_rename.rs | 30 ++-- crates/forge-web/src/pages/repo_scrub.rs | 12 +- crates/forge-web/src/pages/repo_secrets.rs | 22 +-- crates/forge-web/src/pages/repo_security.rs | 15 +- crates/forge-web/src/pages/repo_settings.rs | 128 +++++++++++----- .../forge-web/src/pages/repo_settings_live.rs | 14 +- crates/forge-web/src/pages/repo_side.rs | 5 +- crates/forge-web/src/pages/repo_transfer.rs | 24 +-- crates/forge-web/src/pages/repo_webhooks.rs | 68 +++++---- crates/forge-web/src/pages/review_requests.rs | 18 ++- .../src/pages/settings_appearance.rs | 12 +- crates/forge-web/src/pages/settings_export.rs | 40 +++-- crates/forge-web/src/pages/settings_gpg.rs | 9 +- crates/forge-web/src/pages/settings_keys.rs | 10 +- crates/forge-web/src/pages/settings_live.rs | 8 +- .../src/pages/settings_notifications.rs | 8 +- .../forge-web/src/pages/settings_profile.rs | 28 ++-- .../forge-web/src/pages/settings_security.rs | 30 ++-- .../forge-web/src/pages/settings_sessions.rs | 8 +- crates/forge-web/src/pages/settings_tokens.rs | 9 +- crates/forge-web/src/pages/setup.rs | 7 +- crates/forge-web/src/pages/shell_events.rs | 4 +- crates/forge-web/src/pages/snippet_raw.rs | 4 +- crates/forge-web/src/pages/snippets.rs | 42 +++--- crates/forge-web/src/pages/snippets_live.rs | 8 +- crates/forge-web/src/pages/star.rs | 8 +- crates/forge-web/src/pages/theme_cookie.rs | 4 +- crates/forge-web/src/pages/tree.rs | 26 ++-- crates/forge-web/src/pages/user_prefs.rs | 4 +- crates/forge-web/src/pages/wiki.rs | 92 ++++++------ crates/forge-web/src/pages/wiki_live.rs | 12 +- crates/forge-web/src/raw.rs | 8 +- crates/forge-web/src/test_support.rs | 11 +- crates/forge-web/src/views/commit_line.rs | 3 +- crates/forge-web/src/views/commit_status.rs | 5 +- crates/forge-web/src/views/diff.rs | 28 +++- crates/forge-web/src/views/find.rs | 2 + crates/forge-web/src/views/heatmap.rs | 2 + crates/forge-web/src/views/mod.rs | 45 +++--- crates/forge-web/src/views/parts.rs | 13 +- crates/forge-web/src/views/repo_list.rs | 9 +- crates/forge-web/src/views/review_thread.rs | 9 +- crates/forge-web/src/views/timeline.rs | 2 + 162 files changed, 2031 insertions(+), 1640 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8b532b..547c701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,12 +242,6 @@ version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902" -[[package]] -name = "anymap3" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5dfbc6d8d2675589ccbe4d0fd61df2419075625f8c1a62325e718e2b0049f9" - [[package]] name = "arc-swap" version = "1.9.5" @@ -3396,17 +3390,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "hostname" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" -dependencies = [ - "cfg-if", - "libc", - "windows-link 0.2.1", -] - [[package]] name = "html5ever" version = "0.40.1" @@ -4146,7 +4129,6 @@ dependencies = [ "fastrand", "futures-io", "futures-util", - "hostname", "httpdate", "idna", "mime", @@ -7180,9 +7162,9 @@ checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" [[package]] name = "topcoat" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70b5093d8133b513742b7461a28d374107b8bf9168aa60f4f567ad89acd2ed9e" +checksum = "16bfbdbedee481dc7a9e89ed7c5be0a8fda008d6170fe9012c220590297eb4b9" dependencies = [ "futures-util", "inventory", @@ -7190,13 +7172,14 @@ dependencies = [ "tokio", "tokio-tungstenite", "topcoat-asset", + "topcoat-asset-macro", "topcoat-cookie", "topcoat-core", "topcoat-core-macro", "topcoat-font", "topcoat-font-macro", "topcoat-l10n", - "topcoat-mail", + "topcoat-metadata", "topcoat-router", "topcoat-router-macro", "topcoat-runtime", @@ -7208,9 +7191,9 @@ dependencies = [ [[package]] name = "topcoat-asset" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac70debf9eee62714ce45416eae27b283c3a44a0f9ebcb2ac088fda48b533f3e" +checksum = "14de3c5734f7bb8ffc85ae33baa00e7dafee22978d02ef13e2ce3ad992fb1bc8" dependencies = [ "http", "memchr", @@ -7225,11 +7208,34 @@ dependencies = [ "topcoat-view", ] +[[package]] +name = "topcoat-asset-grammar" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce8fec8374473aa09ec85dd51469aca40ee6175397c4a7e38f7dc22f4798d03" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "topcoat-core-grammar", +] + +[[package]] +name = "topcoat-asset-macro" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d98de54cc49ab5f9d5af639064ed1bb1b562ac170d346280b706cec7a1553d" +dependencies = [ + "quote", + "syn 3.0.10", + "topcoat-asset-grammar", +] + [[package]] name = "topcoat-cookie" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df79aba10192abe21fbd01dfcb46bb04dab5ae64adb4432d9f078eb05f94e6a5" +checksum = "7fa34d585203cb080afce31749310bf5d9f238491636806d875726c7faebe10c" dependencies = [ "cookie", "getrandom 0.2.17", @@ -7242,11 +7248,10 @@ dependencies = [ [[package]] name = "topcoat-core" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffff49b885744cdb89ee158c5d81cc8c619692bd9f4ab3cae92ad1adc0ce612e" +checksum = "121a7616ec29bc5525a4a580554c3d5330ce4314655a13d0d8d10cc1a083fc7a" dependencies = [ - "anymap3", "base64 0.22.1", "elsa", "http", @@ -7258,9 +7263,9 @@ dependencies = [ [[package]] name = "topcoat-core-grammar" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b788a2010234cd29fc050268e52ceb393d2124b20f669a83d8f61a9dbf895bb6" +checksum = "6d2326406a37c4eb212d60bc421589f3b600f50ca440b8e39dbdb7f7d032cb8a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7270,9 +7275,9 @@ dependencies = [ [[package]] name = "topcoat-core-macro" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e3786bf2ee2c8b4f728d3fb53c41f639aa66583788b3135acbd63c11458b25b" +checksum = "020d81b3dfe852b7b5e44bbb2079c6b1346d6dfe50bc267e5d5a05c40bf5d9a4" dependencies = [ "quote", "syn 3.0.10", @@ -7281,9 +7286,9 @@ dependencies = [ [[package]] name = "topcoat-font" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa4656294aac116def1e7633f03117a84b65126c503242793ff4adc78577fb8" +checksum = "5e4382e452ddefff5b03cee1b3c84bcd36783e50afd2fea1e21fc9b41807142e" dependencies = [ "heck", "inventory", @@ -7298,9 +7303,9 @@ dependencies = [ [[package]] name = "topcoat-font-grammar" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b462fae28641a1bb24eab1fa9c473520389ca690331ca53fd6143d5b2746045e" +checksum = "d6159e8e361f19367ddb11de5e5ff9b04f92d91e0c46ef9b1a076404d83fcfe8" dependencies = [ "proc-macro2", "quote", @@ -7311,9 +7316,9 @@ dependencies = [ [[package]] name = "topcoat-font-macro" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40776cd3087aaea5e0c8b597126b1c09dbfb0d69833088d7f3b229305bbbb87f" +checksum = "7e3d3a71216cec0a27497716d4559e34245e61328f6e04fc2a2bac3b80679b31" dependencies = [ "quote", "syn 3.0.10", @@ -7322,10 +7327,11 @@ dependencies = [ [[package]] name = "topcoat-l10n" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34da63b3a5aea3d6c243d9fa8c98ca79b181b985f6a0a042f630672f54d12e9e" +checksum = "d877822424504842f90d9f018dbaa61be2d52071653bc0f0921652ef925fdabd" dependencies = [ + "http", "icu_locale", "icu_locale_core", "topcoat-core", @@ -7333,24 +7339,24 @@ dependencies = [ ] [[package]] -name = "topcoat-mail" -version = "0.11.0" +name = "topcoat-metadata" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a13c10c6399d9eb9b0bde38bd3d947eba56ddfaea99d9a4f971b74b6a651db" +checksum = "bf250ddbaea17bd63c7d6f124ce8f883dee44ece584cfab979ec33a87a030875" dependencies = [ - "lettre", - "thiserror 2.0.21", - "time", + "topcoat-asset", "topcoat-core", + "topcoat-core-macro", "topcoat-router", "topcoat-view", + "topcoat-view-macro", ] [[package]] name = "topcoat-router" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9488065b08f293208b0f1aeb6667d5836b66c12dfced5e330f9a8f1d7f1ca1a" +checksum = "c86534384925992375ac979e9b5af7e4086119803b4586c6ac9bca814e814ed2" dependencies = [ "bytes", "form_urlencoded", @@ -7384,11 +7390,10 @@ dependencies = [ [[package]] name = "topcoat-router-grammar" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3f51fa1a1e538bd34e02f88ebba554ac5931e55c688303a58a8e78123dfb04" +checksum = "0aa0f6bb59f921cdde73395cc526374d8a553d3285c3f4ac8086c40bedc5be3a" dependencies = [ - "heck", "proc-macro2", "quote", "syn 3.0.10", @@ -7397,9 +7402,9 @@ dependencies = [ [[package]] name = "topcoat-router-macro" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c1b56d3bf19d54bddf300d6d57ca754531d7ad5481afca0b2302ac33f5d43af" +checksum = "71ddd5e527cdab30c73293f907e8f40ef16c421484bb7bad107ecd967a6b98c3" dependencies = [ "quote", "syn 3.0.10", @@ -7408,9 +7413,9 @@ dependencies = [ [[package]] name = "topcoat-runtime" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b22136b99694b349a950cd757387a04b080fdb131eecdd51d0511e1a45ebf5" +checksum = "3e8f8651d36f003dd85a6a36ff5e1161b01af1cc5ae5baa38e649bda3605037a" dependencies = [ "futures-util", "pin-project-lite", @@ -7419,6 +7424,7 @@ dependencies = [ "serde_json", "tokio", "topcoat-asset", + "topcoat-asset-macro", "topcoat-core", "topcoat-router", "topcoat-view", @@ -7427,9 +7433,9 @@ dependencies = [ [[package]] name = "topcoat-runtime-grammar" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab93a83c38a045a4f541c2e548d30ba5dfdd3173c18de8b1c7b049709c29db97" +checksum = "1650432fe7adeab5aa815b84245c29c3ea5390a3b4a41d7cc2868e8f60f6277b" dependencies = [ "proc-macro2", "quote", @@ -7443,9 +7449,9 @@ dependencies = [ [[package]] name = "topcoat-runtime-macro" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5acb1db0bdba3c36e4f80f7ef530945779a1b0294b1087e7d877e33005da6283" +checksum = "f4ea7a5b61e948d702a5cb6727c38a3b0c934b630cc003971ca86a9262c16b0c" dependencies = [ "quote", "syn 3.0.10", @@ -7454,9 +7460,9 @@ dependencies = [ [[package]] name = "topcoat-session" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2325c30a484b1b1b6f5012b50bc18994d37c33c6bd2f71be8ff509b591a17457" +checksum = "d705011dbdf07ea9e3f74397f177cf3224a2fa0ff600a2514c11837ef04e1858" dependencies = [ "base64 0.22.1", "getrandom 0.4.3", @@ -7465,15 +7471,14 @@ dependencies = [ "tokio", "topcoat-cookie", "topcoat-core", - "topcoat-router", "web-time", ] [[package]] name = "topcoat-view" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4553b91f30e30c71c2bd95ae8e931a33326c6ffb604663b9d214008f12947c" +checksum = "654e102f97a4c26ba9b7deb72bdac45c8587ced30480b431155a56a935d12e86" dependencies = [ "futures-core", "futures-util", @@ -7487,9 +7492,9 @@ dependencies = [ [[package]] name = "topcoat-view-grammar" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75dd093ffc848370da4cce7670ccdfd4e98eab48e178d5d0da5509f747d85ca6" +checksum = "28e348a794d04565ee00e7899f215c02db9acf0711bb8eefbba2ffa14bc72a5c" dependencies = [ "heck", "proc-macro2", @@ -7501,9 +7506,9 @@ dependencies = [ [[package]] name = "topcoat-view-macro" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffa1688d165704f08d58c03710453d0d39553292bea61b18be7959a996c3e39b" +checksum = "eed1edf71f2fe9f5edf9dcfa2ec3e55b9bae443c015497f80347f82cf6b7af8d" dependencies = [ "quote", "syn 3.0.10", diff --git a/Cargo.toml b/Cargo.toml index f94ab1f..9a1f1ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,7 @@ multer = "3.1.0" lettre = { version = "0.11.24", default-features = false, features = ["smtp-transport", "builder", "tokio1-rustls", "ring", "webpki-roots", "pool"] } # web framework -topcoat = { version = "0.11.0", default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "multipart"] } +topcoat = { version = "0.12.1", default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "multipart"] } # ssh server russh = { version = "0.65.4", default-features = false, features = ["flate2", "aws-lc-rs"] } diff --git a/crates/forge-core/src/store/migrate.rs b/crates/forge-core/src/store/migrate.rs index c4a5751..f124de9 100644 --- a/crates/forge-core/src/store/migrate.rs +++ b/crates/forge-core/src/store/migrate.rs @@ -117,8 +117,14 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ include_str!("../../migrations/0070_pull_viewed_files.sql"), ), (71, include_str!("../../migrations/0071_ci_job_steps.sql")), - (72, include_str!("../../migrations/0072_ember_anvil_default.sql")), - (73, include_str!("../../migrations/0073_sage_ink_default.sql")), + ( + 72, + include_str!("../../migrations/0072_ember_anvil_default.sql"), + ), + ( + 73, + include_str!("../../migrations/0073_sage_ink_default.sql"), + ), ]; /// The highest migration version this binary knows about. diff --git a/crates/forge-core/src/tz.rs b/crates/forge-core/src/tz.rs index 06f8484..68a5508 100644 --- a/crates/forge-core/src/tz.rs +++ b/crates/forge-core/src/tz.rs @@ -23,7 +23,11 @@ pub fn local_date(ts: Timestamp, tz: &str) -> civil::Date { /// it. `None` at the edge of the range jiff can represent. Unknown zones fall back to UTC. pub fn day_span(date: civil::Date, tz: &str) -> Option<(i64, i64)> { let zone = zone_or_utc(tz); - let start = date.at(0, 0, 0, 0).to_zoned_datetime(zone.clone()).ok()?.timestamp(); + let start = date + .at(0, 0, 0, 0) + .to_zoned_datetime(zone.clone()) + .ok()? + .timestamp(); let next = date .tomorrow() .ok()? diff --git a/crates/forge-e2e/tests/e2e/browse_e2e.rs b/crates/forge-e2e/tests/e2e/browse_e2e.rs index 71091f5..3e30798 100644 --- a/crates/forge-e2e/tests/e2e/browse_e2e.rs +++ b/crates/forge-e2e/tests/e2e/browse_e2e.rs @@ -127,7 +127,11 @@ fn element_texts(body: &str, selector: &str) -> Vec { /// Checks the latest commit in a repo page's head line: its short sha linking to the commit, no /// subject, and the commit count label. fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &str) { - assert_eq!(element_texts(body, ".head-sub").len(), 1, "{what}: one head line"); + assert_eq!( + element_texts(body, ".head-sub").len(), + 1, + "{what}: one head line" + ); let shas = element_texts(body, ".head-sub a.mono"); assert_eq!(shas.len(), 1, "{what}: the head line must show the sha"); assert_eq!(shas[0].trim(), &oid[..7], "{what}: short sha"); diff --git a/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs b/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs index f74024d..d5630d5 100644 --- a/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs +++ b/crates/forge-e2e/tests/e2e/community_i18n_e2e.rs @@ -50,10 +50,7 @@ async fn snippets_page_follows_the_browser_language() { assert_eq!(turkish.status().as_u16(), 200); let body = turkish.text().await.expect("read body"); assert!(body.contains("Parçacıklar"), - "Turkish heading" - ); + assert!(body.contains("

Parçacıklar

"), "Turkish heading"); assert!( body.contains("Gösterilecek parçacık yok."), "Turkish empty state" @@ -67,9 +64,6 @@ async fn snippets_page_follows_the_browser_language() { .await .expect("GET /snippets (en)"); let body = english.text().await.expect("read body"); - assert!( - body.contains("

Snippets

"), - "English heading" - ); + assert!(body.contains("

Snippets

"), "English heading"); assert!(body.contains("No snippets to show."), "English empty state"); } diff --git a/crates/forge-e2e/tests/e2e/pulls_e2e.rs b/crates/forge-e2e/tests/e2e/pulls_e2e.rs index c200645..d4e9d4e 100644 --- a/crates/forge-e2e/tests/e2e/pulls_e2e.rs +++ b/crates/forge-e2e/tests/e2e/pulls_e2e.rs @@ -23,7 +23,8 @@ const REPO_PATH: &str = "/tahinli/r"; /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`. fn state_badge(body: &str) -> String { let doc = scraper::Html::parse_document(body); - let selector = scraper::Selector::parse(".head-sub > .badge, .head-sub > .issue-badge").expect("selector"); + let selector = + scraper::Selector::parse(".head-sub > .badge, .head-sub > .issue-badge").expect("selector"); doc.select(&selector) .next() .map(|el| el.text().collect::().trim().to_owned()) diff --git a/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs index c865df6..d3dc02e 100644 --- a/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs @@ -388,7 +388,9 @@ async fn repo_rename_end_to_end() { 200, "repo unchanged until accepted" ); - let offered = http.get("/bob/newpub/settings?section=danger", Some(&bob)).await; + let offered = http + .get("/bob/newpub/settings?section=danger", Some(&bob)) + .await; assert!(offered.body.contains("Pending transfer to carol")); let inbox = http.get("/notifications", Some(&carol)).await; let accept_action = form_action(&inbox.body, "/accept"); diff --git a/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs index 3a0bf8e..7642592 100644 --- a/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs @@ -249,7 +249,10 @@ async fn repo_settings_end_to_end() { // The home page is the signed-in viewer's own page, not a redirect. let home = http.get("/", Some(&bob)).await; assert_eq!(home.status, 200, "home page for a signed-in viewer"); - assert!(home.body.contains("Your repositories"), "home lists their repositories"); + assert!( + home.body.contains("Your repositories"), + "home lists their repositories" + ); // An admin who does not own the repo can delete it. let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await; @@ -523,7 +526,11 @@ async fn branch_protection_end_to_end() { let updated = http .post_form( "/bob/app/settings/branches", - &[("csrf", &owner_csrf), ("pattern", "main"), ("existing", "1")], + &[ + ("csrf", &owner_csrf), + ("pattern", "main"), + ("existing", "1"), + ], Some(&bob), ) .await; @@ -538,7 +545,10 @@ async fn branch_protection_end_to_end() { ) .await; assert_eq!(duplicate.status, 200, "duplicate rule re-renders the page"); - assert!(duplicate.body.contains("already exists"), "duplicate rule names the clash"); + assert!( + duplicate.body.contains("already exists"), + "duplicate rule names the clash" + ); let page = http .get("/bob/app/settings?section=branches", Some(&bob)) .await; @@ -864,7 +874,10 @@ async fn general_settings_end_to_end() { page.body .contains("href=\"/bob/gen/settings/collaborators\"") ); - assert!(page.body.contains("href=\"/bob/gen/settings?section=danger\"")); + assert!( + page.body + .contains("href=\"/bob/gen/settings?section=danger\"") + ); // Description: control characters are stripped and it shows on the repo header. let csrf = csrf_for(&http, &bob).await; diff --git a/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs index f9242db..6457e4d 100644 --- a/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs @@ -148,14 +148,18 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() { offered.header(LOCATION).as_deref(), Some("/bob/priv/settings?section=danger") ); - let status = http.get("/bob/priv/settings?section=danger", Some(&bob)).await; + let status = http + .get("/bob/priv/settings?section=danger", Some(&bob)) + .await; assert!(status.body.contains("Pending transfer to carol")); // Carol cannot read the private repo, yet the inbox offers her the actions. assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 404); let declined = act_from(&http, &carol, "/notifications", "/decline").await; assert_eq!(declined.status, 303, "decline: {}", declined.body); assert_eq!(declined.header(LOCATION).as_deref(), Some("/notifications")); - let after = http.get("/bob/priv/settings?section=danger", Some(&bob)).await; + let after = http + .get("/bob/priv/settings?section=danger", Some(&bob)) + .await; assert!(!after.body.contains("Pending transfer")); assert_eq!(http.get("/bob/priv", Some(&bob)).await.status, 200); @@ -167,7 +171,9 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() { cancelled.header(LOCATION).as_deref(), Some("/bob/priv/settings?section=danger") ); - let after = http.get("/bob/priv/settings?section=danger", Some(&bob)).await; + let after = http + .get("/bob/priv/settings?section=danger", Some(&bob)) + .await; assert!(!after.body.contains("Pending transfer")); // A transfer to an org: plain members get no accept form, owners do. diff --git a/crates/forge-web-base/src/accent.rs b/crates/forge-web-base/src/accent.rs index f2ca432..1c9e017 100644 --- a/crates/forge-web-base/src/accent.rs +++ b/crates/forge-web-base/src/accent.rs @@ -327,7 +327,15 @@ mod tests { ] { assert!(!is_offered(id), "{id}"); } - for id in ["stone", "mist", "fern", "graphite", "dune", "slate-blue", "spark"] { + for id in [ + "stone", + "mist", + "fern", + "graphite", + "dune", + "slate-blue", + "spark", + ] { assert!(!is_offered_base(id), "{id}"); } } diff --git a/crates/forge-web-base/src/compression.rs b/crates/forge-web-base/src/compression.rs index b1461f6..00be97a 100644 --- a/crates/forge-web-base/src/compression.rs +++ b/crates/forge-web-base/src/compression.rs @@ -200,7 +200,7 @@ mod tests { )) .route(RouteFn::new(Method::GET, "/tahinli/demo/blob.bin", binary)) .layer(TowerLayer::new(ResponseCompression)) - .compression(Compression::off()) + .with(Compression::disable()) .build() } diff --git a/crates/forge-web-base/src/i18n/admin.rs b/crates/forge-web-base/src/i18n/admin.rs index e0bfcc7..f59d9e1 100644 --- a/crates/forge-web-base/src/i18n/admin.rs +++ b/crates/forge-web-base/src/i18n/admin.rs @@ -368,12 +368,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { (RunnerEnabledNotice, Tr) => "Çalıştırıcı etkinleştirildi.", (Runners, En) => "Runners", (Runners, Tr) => "Çalıştırıcılar", - (ScheduledBackupsOff, En) => { - "Scheduled backups are off." - } - (ScheduledBackupsOff, Tr) => { - "Zamanlanmış yedeklemeler kapalı." - } + (ScheduledBackupsOff, En) => "Scheduled backups are off.", + (ScheduledBackupsOff, Tr) => "Zamanlanmış yedeklemeler kapalı.", (SecurityLogTitle, En) => "Security log", (SecurityLogTitle, Tr) => "Güvenlik günlüğü", (SecurityNone, En) => "None (plain text)", diff --git a/crates/forge-web-base/src/i18n/issues.rs b/crates/forge-web-base/src/i18n/issues.rs index 9abf7f3..847114f 100644 --- a/crates/forge-web-base/src/i18n/issues.rs +++ b/crates/forge-web-base/src/i18n/issues.rs @@ -673,7 +673,9 @@ pub fn reaction_more(lang: Lang, names: &str, more: usize) -> String { /// Several label additions in one run: "added labels a, b and c". `names` holds at least two. pub fn event_labels_added(lang: Lang, names: &[String]) -> String { - let (last, rest) = names.split_last().map_or(("", &[][..]), |(last, rest)| (last.as_str(), rest)); + let (last, rest) = names + .split_last() + .map_or(("", &[][..]), |(last, rest)| (last.as_str(), rest)); let list = match lang { Lang::En => match rest.is_empty() { true => last.to_owned(), diff --git a/crates/forge-web-base/src/render/markdown.rs b/crates/forge-web-base/src/render/markdown.rs index bb33e88..e3ee145 100644 --- a/crates/forge-web-base/src/render/markdown.rs +++ b/crates/forge-web-base/src/render/markdown.rs @@ -390,12 +390,18 @@ fn text_with_links<'a>( Some(n) => new_node( arena, sourcepos, - NodeValue::Link(Box::new(NodeLink::new(format!("{issues_base}/{n}"), ISSUE_REF_TITLE.to_string()))), + NodeValue::Link(Box::new(NodeLink::new( + format!("{issues_base}/{n}"), + ISSUE_REF_TITLE.to_string(), + ))), ), None => new_node( arena, sourcepos, - NodeValue::Link(Box::new(NodeLink::new(format!("/{}", &label[1..]), USER_MENTION_TITLE.to_string()))), + NodeValue::Link(Box::new(NodeLink::new( + format!("/{}", &label[1..]), + USER_MENTION_TITLE.to_string(), + ))), ), }; link.append(new_node( diff --git a/crates/forge-web/src/api/gitea.rs b/crates/forge-web/src/api/gitea.rs index a59070c..0655537 100644 --- a/crates/forge-web/src/api/gitea.rs +++ b/crates/forge-web/src/api/gitea.rs @@ -25,7 +25,7 @@ use forge_core::{Action, Repo as CoreRepo, User, Visibility}; use http::HeaderMap; use http::header::{AUTHORIZATION, HeaderName, HeaderValue}; use serde_json::{Value, json}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::{headers, uri}; use topcoat::router::response::Response; use topcoat::router::{StatusCode, path_param, route}; @@ -108,7 +108,7 @@ fn effective_headers(cx: &Cx) -> HeaderMap { /// Who is asking, and the raw token they used (for the clone URL of a private repo). async fn caller(cx: &Cx) -> Result<(Option, Option), Refusal> { - let state = app_context::(cx); + let state = context::(cx); let map = effective_headers(cx); let actor = api::authenticate(state, client_ip(cx), &map).await?; let token = api::presented_token(&map).flatten(); @@ -122,16 +122,9 @@ struct Ctx { } async fn read_ctx(cx: &Cx) -> Result { - let state = app_context::(cx); + let state = context::(cx); let (actor, token) = caller(cx).await?; - let repo = api::load_repo( - state, - actor.as_ref(), - path_param::(cx), - path_param::(cx), - Action::Read, - ) - .await?; + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?; Ok(Ctx { repo, token: actor.and(token), @@ -178,7 +171,7 @@ pub fn slice(items: Vec, pg: &Paging) -> (Vec, usize) { pub fn page_response(cx: &Cx, items: Vec, total: usize, pg: &Paging) -> Response { let mut res = api::json(StatusCode::OK, &Value::Array(items)); let last = total.div_ceil(pg.limit.max(1)).max(1); - let state = app_context::(cx); + let state = context::(cx); let base = state.config.base_url.trim_end_matches('/'); let mut rest = String::new(); if let Some(query) = uri(cx).query() { @@ -230,7 +223,7 @@ fn internal(e: impl std::fmt::Display) -> Refusal { } #[route(GET "/api/v1/version")] -async fn version_route(_cx: &Cx) -> topcoat::Result { +async fn version_route(cx: &Cx) -> topcoat::Result { Ok(api::json( StatusCode::OK, &json!({ "version": GITEA_VERSION }), @@ -238,7 +231,7 @@ async fn version_route(_cx: &Cx) -> topcoat::Result { } #[route(GET "/api/v1/settings/api")] -async fn settings_api(_cx: &Cx) -> topcoat::Result { +async fn settings_api(cx: &Cx) -> topcoat::Result { Ok(api::json( StatusCode::OK, &json!({ @@ -302,7 +295,7 @@ pub async fn repo_json( #[route(GET "/api/v1/repos/{owner}/{repo}")] async fn get_repo(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), @@ -336,7 +329,7 @@ fn label_json(base: &str, repo: &CoreRepo, label: &Label) -> Value { #[route(GET "/api/v1/repos/{owner}/{repo}/labels")] async fn list_labels_route(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), @@ -389,7 +382,7 @@ fn state_filter(cx: &Cx) -> Result, Refusal> { #[route(GET "/api/v1/repos/{owner}/{repo}/milestones")] async fn list_milestones_route(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), @@ -495,7 +488,7 @@ fn filter_of(cx: &Cx, pg: &Paging) -> Result { #[route(GET "/api/v1/repos/{owner}/{repo}/issues")] async fn list_issues_route(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), @@ -572,13 +565,13 @@ fn comment_json( #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/comments")] async fn issue_comments(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), }; let result: Result = async { - let issue = issue_row(state, &ctx.repo, path_param::(cx)).await?; + let issue = issue_row(state, &ctx.repo, index(cx)).await?; let all = state .store .list_comments(&issue.id) @@ -634,13 +627,13 @@ async fn reactions_json( #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/reactions")] async fn issue_reactions(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), }; let result: Result = async { - let issue = issue_row(state, &ctx.repo, path_param::(cx)).await?; + let issue = issue_row(state, &ctx.repo, index(cx)).await?; let all = reactions_json( state, &ctx, @@ -659,15 +652,13 @@ async fn issue_reactions(cx: &Cx) -> topcoat::Result { #[route(GET "/api/v1/repos/{owner}/{repo}/issues/comments/{id}/reactions")] async fn comment_reactions(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), }; let result: Result = async { - let id: i64 = path_param::(cx) - .parse() - .map_err(|_| bad("invalid comment id"))?; + let id: i64 = id(cx).parse().map_err(|_| bad("invalid comment id"))?; let (number, position) = split_comment_id(id).ok_or_else(|| not_found("comment not found"))?; let issue = issue_row(state, &ctx.repo, &number.to_string()).await?; @@ -803,7 +794,7 @@ async fn pull_json( #[route(GET "/api/v1/repos/{owner}/{repo}/pulls")] async fn list_pulls_route(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), @@ -893,13 +884,13 @@ async fn review_comments(state: &AppState, issue_id: &str) -> Result topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), }; let result: Result = async { - let issue = pull_issue(state, &ctx.repo, path_param::(cx)).await?; + let issue = pull_issue(state, &ctx.repo, index(cx)).await?; let reviews = state .store .list_reviews(&issue.id) @@ -967,14 +958,14 @@ fn review_comment_json(ctx: &Ctx, number: i64, c: &ReviewComment) -> Value { #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews/{review_id}/comments")] async fn pull_review_comments(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let ctx = match read_ctx(cx).await { Ok(ctx) => ctx, Err(res) => return Ok(*res), }; let result: Result = async { - let issue = pull_issue(state, &ctx.repo, path_param::(cx)).await?; - let raw = path_param::(cx); + let issue = pull_issue(state, &ctx.repo, index(cx)).await?; + let raw = review_id(cx); let reviews = state .store .list_reviews(&issue.id) diff --git a/crates/forge-web/src/api/packages.rs b/crates/forge-web/src/api/packages.rs index 319d99f..3a42179 100644 --- a/crates/forge-web/src/api/packages.rs +++ b/crates/forge-web/src/api/packages.rs @@ -13,7 +13,7 @@ use http::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue}; use http_body::Frame; use http_body_util::StreamBody; use serde_json::{Value, json}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, StatusCode, path_param, route}; @@ -33,7 +33,7 @@ path_param!(version); /// The caller of a registry request. Reads with a token that lacks the scope are served as /// anonymous, so a token made for another purpose cannot break a public install. Writes refuse. async fn caller(cx: &Cx, scope_required: bool) -> Result, Refusal> { - let state = app_context::(cx); + let state = context::(cx); let normalized = bare_token_as_bearer(headers(cx)); let (user, token_id, scopes) = match api::authenticate_token(state, client_ip(cx), &normalized).await { @@ -120,8 +120,8 @@ fn text(body: String) -> Response { /// Loads the registry owner named in the path, as the caller may see it. A missing owner is 404. async fn owner_of(cx: &Cx) -> Result { - let state = app_context::(cx); - match package_ops::owner_named(state, path_param::(cx)).await { + let state = context::(cx); + match package_ops::owner_named(state, owner(cx)).await { Ok(Some(found)) => Ok(found), Ok(_) => Err(Box::new(failure(PackageError::NotFound))), Err(e) => Err(Box::new(failure(e))), @@ -130,7 +130,7 @@ async fn owner_of(cx: &Cx) -> Result { #[route(GET "/api/packages/{owner}/cargo/config.json")] async fn config(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if let Err(res) = caller(cx, false).await { return Ok(*res); } @@ -164,7 +164,7 @@ async fn index_long(cx: &Cx) -> topcoat::Result { } async fn index_response(cx: &Cx) -> Response { - let state = app_context::(cx); + let state = context::(cx); let actor = match caller(cx, false).await { Ok(actor) => actor, Err(res) => return *res, @@ -173,13 +173,11 @@ async fn index_response(cx: &Cx) -> Response { Ok(owner) => owner, Err(res) => return *res, }; - let package = - match package_ops::readable_package(state, actor.as_ref(), &owner, path_param::(cx)) - .await - { - Ok(package) => package, - Err(e) => return failure(e), - }; + let package = match package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await + { + Ok(package) => package, + Err(e) => return failure(e), + }; match package_ops::index_file(state, &package).await { Ok(body) => text(body), Err(e) => failure(e), @@ -189,7 +187,7 @@ async fn index_response(cx: &Cx) -> Response { /// The `.crate` file of one version, streamed from the blob store. #[route(GET "/api/packages/{owner}/cargo/download/{name}/{version}")] async fn download(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match caller(cx, false).await { Ok(actor) => actor, Err(res) => return Ok(*res), @@ -198,18 +196,11 @@ async fn download(cx: &Cx) -> topcoat::Result { Ok(owner) => owner, Err(res) => return Ok(*res), }; - let read = match package_ops::download( - state, - actor.as_ref(), - &owner, - path_param::(cx), - path_param::(cx), - ) - .await - { - Ok(read) => read, - Err(e) => return Ok(failure(e)), - }; + let read = + match package_ops::download(state, actor.as_ref(), &owner, name(cx), version(cx)).await { + Ok(read) => read, + Err(e) => return Ok(failure(e)), + }; let chunks = read.stream.map(|chunk| chunk.map(Frame::data)); let mut res = Response::new(Body::new(StreamBody::new(chunks))); *res.status_mut() = StatusCode::OK; @@ -226,7 +217,7 @@ async fn download(cx: &Cx) -> topcoat::Result { /// length-prefixed `.crate`. It is read whole, up to the publish limit. #[route(PUT "/api/packages/{owner}/cargo/api/v1/crates/new")] async fn publish(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match caller(cx, true).await { Ok(Some(actor)) => actor, Ok(None) => { @@ -271,7 +262,7 @@ async fn unyank(cx: &Cx) -> topcoat::Result { } async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match caller(cx, true).await { Ok(Some(actor)) => actor, Ok(None) => { @@ -286,16 +277,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result { Ok(owner) => owner, Err(res) => return Ok(*res), }; - match package_ops::set_yanked( - state, - &owner, - &actor, - path_param::(cx), - path_param::(cx), - yanked, - ) - .await - { + match package_ops::set_yanked(state, &owner, &actor, name(cx), version(cx), yanked).await { Ok(()) => Ok(api::json(StatusCode::OK, &json!({ "ok": true }))), Err(e) => Ok(failure(e)), } @@ -305,7 +287,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result { /// an org, its owners. Read-only: adding or removing owners is done in the forge. #[route(GET "/api/packages/{owner}/cargo/api/v1/crates/{name}/owners")] async fn owners(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match caller(cx, false).await { Ok(actor) => actor, Err(res) => return Ok(*res), @@ -314,9 +296,7 @@ async fn owners(cx: &Cx) -> topcoat::Result { Ok(owner) => owner, Err(res) => return Ok(*res), }; - if let Err(e) = - package_ops::readable_package(state, actor.as_ref(), &owner, path_param::(cx)).await - { + if let Err(e) = package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await { return Ok(failure(e)); } let people: Vec = if owner.is_org() { diff --git a/crates/forge-web/src/api/releases.rs b/crates/forge-web/src/api/releases.rs index de69e36..ea72a1b 100644 --- a/crates/forge-web/src/api/releases.rs +++ b/crates/forge-web/src/api/releases.rs @@ -13,7 +13,7 @@ use futures_util::StreamExt; use http::header::CONTENT_TYPE; use serde::Deserialize; use serde_json::{Value, json}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, StatusCode, path_param, route}; @@ -55,7 +55,7 @@ struct PatchBody { #[route(GET "/api/v1/repos/{owner}/{repo}/releases")] async fn list_releases(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, can_write) = match read_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), @@ -82,17 +82,17 @@ async fn list_releases(cx: &Cx) -> topcoat::Result { /// Gitea's `GET .../releases/{id}/assets/{attachment_id}`: one asset of one release. #[route(GET "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] async fn get_asset(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, can_write) = match read_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let release = match release_in_repo(state, &repo, path_param::(cx)).await { + let release = match release_in_repo(state, &repo, id(cx)).await { Ok(release) if can_write || !release.draft => release, Ok(_) => return Ok(not_found()), Err(res) => return Ok(*res), }; - let wanted = path_param::(cx); + let wanted = asset(cx); let assets = match state.store.list_release_assets(&release.id).await { Ok(assets) => assets, Err(e) => return Ok(*api::internal(e)), @@ -112,12 +112,12 @@ async fn get_asset(cx: &Cx) -> topcoat::Result { #[route(GET "/api/v1/repos/{owner}/{repo}/releases/tags/{tag}")] async fn get_release_by_tag(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, can_write) = match read_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let tag_name = path_param::(cx); + let tag_name = tag(cx); let release = match state.store.release_by_tag(&repo.id, tag_name).await { Ok(Some(release)) if can_write || !release.draft => release, Ok(_) => return Ok(not_found()), @@ -131,7 +131,7 @@ async fn get_release_by_tag(cx: &Cx) -> topcoat::Result { #[route(POST "/api/v1/repos/{owner}/{repo}/releases")] async fn create_release(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, user) = match write_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), @@ -176,12 +176,12 @@ async fn create_release(cx: &Cx, body: Body) -> topcoat::Result { #[route(PATCH "/api/v1/repos/{owner}/{repo}/releases/{id}")] async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, user) = match write_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let release = match release_in_repo(state, &repo, path_param::(cx)).await { + let release = match release_in_repo(state, &repo, id(cx)).await { Ok(release) => release, Err(res) => return Ok(*res), }; @@ -218,12 +218,12 @@ async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result { #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}")] async fn delete_release(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, user) = match write_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let release = match release_in_repo(state, &repo, path_param::(cx)).await { + let release = match release_in_repo(state, &repo, id(cx)).await { Ok(release) => release, Err(res) => return Ok(*res), }; @@ -236,12 +236,12 @@ async fn delete_release(cx: &Cx) -> topcoat::Result { /// Streams the raw request body into an asset. `201` for a new name, `200` when it replaces one. #[route(PUT "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, user) = match write_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let release = match release_in_repo(state, &repo, path_param::(cx)).await { + let release = match release_in_repo(state, &repo, id(cx)).await { Ok(release) => release, Err(res) => return Ok(*res), }; @@ -264,7 +264,7 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result { &repo, &release, &user, - path_param::(cx), + asset(cx), content_type.as_deref(), stream, max_bytes, @@ -287,17 +287,17 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result { #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] async fn delete_asset(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let (repo, _user) = match write_context(cx).await { Ok(found) => found, Err(res) => return Ok(*res), }; - let release = match release_in_repo(state, &repo, path_param::(cx)).await { + let release = match release_in_repo(state, &repo, id(cx)).await { Ok(release) => release, Err(res) => return Ok(*res), }; // The asset may be named by its forge id or by the integer shown as `id` in the JSON. - let mut asset = path_param::(cx).to_owned(); + let mut asset = asset(cx).to_owned(); if gitea::is_numeric(&asset) && let Ok(assets) = state.store.list_release_assets(&release.id).await && let Some(found) = assets @@ -318,21 +318,14 @@ const MAX_JSON_BYTES: usize = 64 * 1024; /// Authenticates an optional caller and loads the repo for reading. Also reports whether the /// caller may write, which decides whether drafts are visible. async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> { - let state = app_context::(cx); + let state = context::(cx); let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?; - let repo = api::load_repo( - state, - actor.as_ref(), - path_param::(cx), - path_param::(cx), - Action::Read, - ) - .await?; + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?; let can_write = api::load_repo( state, actor.as_ref(), - path_param::(cx), - path_param::(cx), + owner(cx), + self::repo(cx), Action::Write, ) .await @@ -342,16 +335,9 @@ async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> { /// Authenticates a required caller with write access and loads the repo. async fn write_context(cx: &Cx) -> Result<(CoreRepo, User), Refusal> { - let state = app_context::(cx); + let state = context::(cx); let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?; - let repo = api::load_repo( - state, - actor.as_ref(), - path_param::(cx), - path_param::(cx), - Action::Write, - ) - .await?; + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await?; match actor { Some(user) => Ok((repo, user)), None => Err(Box::new(api::unauthorized())), diff --git a/crates/forge-web/src/api/statuses.rs b/crates/forge-web/src/api/statuses.rs index 1d36d5e..ede86c7 100644 --- a/crates/forge-web/src/api/statuses.rs +++ b/crates/forge-web/src/api/statuses.rs @@ -8,7 +8,7 @@ use forge_core::Action; use forge_core::store::commit_status::{CommitStatus, DEFAULT_CONTEXT, StatusState, combine}; use serde::Deserialize; use serde_json::{Value, json}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, StatusCode, path_param, route}; @@ -35,19 +35,12 @@ struct ReportBody { #[route(POST "/api/v1/repos/{owner}/{repo}/statuses/{sha}")] async fn report_status(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await { Ok(actor) => actor, Err(res) => return Ok(*res), }; - let repo = match api::load_repo( - state, - actor.as_ref(), - path_param::(cx), - path_param::(cx), - Action::Write, - ) - .await + let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await { Ok(repo) => repo, Err(res) => return Ok(*res), @@ -55,7 +48,7 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result { let Some(user) = actor else { return Ok(api::unauthorized()); }; - let Some(sha) = api::normalize_sha(path_param::(cx)) else { + let Some(sha) = api::normalize_sha(sha(cx)) else { return Ok(not_a_full_sha()); }; let bytes = match api::read_body(body, MAX_BODY_BYTES).await { @@ -117,24 +110,17 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result { #[route(GET "/api/v1/repos/{owner}/{repo}/commits/{sha}/statuses")] async fn list_statuses(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await { Ok(actor) => actor, Err(res) => return Ok(*res), }; - let repo = match api::load_repo( - state, - actor.as_ref(), - path_param::(cx), - path_param::(cx), - Action::Read, - ) - .await + let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await { Ok(repo) => repo, Err(res) => return Ok(*res), }; - let Some(sha) = api::normalize_sha(path_param::(cx)) else { + let Some(sha) = api::normalize_sha(sha(cx)) else { return Ok(not_a_full_sha()); }; let path = match api::repo_dir(state, &repo) { diff --git a/crates/forge-web/src/auth.rs b/crates/forge-web/src/auth.rs index dd4e618..13f4bf4 100644 --- a/crates/forge-web/src/auth.rs +++ b/crates/forge-web/src/auth.rs @@ -13,7 +13,7 @@ use forge_core::token::{constant_time_eq, hash_token}; use forge_core::{Session, Store, User, secret, totp}; use tokio::sync::Semaphore; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; use topcoat::router::error::{forbidden, see_other}; use topcoat::router::request::{headers, uri}; @@ -54,7 +54,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result let Some(cookie) = session_jar(cx).get(SESSION_COOKIE) else { return Ok(None); }; - let store = &app_context::(cx).store; + let store = &context::(cx).store; let Some(session) = store .session_by_token_hash(&hash_token(cookie.value())) .await? @@ -76,7 +76,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result /// Creates a session for `user` and sets the session cookie on the response. pub async fn login(cx: &Cx, user: &User) -> forge_core::Result { - let store = &app_context::(cx).store; + let store = &context::(cx).store; let token = new_session_token(); let addr = client_addr(cx).to_string(); let session = store @@ -90,7 +90,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result { ) .await?; // A new sign-in shows up in the user's session list in their other open tabs. - app_context::(cx) + context::(cx) .live .bump(&crate::live::Topic::Account(user.id.clone())); let max_age = time::Duration::seconds(i64::try_from(SESSION_TTL.as_secs()).unwrap_or(i64::MAX)); @@ -108,7 +108,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result { /// Deletes the session row and clears the cookie. pub async fn logout(cx: &Cx, session: &Session) -> forge_core::Result<()> { - let state = app_context::(cx); + let state = context::(cx); state.store.delete_session(&session.id).await?; // The user's other tabs may show this session (a page that now leaves for the login page). crate::pages::settings_live::bump_account(state, &session.user_id); diff --git a/crates/forge-web/src/boot.rs b/crates/forge-web/src/boot.rs index 6f396e5..45dcc8d 100644 --- a/crates/forge-web/src/boot.rs +++ b/crates/forge-web/src/boot.rs @@ -18,7 +18,7 @@ use tokio::net::{TcpListener, UnixListener}; use tokio::signal::unix::{SignalKind, signal}; use tokio::sync::Notify; use tokio::sync::watch; -use topcoat::cookie::RouterBuilderCookieExt; +use topcoat::cookie::CookieLayer; use topcoat::router::tower::TowerLayer; use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt, RouterService}; @@ -169,11 +169,9 @@ pub async fn serve( // `ResponseCompression` compresses text responses only and skips git, LFS, raw and archive paths. let public: Router = Router::builder() .discover() - .app_context(state.clone()) + .with(state.clone()) .layer(crate::pages::settings_live::AccountWriteLayer) - .cookies() - .layer(crate::pages::settings_profile::avatar_body_limit()) - .layer(crate::pages::settings_profile::org_avatar_body_limit()) + .layer(CookieLayer::new()) .layer(crate::pages::repo_ctx::RepoMovedLayer) .layer(crate::pages::pull_live::PullWriteLayer) .layer(crate::pages::discussion_live::DiscussionWriteLayer) @@ -181,7 +179,7 @@ pub async fn serve( .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer) .layer(crate::pages::not_found_page::NotFoundLayer) .layer(TowerLayer::new(crate::compression::ResponseCompression)) - .compression(Compression::off()) + .with(Compression::disable()) .build(); let internal_router = internal::router(state.clone()); let raw_router = raw::router(state.clone()); diff --git a/crates/forge-web/src/ci/api.rs b/crates/forge-web/src/ci/api.rs index d1f98b6..3363393 100644 --- a/crates/forge-web/src/ci/api.rs +++ b/crates/forge-web/src/ci/api.rs @@ -22,7 +22,7 @@ use futures_util::StreamExt; use http::header::HeaderValue; use serde_json::json; use std::collections::BTreeMap; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route}; @@ -146,7 +146,7 @@ pub fn valid_artifact_name(name: &str) -> bool { #[route(POST "/api/v1/ci/runners/register")] async fn register(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let request: RegisterRequest = match json_body(body).await { Ok(request) => request, Err(res) => return Ok(*res), @@ -189,7 +189,7 @@ async fn register(cx: &Cx, body: Body) -> topcoat::Result { #[route(POST "/api/v1/ci/runners/claim")] async fn claim(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); // The labels in the request are ignored: the labels stored at registration are used, plus the // arch and OS the runner reports, so `runs_on = ["aarch64"]` needs no admin to type a label. let mut runner = match runner_from(state, headers(cx)).await { @@ -330,7 +330,7 @@ async fn set_restart_header(state: &AppState, runner_id: &str, res: &mut Respons /// number the forge wants for this boot id, so the runner resends what was lost. #[route(POST "/api/v1/ci/runners/log")] async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let runner = match runner_from(state, headers(cx)).await { Ok(runner) => runner, Err(res) => return Ok(*res), @@ -364,7 +364,7 @@ async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result { /// page. Answers 204 with no body. #[route(POST "/api/v1/ci/runners/metrics")] async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let runner = match runner_from(state, headers(cx)).await { Ok(runner) => runner, Err(res) => return Ok(*res), @@ -397,7 +397,7 @@ async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result { /// starts, applies them to its in-memory config, then reports its effective config here. #[route(GET "/api/v1/ci/runners/config")] async fn runner_config_get(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let runner = match runner_from(state, headers(cx)).await { Ok(runner) => runner, Err(res) => return Ok(*res), @@ -407,7 +407,7 @@ async fn runner_config_get(cx: &Cx) -> topcoat::Result { #[route(PUT "/api/v1/ci/runners/config")] async fn runner_config_put(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let runner = match runner_from(state, headers(cx)).await { Ok(runner) => runner, Err(res) => return Ok(*res), @@ -557,7 +557,7 @@ fn idle_text(skips: &QueueSkips, free: Option) -> Option { /// The running binary, for a runner that updates itself. 404 unless self-update is enabled. #[route(GET "/api/v1/ci/runners/binary")] async fn runner_binary(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if let Err(res) = runner_from(state, headers(cx)).await { return Ok(*res); } @@ -768,8 +768,8 @@ async fn is_fork_run(state: &AppState, run: &CiRun) -> Result { #[route(POST "/api/v1/ci/jobs/{job_id}/heartbeat")] async fn heartbeat(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); - let job = match job_from(state, headers(cx), path_param::(cx)).await { + let state = context::(cx); + let job = match job_from(state, headers(cx), job_id(cx)).await { Ok(job) => job, Err(res) => return Ok(*res), }; @@ -845,9 +845,9 @@ enum LogWrite { #[route(POST "/api/v1/ci/jobs/{job_id}/logs")] async fn append_log(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let job = match job_from(state, headers, path_param::(cx)).await { + let job = match job_from(state, headers, job_id(cx)).await { Ok(job) => job, Err(res) => return Ok(*res), }; @@ -1037,12 +1037,12 @@ async fn store_log_bytes( #[route(PUT "/api/v1/ci/jobs/{job_id}/artifacts/{artifact_name}")] async fn upload_artifact(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); - let job = match job_from(state, headers(cx), path_param::(cx)).await { + let state = context::(cx); + let job = match job_from(state, headers(cx), job_id(cx)).await { Ok(job) => job, Err(res) => return Ok(*res), }; - let name = path_param::(cx); + let name = artifact_name(cx); if !valid_artifact_name(name) { return Ok(api::error( StatusCode::UNPROCESSABLE_ENTITY, @@ -1187,8 +1187,8 @@ fn upload_failure(e: CoreError, interrupted: bool) -> Refusal { #[route(POST "/api/v1/ci/jobs/{job_id}/finish")] async fn finish(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); - let job = match job_from(state, headers(cx), path_param::(cx)).await { + let state = context::(cx); + let job = match job_from(state, headers(cx), job_id(cx)).await { Ok(job) => job, Err(res) => return Ok(*res), }; @@ -1210,8 +1210,8 @@ async fn finish(cx: &Cx, body: Body) -> topcoat::Result { #[route(POST "/api/v1/ci/jobs/{job_id}/requeue")] async fn requeue(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); - let job = match job_from(state, headers(cx), path_param::(cx)).await { + let state = context::(cx); + let job = match job_from(state, headers(cx), job_id(cx)).await { Ok(job) => job, Err(res) => return Ok(*res), }; diff --git a/crates/forge-web/src/client_ip.rs b/crates/forge-web/src/client_ip.rs index c4f608e..ee3ab4f 100644 --- a/crates/forge-web/src/client_ip.rs +++ b/crates/forge-web/src/client_ip.rs @@ -8,7 +8,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use ipnet::IpNet; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::{headers, remote_addr}; use crate::state::AppState; @@ -24,7 +24,7 @@ pub fn client_ip(cx: &Cx) -> IpAddr { /// The exact client address for this request, normalized but not bucketed, for display and audit. /// Unix-socket requests map to the unspecified address. pub fn client_addr(cx: &Cx) -> IpAddr { - let live = app_context::(cx).live(); + let live = context::(cx).live(); let trusted = &live.trusted_proxies; let peer = remote_addr(cx).map(|addr| addr.ip()); let forwarded = headers(cx) diff --git a/crates/forge-web/src/git_http.rs b/crates/forge-web/src/git_http.rs index a5f1a57..7e86461 100644 --- a/crates/forge-web/src/git_http.rs +++ b/crates/forge-web/src/git_http.rs @@ -2,7 +2,7 @@ //! Streams bodies to and from `git --stateless-rpc`; gzip request bodies are decoded. //! //! Compression must be off for these responses. Topcoat's compression is configured only on the -//! router builder (`Router::builder().compression(Compression::off())`), so boot.rs has to set it. +//! router builder (`Router::builder().with(Compression::disable())`), so boot.rs has to set it. use std::net::IpAddr; use std::time::Instant; @@ -20,7 +20,7 @@ use http_body_util::StreamBody; use tokio::io::AsyncReadExt; use tokio::process::{Child, ChildStdin}; use tokio_util::io::{ReaderStream, StreamReader}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, HeaderMap, StatusCode, path_param, query_params, route}; @@ -46,10 +46,10 @@ async fn info_refs(cx: &Cx) -> topcoat::Result { return Ok(text(StatusCode::FORBIDDEN, "dumb protocol not supported")); }; - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let repo_name = path_param::(cx); + let owner = owner(cx); + let repo_name = repo(cx); let (actor, repo, path) = match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await { @@ -102,10 +102,10 @@ async fn receive_pack(cx: &Cx, body: Body) -> topcoat::Result { /// Shared body of the two POST routes: authorize, spawn `git --stateless-rpc`, pipe the /// request body into its stdin and stream its stdout back. async fn serve_rpc(cx: &Cx, service: GitService, body: Body) -> Response { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let repo_name = path_param::(cx); + let owner = owner(cx); + let repo_name = repo(cx); let (actor, repo, path) = match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await { diff --git a/crates/forge-web/src/internal.rs b/crates/forge-web/src/internal.rs index 0847357..9104e6a 100644 --- a/crates/forge-web/src/internal.rs +++ b/crates/forge-web/src/internal.rs @@ -14,7 +14,7 @@ use forge_core::protection::effective; use forge_core::{Repo, Role, Store}; use forge_git::{GitCommand, GitEnv}; use serde::{Deserialize, Serialize}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Json; use topcoat::router::error::{bad_request, forbidden}; use topcoat::router::request::headers; @@ -121,7 +121,7 @@ pub fn router(state: AppState) -> Router { "/internal/admin/live", admin_live, )) - .app_context(state) + .with(state) .build() } @@ -144,7 +144,7 @@ async fn hook_endpoint( body: Body, stage: Stage, ) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let presented = headers(cx) .get(TOKEN_HEADER) .and_then(|v| v.to_str().ok()) @@ -219,7 +219,7 @@ struct AdminLiveRequest { /// `POST /internal/admin/live`. Wakes the open pages of the running server for a write made by /// another process (the admin CLI). The body is small and the answer carries no data. async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if !admin_authorized(cx, state) { return Err(forbidden().into()); } @@ -261,7 +261,7 @@ async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result { /// `POST /internal/admin/lfs-gc`. The body is ignored. async fn admin_lfs_gc_endpoint(cx: &Cx, _body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if !admin_authorized(cx, state) { return Err(forbidden().into()); } @@ -306,7 +306,7 @@ fn admin_authorized(cx: &Cx, state: &AppState) -> bool { } async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if !admin_authorized(cx, state) { return Err(forbidden().into()); } @@ -348,7 +348,7 @@ async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result } async fn admin_fsck_endpoint(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); if !admin_authorized(cx, state) { return Err(forbidden().into()); } diff --git a/crates/forge-web/src/lfs/routes.rs b/crates/forge-web/src/lfs/routes.rs index 9490be7..cf52a6b 100644 --- a/crates/forge-web/src/lfs/routes.rs +++ b/crates/forge-web/src/lfs/routes.rs @@ -21,7 +21,7 @@ use serde_json::{Value, json}; use sha2::{Digest, Sha256}; use tokio::io::AsyncWriteExt; use tokio_util::io::ReaderStream; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::response::Response; use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route, to_bytes}; @@ -74,10 +74,10 @@ struct VerifyRequest { #[route(POST "/{owner}/{repo}/info/lfs/objects/batch")] async fn batch(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let bytes = to_bytes(body, MAX_BATCH_BYTES).await?; let BatchPlan { request, action } = match parse_batch_operation(&bytes) { @@ -194,11 +194,11 @@ fn parse_batch_operation(bytes: &[u8]) -> Result> { #[route(GET "/{owner}/{repo}/info/lfs/objects/{oid}")] async fn get_object(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let name = path_param::(cx); - let oid = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); + let oid = oid(cx); if !is_valid_oid(oid) { return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid")); } @@ -234,11 +234,11 @@ async fn get_object(cx: &Cx) -> topcoat::Result { #[route(PUT "/{owner}/{repo}/info/lfs/objects/{oid}")] async fn put_object(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let name = path_param::(cx); - let oid = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); + let oid = oid(cx); if !is_valid_oid(oid) { return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid")); } @@ -275,10 +275,10 @@ async fn put_object(cx: &Cx, body: Body) -> topcoat::Result { #[route(POST "/{owner}/{repo}/info/lfs/objects/verify")] async fn verify(cx: &Cx, body: Body) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let repo = match authorize(state, client_ip(cx), headers, owner, name, Action::Write).await { Ok(repo) => repo, diff --git a/crates/forge-web/src/main.rs b/crates/forge-web/src/main.rs index fa3a434..48e2bae 100644 --- a/crates/forge-web/src/main.rs +++ b/crates/forge-web/src/main.rs @@ -77,7 +77,7 @@ const USAGE: &str = "usage: forge [--config ] [serve | hook Result { +async fn healthz(cx: &topcoat::context::Cx) -> Result { Ok(format!("ok {}", env!("FORGE_BUILD_SHA"))) } diff --git a/crates/forge-web/src/oci/auth.rs b/crates/forge-web/src/oci/auth.rs index b69a3bf..5fc7ffc 100644 --- a/crates/forge-web/src/oci/auth.rs +++ b/crates/forge-web/src/oci/auth.rs @@ -9,7 +9,7 @@ use forge_core::User; use forge_core::oci as rules; use forge_core::packages::{KIND_OCI, Package}; use http::header::{AUTHORIZATION, HeaderValue, WWW_AUTHENTICATE}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::StatusCode; use topcoat::router::request::headers; use topcoat::router::response::Response; @@ -42,7 +42,7 @@ pub struct Target { /// verified here; anything else goes to the personal access token check the API uses. A bad /// credential is a 401 with the challenge, so the client can ask again. pub async fn caller(cx: &Cx) -> Result { - let state = app_context::(cx); + let state = context::(cx); let headers = headers(cx); let Some(value) = headers.get(AUTHORIZATION).and_then(|v| v.to_str().ok()) else { return Ok(Caller { user: None }); diff --git a/crates/forge-web/src/oci/mod.rs b/crates/forge-web/src/oci/mod.rs index 3a3d202..49ba38b 100644 --- a/crates/forge-web/src/oci/mod.rs +++ b/crates/forge-web/src/oci/mod.rs @@ -19,7 +19,7 @@ pub mod manifests; use forge_core::oci as rules; use http::header::{CONTENT_TYPE, HeaderValue}; use serde_json::{Value, json}; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::{headers, method, uri}; use topcoat::router::response::Response; use topcoat::router::{Body, StatusCode, path_param, route}; @@ -105,7 +105,7 @@ fn query_value(pairs: &[(String, String)], key: &str) -> Option { /// `GET /v2/`: the probe. A caller with valid credentials gets 200; anyone else the challenge. #[route(GET "/v2/")] async fn root(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); Ok(match auth::caller(cx).await { Ok(Caller { user: Some(_) }) => json_response(StatusCode::OK, &json!({})), Ok(_) => auth::challenge(state, None), @@ -117,7 +117,7 @@ async fn root(cx: &Cx) -> topcoat::Result { /// short-lived bearer token. Anonymous callers get an anonymous token, which reads public images. #[route(GET "/v2/token")] async fn token(cx: &Cx) -> topcoat::Result { - let state = app_context::(cx); + let state = context::(cx); let caller = match auth::caller(cx).await { Ok(caller) => caller, Err(res) => return Ok(*res), @@ -168,8 +168,8 @@ async fn delete_v2(cx: &Cx, body: Body) -> topcoat::Result { /// Routes a request below `/v2/` to its operation. The caller is resolved first, so every answer /// about a repository comes from the same identity. async fn dispatch(cx: &Cx, body: Body) -> Response { - let state = app_context::(cx); - let segments: Vec = path_param::(cx).map(str::to_owned).collect(); + let state = context::(cx); + let segments: Vec = rest(cx).map(str::to_owned).collect(); let mut parts: Vec<&str> = segments.iter().map(String::as_str).collect(); while parts.last() == Some(&"") { parts.pop(); diff --git a/crates/forge-web/src/pages/activity.rs b/crates/forge-web/src/pages/activity.rs index f58a8b4..62b1f8b 100644 --- a/crates/forge-web/src/pages/activity.rs +++ b/crates/forge-web/src/pages/activity.rs @@ -9,7 +9,7 @@ use forge_core::{Reason, User}; use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; use serde_json::{Value, json}; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::response::Response; use topcoat::router::{Body, HeaderValue, StatusCode, route}; @@ -108,7 +108,7 @@ async fn activity(cx: &Cx) -> Result { *res.status_mut() = StatusCode::UNAUTHORIZED; return Ok(res); }; - let state = app_context::(cx); + let state = context::(cx); let body = activity_json(state, &user).await?; let mut response = Response::new(Body::from(body.to_string().into_bytes())); let headers = response.headers_mut(); @@ -131,7 +131,7 @@ async fn activity_stream(cx: &Cx) -> Result { *res.status_mut() = StatusCode::UNAUTHORIZED; return Ok(res); }; - let state = app_context::(cx).clone(); + let state = context::(cx).clone(); events_response(cx, activity_changes(state, user, "changed")) } diff --git a/crates/forge-web/src/pages/admin_backups.rs b/crates/forge-web/src/pages/admin_backups.rs index e7a07df..653bb49 100644 --- a/crates/forge-web/src/pages/admin_backups.rs +++ b/crates/forge-web/src/pages/admin_backups.rs @@ -12,7 +12,7 @@ use forge_core::store::backup_runs::{BackupRun, RunKind}; use forge_core::{AuditAction, Error, Store, User}; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{forbidden, see_other}; use topcoat::router::response::Response; @@ -109,7 +109,7 @@ fn run_row(run: &BackupRun, lang: Lang) -> RunRow { /// The rail of the Backups tab: Backups and Replication. #[component] -pub(crate) async fn backups_rail(lang: Lang, current: &'static str) -> Result { +pub(crate) async fn backups_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result { let items = vec![ RailItem { name: g::t(lang, K::Backups).to_owned(), @@ -131,6 +131,7 @@ pub(crate) async fn backups_rail(lang: Lang, current: &'static str) -> Result) -> Result Result { admin_only(cx).await?; - let state = app_context::(cx); + let state = context::(cx); let store = state.store.clone(); let jobs = state.jobs.clone(); stream_changes( @@ -233,7 +234,7 @@ async fn backups_events(cx: &Cx) -> Result { async fn backups_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let query = query_params::(cx)?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, Some(&viewer.0)); let runs = state.store.recent_runs(RUN_LIMIT).await?; let rows: Vec = runs.iter().map(|run| run_row(run, lang)).collect(); @@ -255,7 +256,7 @@ async fn backups_save(cx: &Cx, Form(form): Form>) -> Res return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = notice_of( lang, save_topic( @@ -289,7 +290,7 @@ async fn start_run(cx: &Cx, csrf: String, kind: RunKind) -> Result { return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = match launch(cx, state, &viewer.0, kind, lang).await { Ok(()) => g::started_notice(lang, kind), Err(e) => match e { @@ -548,7 +549,10 @@ mod tests { assert_eq!(status, 200); assert!(body.contains("schedule")); assert!(body.contains("disk full")); - assert!(!body.contains("hc.example.test"), "a healthcheck URL is a secret and is never rendered"); + assert!( + !body.contains("hc.example.test"), + "a healthcheck URL is a secret and is never rendered" + ); assert!( !body.contains("SECRET-TOKEN"), "the healthcheck token must not be shown" diff --git a/crates/forge-web/src/pages/admin_health.rs b/crates/forge-web/src/pages/admin_health.rs index 5355125..9f20b10 100644 --- a/crates/forge-web/src/pages/admin_health.rs +++ b/crates/forge-web/src/pages/admin_health.rs @@ -14,12 +14,14 @@ use forge_core::store::replication::DB_SUBJECT; use forge_core::time::stamp_to_unix; use tokio::process::Command; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::response::Response; use topcoat::router::{page, query_params, route}; use topcoat::view::{View, component, view}; -use crate::i18n::accounts::{A, duration_short, duration_short_in, meta_line, needs_attention, on_disk, t as at}; +use crate::i18n::accounts::{ + A, duration_short, duration_short_in, meta_line, needs_attention, on_disk, t as at, +}; use crate::i18n::alerts as alert_text; use crate::i18n::{self, Lang}; use crate::live::{Topic, stream_changes}; @@ -464,7 +466,7 @@ async fn alert_rows(state: &AppState, lang: Lang) -> Result> { /// The alert's raised time as a live relative time, worded per language. #[component] -async fn since_line(lang: Lang, stamp: &str) -> Result { +async fn since_line(cx: &Cx, lang: Lang, stamp: &str) -> Result { Ok(view! { if matches!(lang, Lang::Tr) { rel_time(lang: lang, stamp: stamp) " başladı" @@ -476,6 +478,7 @@ async fn since_line(lang: Lang, stamp: &str) -> Result { #[component] async fn health_view( + cx: &Cx, lang: Lang, health: Health, alerts: Vec, @@ -579,7 +582,7 @@ async fn health_view( async fn health_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let query = query_params::(cx)?; let health = gather(state, lang).await?; let all = alert_rows(state, lang).await?; @@ -644,7 +647,7 @@ async fn health_fingerprint(state: &AppState) -> Result { #[route(GET "/admin/health/events")] async fn health_events(cx: &Cx) -> Result { admin_only(cx).await?; - let state = app_context::(cx).clone(); + let state = context::(cx).clone(); stream_changes(cx, crate::live::admin(), &[Topic::AdminHealth], move || { let state = state.clone(); async move { health_fingerprint(&state).await } diff --git a/crates/forge-web/src/pages/admin_mail.rs b/crates/forge-web/src/pages/admin_mail.rs index a1d93ce..5bf3aec 100644 --- a/crates/forge-web/src/pages/admin_mail.rs +++ b/crates/forge-web/src/pages/admin_mail.rs @@ -19,7 +19,7 @@ use futures_util::{Stream, stream}; use serde::Deserialize; use tokio::sync::watch; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::content::sse::Event; use topcoat::router::error::{forbidden, see_other}; @@ -199,6 +199,7 @@ async fn page_data( #[component] async fn mail_view( + cx: &Cx, lang: Lang, csrf: String, data: PageData, @@ -332,7 +333,7 @@ async fn mail_view( async fn mail_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let query = query_params::(cx)?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, Some(&viewer.0)); let tab = if query.tab.as_deref() == Some("queue") { Tab::Queue @@ -398,7 +399,7 @@ async fn mail_save(cx: &Cx, Form(form): Form) -> Result return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let saved = save_settings(cx, state, &viewer.0, &form, lang).await; let transport = if form.transport.is_empty() { Ok(None) @@ -488,7 +489,7 @@ async fn mail_test(cx: &Cx, Form(form): Form) -> Result { return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = match queue_test(cx, state, &viewer.0, lang).await { Ok(()) => g::t(lang, K::TestQueued).to_owned(), Err(Error::Invalid(message)) => message, @@ -577,7 +578,7 @@ async fn queue_action(cx: &Cx, form: QueueForm, action: QueueAction) -> Result(cx); + let state = context::(cx); let now = now_stamp(); let (done, notice) = match action { QueueAction::Retry => { diff --git a/crates/forge-web/src/pages/admin_replication.rs b/crates/forge-web/src/pages/admin_replication.rs index 6246595..5f9598d 100644 --- a/crates/forge-web/src/pages/admin_replication.rs +++ b/crates/forge-web/src/pages/admin_replication.rs @@ -16,7 +16,7 @@ use forge_core::time::stamp_ago; use forge_core::{AuditAction, Error}; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{forbidden, see_other}; use topcoat::router::response::Response; @@ -229,6 +229,7 @@ async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result #[component] async fn replication_view( + cx: &Cx, lang: Lang, csrf: String, data: PageData, @@ -352,7 +353,7 @@ async fn page_fingerprint(state: &AppState) -> Result { #[route(GET "/admin/replication/events")] async fn replication_events(cx: &Cx) -> Result { admin_only(cx).await?; - let state = app_context::(cx).clone(); + let state = context::(cx).clone(); stream_changes( cx, crate::live::admin(), @@ -425,7 +426,7 @@ async fn replication_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let query = query_params::(cx)?; let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let mut data = page_data(state, lang).await?; let list = repo_list(&mut data, query); let settings = setting_rows(state, lang, REPLICATION_KEYS).await?; @@ -444,7 +445,7 @@ async fn replication_save(cx: &Cx, Form(form): Form>) -> return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = notice_of( lang, save_topic( @@ -474,7 +475,7 @@ async fn replication_reconcile(cx: &Cx, Form(form): Form) -> Resu return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = match reconcile_now(cx, state, &viewer.0, lang).await { Ok(()) => g::t(lang, K::ReconcileStarted).to_owned(), Err(Error::Config(message)) => message, diff --git a/crates/forge-web/src/pages/admin_runners.rs b/crates/forge-web/src/pages/admin_runners.rs index b9d0d35..61b47a7 100644 --- a/crates/forge-web/src/pages/admin_runners.rs +++ b/crates/forge-web/src/pages/admin_runners.rs @@ -17,7 +17,7 @@ use serde::Deserialize; use time::OffsetDateTime; use time::format_description::well_known::Rfc3339; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{SeeOther, forbidden, see_other}; use topcoat::router::request::uri; @@ -62,18 +62,8 @@ fn s(lang: Lang, en: &'static str, tr: &'static str) -> &'static str { /// Extra notice words: (word, English, Turkish, is an error). const EXTRA_NOTICES: [(&str, &str, &str, bool); 8] = [ - ( - "saved", - "Saved.", - "Kaydedildi.", - false, - ), - ( - "saved-restart", - "Saved.", - "Kaydedildi.", - false, - ), + ("saved", "Saved.", "Kaydedildi.", false), + ("saved-restart", "Saved.", "Kaydedildi.", false), ( "reset", "Override removed.", @@ -322,6 +312,7 @@ fn register_command(base_url: &str, token: &str) -> String { #[component] async fn runners_view( + cx: &Cx, lang: Lang, csrf: String, rows: Vec, @@ -388,6 +379,7 @@ fn list_href(page: u64, notice: &str) -> String { /// that are not destructive, so the confirm button is soft. #[component] pub(crate) async fn confirm_post( + cx: &Cx, lang: Lang, csrf: &str, action: &str, @@ -433,6 +425,7 @@ fn disable_message(lang: Lang, name: &str) -> String { /// pending the control shows that instead, and the runner clears it by coming back with a new id. #[component] async fn restart_control( + cx: &Cx, lang: Lang, csrf: &str, action: &str, @@ -461,7 +454,7 @@ const PIP_MAX: u32 = 16; /// The load of a runner: the jobs running, as a pip per concurrency slot, or a meter past `PIP_MAX`. #[component] -async fn load_meter(lang: Lang, running: u32, max: u32) -> Result { +async fn load_meter(cx: &Cx, lang: Lang, running: u32, max: u32) -> Result { let running_text = running.to_string(); let meter_max = max.max(1).to_string(); let use_pips = (1..=PIP_MAX).contains(&max); @@ -492,11 +485,7 @@ async fn load_meter(lang: Lang, running: u32, max: u32) -> Result { } #[component] -async fn token_view( - lang: Lang, - token: String, - command: String, -) -> Result { +async fn token_view(cx: &Cx, lang: Lang, token: String, command: String) -> Result { Ok(view! { head(title: g::t(lang, K::RegistrationToken))

(g::t(lang, K::CopyTokenNow))

@@ -522,7 +511,7 @@ async fn runners_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); let query = query_params::(cx)?; - let state = app_context::(cx); + let state = context::(cx); let tz = viewer.0.timezone.clone(); let now = now_unix(); let all: Vec = state @@ -566,7 +555,7 @@ async fn runner_token_create(cx: &Cx, Form(form): Form) -> Result(cx); + let state = context::(cx); let lang = i18n::lang(cx, Some(&viewer.0)); let ttl_hours = state.live().ci.registration_token_hours; let token = match state @@ -617,8 +606,8 @@ async fn runner_set_disabled(cx: &Cx, Form(form): Form) -> Result(cx); - let state = app_context::(cx); + let id = runner_id(cx); + let state = context::(cx); if runner_named(state, id).await?.is_none() { return Ok(back_to_list("missing")); } @@ -636,8 +625,8 @@ async fn runner_delete(cx: &Cx, Form(form): Form) -> Result if !check_csrf(&viewer.1, &form.csrf) { return Err(forbidden().into()); } - let id = path_param::(cx); - let state = app_context::(cx); + let id = runner_id(cx); + let state = context::(cx); let Some(runner) = runner_named(state, id).await? else { return Ok(back_to_list("missing")); }; @@ -816,10 +805,18 @@ fn field_text(lang: Lang, key: &str) -> &'static str { "limits.cpus" => s(lang, "CPU limit", "CPU sınırı"), "limits.pids" => s(lang, "Process limit", "İşlem sınırı"), "work_dir" => s(lang, "Work directory", "Çalışma dizini"), - "limits.image_max_gb" => s(lang, "Image cache max (GB)", "Kalıp önbelleği üst sınırı (GB)"), + "limits.image_max_gb" => s( + lang, + "Image cache max (GB)", + "Kalıp önbelleği üst sınırı (GB)", + ), "limits.job_disk_gb" => s(lang, "Disk per job (GB)", "İş başına disk (GB)"), "images.keep_days" => s(lang, "Keep images (days)", "Kalıpları sakla (gün)"), - "cache_max_gib" => s(lang, "Build cache max (GiB)", "Derleme önbelleği üst sınırı (GiB)"), + "cache_max_gib" => s( + lang, + "Build cache max (GiB)", + "Derleme önbelleği üst sınırı (GiB)", + ), "sandbox.userns" => s(lang, "User namespaces", "Kullanıcı ad alanları"), "name" => s(lang, "Name", "Ad"), "url" => s(lang, "Forge URL", "Forge adresi"), @@ -1371,6 +1368,7 @@ fn current(on: bool) -> Option<&'static str> { #[component] async fn runner_detail_view( + cx: &Cx, lang: Lang, csrf: String, runner: CiRunner, @@ -1418,7 +1416,11 @@ async fn runner_detail_view( let slots = row.concurrency.parse::().unwrap_or(0); let mut sub = vec![SubPart::text(row.state_text)]; if row.restart_pending.is_some() { - sub.push(SubPart::text(s(lang, "restart pending", "yeniden başlatma bekliyor"))); + sub.push(SubPart::text(s( + lang, + "restart pending", + "yeniden başlatma bekliyor", + ))); } let jobs_href = format!("{}?tab=jobs", row.detail_href); let save_action = format!("{}/settings", row.detail_href); @@ -1644,8 +1646,8 @@ async fn runner_detail_view( async fn runner_detail_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); - let id = path_param::(cx); + let state = context::(cx); + let id = runner_id(cx); let Some(runner) = runner_named(state, id).await? else { return Err(back_to_list("missing").into()); }; @@ -1683,8 +1685,8 @@ async fn runner_save_settings( if !check_csrf(&viewer.1, form.get("csrf").map_or("", String::as_str)) { return Err(forbidden().into()); } - let id = path_param::(cx); - let state = app_context::(cx); + let id = runner_id(cx); + let state = context::(cx); let tab = tab_slug(form.get("tab").map(String::as_str)); let back = |notice: &str| { see_other(format!( @@ -1756,7 +1758,7 @@ async fn runner_save_settings( #[route(GET "/admin/runners/events")] async fn runners_events(cx: &Cx) -> Result { admin_only(cx).await?; - let state = app_context::(cx); + let state = context::(cx); let wake = state.ci_live.subscribe_runners(); let events = futures_util::stream::unfold(wake, |mut wake| async move { wake.changed().await.ok()?; @@ -1776,8 +1778,8 @@ async fn runner_set_config(cx: &Cx, Form(form): Form) -> Result(cx); - let state = app_context::(cx); + let id = runner_id(cx); + let state = context::(cx); let back = |notice: &str| { if form.back == "detail" { let tab = tab_slug(Some(form.tab.as_str())); @@ -1851,8 +1853,8 @@ async fn runner_restart(cx: &Cx, Form(form): Form) -> Result(cx); - let state = app_context::(cx); + let id = runner_id(cx); + let state = context::(cx); let back = |notice: &str| { if form.back == "detail" { see_other(format!("/admin/runners/{}?notice={}", enc(id), enc(notice))) diff --git a/crates/forge-web/src/pages/admin_server.rs b/crates/forge-web/src/pages/admin_server.rs index a8be08d..cb000c7 100644 --- a/crates/forge-web/src/pages/admin_server.rs +++ b/crates/forge-web/src/pages/admin_server.rs @@ -21,7 +21,7 @@ use forge_core::{AuditAction, Error}; use futures_util::StreamExt; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{forbidden, see_other}; use topcoat::router::response::Response; @@ -546,7 +546,7 @@ pub(crate) fn with_notice(back: &str, notice: &str) -> String { /// The hidden form that resets one setting: the rows' "Reset to file value" buttons post to it by /// id. It goes outside the forms that save, since a form cannot hold another. #[component] -pub(crate) async fn reset_form(csrf: String, back: String) -> Result { +pub(crate) async fn reset_form(cx: &Cx, csrf: String, back: String) -> Result { Ok(view! {
@@ -557,7 +557,7 @@ pub(crate) async fn reset_form(csrf: String, back: String) -> Result /// The rows of a settings topic, one line each. The caller's form holds them. #[component] -pub(crate) async fn setting_lines(lang: Lang, rows: Vec) -> Result { +pub(crate) async fn setting_lines(cx: &Cx, lang: Lang, rows: Vec) -> Result { Ok(view! { for r in rows.iter() { srv_row(lang: lang, row: r) @@ -584,7 +584,7 @@ async fn search_hits( /// One setting on one line: its name, then its control (or its value when it cannot be changed /// here), then what to know about it. Every control is the same width, so the notes line up. #[component] -async fn srv_row(lang: Lang, row: &Row) -> Result { +async fn srv_row(cx: &Cx, lang: Lang, row: &Row) -> Result { let id = format!("srv-{}", row.key); let input = format!("srv-{}-in", row.key); Ok(view! { @@ -619,7 +619,7 @@ async fn srv_row(lang: Lang, row: &Row) -> Result { /// The facts after a setting's control: its kind, whether a restart is needed, and its override. #[component] -async fn srv_hints(lang: Lang, row: &Row) -> Result { +async fn srv_hints(cx: &Cx, lang: Lang, row: &Row) -> Result { Ok(view! { if !row.kind_label.is_empty() { @@ -644,6 +644,7 @@ async fn srv_hints(lang: Lang, row: &Row) -> Result { #[component] async fn server_view( + cx: &Cx, lang: Lang, csrf: String, page: &'static SrvPage, @@ -738,7 +739,7 @@ async fn server_view( async fn server_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let query = query_params::(cx)?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, Some(&viewer.0)); let slug = query.cat.as_deref().or(query.tab.as_deref()).unwrap_or(""); if let Some(to) = moved_slug(slug) { @@ -769,7 +770,7 @@ async fn server_save(cx: &Cx, Form(form): Form>) -> Resu return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let page = form .get("tab") .and_then(|t| page_by_slug(t)) @@ -841,7 +842,7 @@ async fn server_restart(cx: &Cx, Form(form): Form) -> Result(cx); + let state = context::(cx); let group = Group::parse(&form.tab).unwrap_or(Group::General); audit::record( &state.store, @@ -909,7 +910,7 @@ async fn server_reset(cx: &Cx, Form(form): Form) -> Result return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let notice = match reset(cx, state, &viewer.0, &form.key).await { Ok(()) => g::t(lang, K::SrvResetDone).to_owned(), Err(Error::Invalid(message)) => message, diff --git a/crates/forge-web/src/pages/admin_user_detail.rs b/crates/forge-web/src/pages/admin_user_detail.rs index 3d49baa..4a05483 100644 --- a/crates/forge-web/src/pages/admin_user_detail.rs +++ b/crates/forge-web/src/pages/admin_user_detail.rs @@ -10,7 +10,7 @@ use forge_core::store::user_delete::GHOST_USERNAME; use forge_core::{AuditAction, Store, User}; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{forbidden, not_found, see_other}; use topcoat::router::response::Response; @@ -88,7 +88,7 @@ fn is_ghost(user: &User) -> bool { } async fn load(cx: &Cx) -> Result { - let store = &app_context::(cx).store; + let store = &context::(cx).store; let id = path_param_segment(cx, "user_id").to_owned(); let Some(target) = store.user_by_id(&id).await? else { return Err(not_found().into()); @@ -161,6 +161,7 @@ fn local_stamp(stamp: &str, tz: &str) -> String { #[component] async fn detail_body( + cx: &Cx, lang: Lang, csrf: &str, viewer_id: &str, @@ -445,6 +446,7 @@ async fn detail_body( /// delete, which opens the page that says what goes with it. #[component] async fn org_body( + cx: &Cx, lang: Lang, org: User, members: Vec<(User, OrgMemberRole)>, @@ -564,7 +566,7 @@ async fn account_fingerprint(store: &Store, user_id: &str) -> Result { async fn detail_events(cx: &Cx) -> Result { admin_only(cx).await?; let id = path_param_segment(cx, "user_id").to_owned(); - let store = app_context::(cx).store.clone(); + let store = context::(cx).store.clone(); let topic = Topic::AdminUser(id.clone()); stream_changes(cx, crate::live::admin(), &[topic], move || { let store = store.clone(); @@ -579,7 +581,7 @@ async fn detail_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); let query = query_params::(cx)?; - let store = &app_context::(cx).store; + let store = &context::(cx).store; let id = path_param_segment(cx, "user_id").to_owned(); let org = match store.user_by_id(&id).await? { Some(user) if user.is_org() => { @@ -625,7 +627,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let state = app_context::(cx); + let state = context::(cx); let store = &state.store; let detail = load(cx).await?; let target = &detail.target; @@ -661,7 +663,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, Ok(()) => { // A suspension ends the user's sessions: their open tabs must see it. crate::pages::settings_live::bump_account( - app_context::(cx), + context::(cx), &target.id, ); audit( @@ -748,8 +750,8 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, /// Redirects to the detail page after a success, or renders it with a message. async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result { - // `view!` expects the `__cx` binding that `#[page]` provides. - let __cx = cx; + // `view!` expects the `cx` binding that `#[page]` provides. + let cx = cx; let (outcome, detail) = perform(cx, &form, action).await?; let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); diff --git a/crates/forge-web/src/pages/admin_users.rs b/crates/forge-web/src/pages/admin_users.rs index a78a661..1614bac 100644 --- a/crates/forge-web/src/pages/admin_users.rs +++ b/crates/forge-web/src/pages/admin_users.rs @@ -7,7 +7,7 @@ use forge_core::store::user_delete::{DeletionReport, GHOST_USERNAME}; use forge_core::{AuditAction, Session, Store, User}; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{forbidden, not_found, see_other}; use topcoat::router::response::Response; @@ -168,6 +168,7 @@ impl UserRow { #[component] async fn users_view( + cx: &Cx, lang: Lang, csrf: &str, users: Vec, @@ -289,7 +290,7 @@ async fn users_view( /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`. #[component] -pub(crate) async fn users_rail(lang: Lang, current: &'static str) -> Result { +pub(crate) async fn users_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result { let items = vec![ RailItem { name: g::t(lang, K::Users).to_owned(), @@ -333,7 +334,7 @@ async fn list_fingerprint(store: &Store) -> topcoat::Result { #[route(GET "/admin/users/events")] async fn users_events(cx: &Cx) -> Result { admin_only(cx).await?; - let store = app_context::(cx).store.clone(); + let store = context::(cx).store.clone(); stream_changes(cx, crate::live::admin(), &[Topic::AdminUsers], move || { let store = store.clone(); async move { list_fingerprint(&store).await } @@ -346,7 +347,7 @@ async fn users_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); let (finder, kind, page) = listing_args(query_params::(cx)?); - let users = app_context::(cx).store.list_users().await?; + let users = context::(cx).store.list_users().await?; let csrf = viewer.1.csrf_token.clone(); let title = g::t(lang, K::Users); Ok(view! { @@ -361,7 +362,7 @@ async fn users_create(cx: &Cx, Form(form): Form) -> Result(cx).store; + let store = &context::(cx).store; // Ok(Ok(user)) created; Ok(Err(message)) rejected with a user-facing message. let outcome: Result> = create_user(store, &form, lang).await; @@ -487,6 +488,7 @@ async fn review_target( #[component] async fn delete_body( + cx: &Cx, lang: Lang, csrf: &str, target: User, @@ -555,6 +557,7 @@ async fn delete_body( /// An organization is not a person: this points at its own settings instead of offering a delete. #[component] async fn org_delete_note( + cx: &Cx, lang: Lang, target: User, repos: Vec, @@ -593,7 +596,7 @@ async fn org_delete_note( async fn user_delete_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); - let store = &app_context::(cx).store; + let store = &context::(cx).store; let target_id = path_param_segment(cx, "user_id").to_owned(); let Some(target) = store.user_by_id(&target_id).await? else { return Err(not_found().into()); @@ -632,7 +635,7 @@ async fn user_delete(cx: &Cx, Form(form): Form) -> Result return Err(forbidden().into()); } let lang = i18n::lang(cx, Some(&viewer.0)); - let store = &app_context::(cx).store; + let store = &context::(cx).store; let target_id = path_param_segment(cx, "user_id").to_owned(); let Some(target) = store.user_by_id(&target_id).await? else { return Err(not_found().into()); @@ -654,7 +657,7 @@ async fn user_delete(cx: &Cx, Form(form): Form) -> Result match store.delete_user(&target.id, &ghost.id).await { Ok(_) => { // Their sessions and keys are gone: any open tab of theirs must leave. - crate::pages::settings_live::bump_account(app_context::(cx), &target.id); + crate::pages::settings_live::bump_account(context::(cx), &target.id); audit::record( store, Some(cx), diff --git a/crates/forge-web/src/pages/archive.rs b/crates/forge-web/src/pages/archive.rs index 35a8f92..88486c7 100644 --- a/crates/forge-web/src/pages/archive.rs +++ b/crates/forge-web/src/pages/archive.rs @@ -17,7 +17,7 @@ use tokio::process::Child; use tokio::sync::{OwnedSemaphorePermit, Semaphore}; use tokio_util::io::ReaderStream; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::error::not_found; use topcoat::router::response::Response; use topcoat::router::{Body, path_param, route}; @@ -73,15 +73,15 @@ fn archive_prefix(repo: &str, reference: &str, commit: &str) -> String { #[route(GET "/{owner}/{repo}/archive/{*rest}")] async fn archive(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let rest = path_param::(cx).collect::>().join("/"); + let owner = owner(cx); + let name = repo(cx); + let rest = rest(cx).collect::>().join("/"); let Some((reference, format)) = split_format(&rest) else { return Err(not_found().into()); }; let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let repo_dir = ctx.path.clone(); let rev = reference.to_owned(); diff --git a/crates/forge-web/src/pages/assets.rs b/crates/forge-web/src/pages/assets.rs index 9d029b5..70d6eaa 100644 --- a/crates/forge-web/src/pages/assets.rs +++ b/crates/forge-web/src/pages/assets.rs @@ -134,7 +134,7 @@ const OFFLINE_HTML: &str = include_str!("../../assets/offline.html"); const OFFLINE_JS: &str = include_str!("../../assets/offline.js"); #[route(GET "/assets/offline.html")] -async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> { +async fn offline_html(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> { let mut headers = HeaderMap::new(); headers.insert( header::CONTENT_TYPE, @@ -150,7 +150,7 @@ async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> { } #[route(GET "/assets/offline.js")] -async fn offline_js() -> Result<(StatusCode, HeaderMap, &'static str)> { +async fn offline_js(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> { let mut headers = HeaderMap::new(); headers.insert( header::CONTENT_TYPE, @@ -216,42 +216,42 @@ const FONT_CACHE: &str = "public, max-age=31536000, immutable"; const LICENSE_CACHE: &str = "public, max-age=86400"; #[route(GET "/assets/fonts/figtree-5.3.0-latin-wght.woff2")] -async fn figtree_latin() -> Result { +async fn figtree_latin(cx: &Cx) -> Result { Ok(bytes_response(FIGTREE_LATIN, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/figtree-5.3.0-latin-ext-wght.woff2")] -async fn figtree_latin_ext() -> Result { +async fn figtree_latin_ext(cx: &Cx) -> Result { Ok(bytes_response(FIGTREE_LATIN_EXT, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/archivo-5.3.0-latin-wdth.woff2")] -async fn archivo_latin() -> Result { +async fn archivo_latin(cx: &Cx) -> Result { Ok(bytes_response(ARCHIVO_LATIN, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/archivo-5.3.0-latin-ext-wdth.woff2")] -async fn archivo_latin_ext() -> Result { +async fn archivo_latin_ext(cx: &Cx) -> Result { Ok(bytes_response(ARCHIVO_LATIN_EXT, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400.woff2")] -async fn plex_mono_400() -> Result { +async fn plex_mono_400(cx: &Cx) -> Result { Ok(bytes_response(PLEX_MONO_400, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-500.woff2")] -async fn plex_mono_500() -> Result { +async fn plex_mono_500(cx: &Cx) -> Result { Ok(bytes_response(PLEX_MONO_500, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-600.woff2")] -async fn plex_mono_600() -> Result { +async fn plex_mono_600(cx: &Cx) -> Result { Ok(bytes_response(PLEX_MONO_600, "font/woff2", FONT_CACHE)) } #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400-italic.woff2")] -async fn plex_mono_400_italic() -> Result { +async fn plex_mono_400_italic(cx: &Cx) -> Result { Ok(bytes_response( PLEX_MONO_400_ITALIC, "font/woff2", @@ -260,7 +260,7 @@ async fn plex_mono_400_italic() -> Result { } #[route(GET "/assets/fonts/Figtree-OFL.txt")] -async fn figtree_license() -> Result { +async fn figtree_license(cx: &Cx) -> Result { Ok(bytes_response( FIGTREE_LICENSE, "text/plain; charset=utf-8", @@ -269,7 +269,7 @@ async fn figtree_license() -> Result { } #[route(GET "/assets/fonts/Archivo-OFL.txt")] -async fn archivo_license() -> Result { +async fn archivo_license(cx: &Cx) -> Result { Ok(bytes_response( ARCHIVO_LICENSE, "text/plain; charset=utf-8", @@ -278,7 +278,7 @@ async fn archivo_license() -> Result { } #[route(GET "/assets/fonts/IBMPlexMono-OFL.txt")] -async fn plex_mono_license() -> Result { +async fn plex_mono_license(cx: &Cx) -> Result { Ok(bytes_response( PLEX_MONO_LICENSE, "text/plain; charset=utf-8", @@ -288,13 +288,16 @@ async fn plex_mono_license() -> Result { #[cfg(test)] mod tests { - use topcoat::cookie::RouterBuilderCookieExt; + use topcoat::cookie::CookieLayer; use topcoat::router::request::Request; use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes}; #[tokio::test] async fn fonts_and_licenses_are_served() { - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); // Bundled fonts are immutable woff2 files. for uri in [ "/assets/fonts/figtree-5.3.0-latin-wght.woff2", @@ -347,7 +350,10 @@ mod tests { #[tokio::test] async fn stylesheet_is_served_with_headers_from_the_security_layer() { - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); let req = Request::builder() .method("GET") .uri(crate::views::STYLESHEET_HREF) @@ -373,7 +379,10 @@ mod tests { #[tokio::test] async fn immutable_assets_are_served_with_long_cache() { - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); // Each bundle is immutable under its own type. Its body holds the marker, when one is given. for (uri, kind, marker) in [ (crate::views::STYLESHEET_HREF, "text/css; charset=utf-8", ""), @@ -422,7 +431,10 @@ mod tests { #[tokio::test] async fn alive_stream_sends_retry_first() { use http_body_util::BodyExt; - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); let req = Request::builder() .method("GET") .uri("/-/alive") @@ -447,7 +459,10 @@ mod tests { #[tokio::test] async fn offline_page_and_script_are_served_without_caching() { - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); for (uri, kind) in [ ("/assets/offline.html", "text/html"), ("/assets/offline.js", "text/javascript"), @@ -471,7 +486,10 @@ mod tests { #[tokio::test] async fn custom_css_keys_the_hue_choices_and_is_empty_without_one() { - let router: Router = Router::builder().discover().cookies().build(); + let router: Router = Router::builder() + .discover() + .layer(CookieLayer::new()) + .build(); let req = Request::builder() .method("GET") .uri("/theme/custom.css?al=hue-215&ad=plum&bl=hue-7&bd=hue-360") diff --git a/crates/forge-web/src/pages/audit_log.rs b/crates/forge-web/src/pages/audit_log.rs index bb4c3ab..3372f10 100644 --- a/crates/forge-web/src/pages/audit_log.rs +++ b/crates/forge-web/src/pages/audit_log.rs @@ -7,7 +7,7 @@ use forge_core::{AuditAction, AuditEntry, AuditFilter, Store}; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::response::Response; use topcoat::router::{page, query_params, route}; use topcoat::view::{View, component, view}; @@ -84,7 +84,11 @@ impl Span { fn from_query(query: &AuditQuery) -> Span { let clean = |v: &Option| v.clone().unwrap_or_default().trim().to_owned(); let when = clean(&query.when); - let when = if WHENS.contains(&when.as_str()) { when } else { String::new() }; + let when = if WHENS.contains(&when.as_str()) { + when + } else { + String::new() + }; let (from, to) = if when == "custom" { (clean(&query.from), clean(&query.to)) } else { @@ -396,6 +400,7 @@ fn nav_for( /// The search and the action filter, in one GET form to `action`. #[component] async fn log_tools( + cx: &Cx, lang: Lang, form_action: &str, finder: Finder, @@ -451,6 +456,7 @@ async fn log_tools( /// The facts of one entry after its name: time, then whatever `show` asks for. #[component] async fn entry_facts( + cx: &Cx, lang: Lang, row: RowView, show_actor: bool, @@ -477,7 +483,12 @@ async fn entry_facts( } #[component] -async fn audit_table(lang: Lang, groups: Vec, show_actor: bool) -> Result { +async fn audit_table( + cx: &Cx, + lang: Lang, + groups: Vec, + show_actor: bool, +) -> Result { Ok(view! { if groups.is_empty() {

(g::t(lang, K::NoEntries))

@@ -495,7 +506,7 @@ async fn audit_table(lang: Lang, groups: Vec, show_actor: bool) -> Result /// One entry on its own line. #[component] -async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result { +async fn single_row(cx: &Cx, lang: Lang, mut group: Group, show_actor: bool) -> Result { let row = group.rows.remove(0); let name = row.name.clone(); let action = row.action.clone(); @@ -510,10 +521,13 @@ async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result Result { +async fn group_row(cx: &Cx, lang: Lang, mut group: Group, show_actor: bool) -> Result { let count = group.rows.len().to_string(); let target = group.shared_target().map(str::to_owned); - let ip = group.shared_ip().map(str::to_owned).filter(|ip| !ip.is_empty()); + let ip = group + .shared_ip() + .map(str::to_owned) + .filter(|ip| !ip.is_empty()); let details = group .shared_details() .map(str::to_owned) @@ -568,6 +582,7 @@ async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result, finder: Finder, @@ -662,7 +679,7 @@ async fn admin_audit_page(cx: &Cx) -> Result { let viewer = admin_only(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); let query = query_params::(cx)?; - let store = &app_context::(cx).store; + let store = &context::(cx).store; let (finder, action, actor) = query_parts(query); let span = Span::from_query(query); @@ -734,7 +751,7 @@ async fn admin_audit_events(cx: &Cx) -> Result { let query = query_params::(cx)?; let action = query.action.clone().unwrap_or_default().trim().to_owned(); let actor = query.actor.clone().unwrap_or_default().trim().to_owned(); - let store = app_context::(cx).store.clone(); + let store = context::(cx).store.clone(); stream_changes(cx, crate::live::admin(), &[Topic::AdminAudit], move || { let store = store.clone(); let action = action.clone(); @@ -749,7 +766,7 @@ async fn own_log_page(cx: &Cx) -> Result { let viewer = require_user(cx).await?; let lang = i18n::lang(cx, Some(&viewer.0)); let query = query_params::(cx)?; - let store = &app_context::(cx).store; + let store = &context::(cx).store; let (finder, action, _) = query_parts(query); let span = Span::from_query(query); let mut filter = AuditFilter { @@ -768,7 +785,7 @@ async fn own_log_page(cx: &Cx) -> Result { let mut params = keep_params(&finder, &action, ""); params.extend(span.params()); let nav = nav_for(page, pages, "/settings/security/log", ¶ms); - let items = security_rail_for(app_context::(cx), lang, &viewer, "log").await?; + let items = security_rail_for(context::(cx), lang, &viewer, "log").await?; let title = g::t(lang, K::SecurityLogTitle); Ok(view! { shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, items: items, finder: finder.clone(), action: action.clone(), span: span.clone(), total: total, groups: groups, page: page, pages: pages, nav: nav)) diff --git a/crates/forge-web/src/pages/authoring.rs b/crates/forge-web/src/pages/authoring.rs index 07182a1..289f284 100644 --- a/crates/forge-web/src/pages/authoring.rs +++ b/crates/forge-web/src/pages/authoring.rs @@ -16,7 +16,7 @@ use http_body_util::StreamBody; use serde::Deserialize; use serde_json::json; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::error::{bad_request, forbidden, not_found}; use topcoat::router::request::{headers, uri}; @@ -121,8 +121,8 @@ fn fail(status: StatusCode, message: &str) -> Response { /// comment can attach), and the repo must not be archived. #[route(POST "/{owner}/{repo}/attachments")] async fn upload(cx: &Cx, body: Body) -> Result { - let ctx = load_repo(cx, path_param::(cx), path_param::(cx)).await?; - let state = app_context::(cx); + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; + let state = context::(cx); if ctx.repo.archived { return Err(forbidden().into()); } @@ -228,11 +228,11 @@ async fn upload(cx: &Cx, body: Body) -> Result { /// Serves an attachment to anyone who can read its repo; everyone else gets 404. #[route(GET "/attachments/{id}/{name}")] async fn download(cx: &Cx) -> Result { - let state = app_context::(cx); - let Some(att) = state.store.attachment(path_param::(cx)).await? else { + let state = context::(cx); + let Some(att) = state.store.attachment(id(cx)).await? else { return Err(not_found().into()); }; - if att.name != path_param::(cx) { + if att.name != name(cx) { return Err(not_found().into()); } let Some(repo) = state.store.repo_by_id(&att.repo_id).await? else { @@ -289,8 +289,8 @@ async fn download(cx: &Cx) -> Result { /// `kind=issue` lists issues and pull requests by number or title. #[route(GET "/{owner}/{repo}/suggest")] async fn suggest(cx: &Cx) -> Result { - let ctx = load_repo(cx, path_param::(cx), path_param::(cx)).await?; - let state = app_context::(cx); + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; + let state = context::(cx); if ctx.viewer.is_none() { return Err(forbidden().into()); } @@ -364,10 +364,10 @@ async fn pull_tasks(cx: &Cx, Form(form): Form) -> Result { } async fn toggle(cx: &Cx, kind: ItemKind, form: TaskForm) -> Result { - let number = parse_number(path_param::(cx))?; - let ctx = load_repo(cx, path_param::(cx), path_param::(cx)).await?; + let number = parse_number(number(cx))?; + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; let (user, _) = require_csrf(cx, &form.csrf).await?; - let state = app_context::(cx); + let state = context::(cx); let item = item_for(state, &ctx, kind, number).await?; let Ok(index) = form.index.parse::() else { return Err(bad_request("bad task index").into()); diff --git a/crates/forge-web/src/pages/avatars.rs b/crates/forge-web/src/pages/avatars.rs index 33b0e0e..7c7a383 100644 --- a/crates/forge-web/src/pages/avatars.rs +++ b/crates/forge-web/src/pages/avatars.rs @@ -8,7 +8,7 @@ use http::header::{ }; use sha2::{Digest, Sha256}; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::headers; use topcoat::router::{path_param_segment, query_params, route}; @@ -96,7 +96,7 @@ async fn avatar(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec)> { .get(IF_NONE_MATCH) .and_then(|v| v.to_str().ok()) .map(str::to_owned); - let store = &app_context::(cx).store; + let store = &context::(cx).store; let Some(user) = store.user_by_username(&name).await? else { return Ok(( @@ -155,7 +155,10 @@ mod tests { assert_eq!(svg, super::default_svg("<")); let url = super::default_data_url("<"); assert!(url.starts_with("data:image/svg+xml,%3Csvg"), "{url}"); - assert!(!url.contains('<') && !url.contains('#') && !url.contains('"'), "{url}"); + assert!( + !url.contains('<') && !url.contains('#') && !url.contains('"'), + "{url}" + ); assert!(super::PALETTE.iter().any(|c| svg.contains(c))); } diff --git a/crates/forge-web/src/pages/banner.rs b/crates/forge-web/src/pages/banner.rs index 27d053e..9f2eb38 100644 --- a/crates/forge-web/src/pages/banner.rs +++ b/crates/forge-web/src/pages/banner.rs @@ -11,7 +11,7 @@ use forge_core::config::BannerConfig; use forge_core::token::hash_token; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context, try_app_context}; +use topcoat::context::{Cx, context, try_context}; use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; use topcoat::router::content::Form; use topcoat::router::error::{SeeOther, see_other}; @@ -66,7 +66,7 @@ pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Opt /// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's /// account preferences; without them the dismissal comes from the cookie. pub fn current(cx: &Cx, prefs: Option<&HashMap>) -> Option { - let state = try_app_context::(cx)?; + let state = try_context::(cx)?; let live = state.live(); if live.banner.message.trim().is_empty() { return None; @@ -90,7 +90,7 @@ struct DismissForm { async fn dismiss(cx: &Cx, Form(form): Form) -> Result { let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit()); if hash_ok && let Some((user, _)) = current_user(cx).await? { - app_context::(cx) + context::(cx) .store .set_user_pref(&user.id, BANNER_PREF, &form.hash) .await?; diff --git a/crates/forge-web/src/pages/blame.rs b/crates/forge-web/src/pages/blame.rs index b25a5fd..0aa2308 100644 --- a/crates/forge-web/src/pages/blame.rs +++ b/crates/forge-web/src/pages/blame.rs @@ -7,7 +7,7 @@ use std::time::Duration; use forge_git::blame::{Blame, blame}; use forge_git::browse::EntryKind; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::error::not_found; use topcoat::router::{page, path_param}; use topcoat::view::{Unescaped, View, component, view}; @@ -16,10 +16,10 @@ use crate::i18n::browse as b; use crate::i18n::code::{self as g, K}; use crate::i18n::{self, Lang}; use crate::pages::blob::{Line, text_lines}; +use crate::pages::passkeys::s; use crate::pages::ref_live; use crate::pages::repo::repo_head; use crate::pages::repo_ctx::load_repo; -use crate::pages::passkeys::s; use crate::pages::tree::{MAX_BLOB_BYTES, read_file, resolve}; use crate::render::emoji::emojify; use crate::state::AppState; @@ -103,7 +103,7 @@ fn build_rows( } #[component] -async fn blame_table(rows: Vec, lang: Lang) -> Result { +async fn blame_table(cx: &Cx, rows: Vec, lang: Lang) -> Result { Ok(view! {
@@ -141,12 +141,12 @@ async fn blame_table(rows: Vec, lang: Lang) -> Result { #[page("/{owner}/{repo}/blame/{*rest}")] async fn blame_page(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let rest = path_param::(cx).collect::>().join("/"); + let owner = owner(cx); + let name = repo(cx); + let rest = rest(cx).collect::>().join("/"); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); let repo = &ctx.repo; @@ -199,7 +199,10 @@ async fn blame_page(cx: &Cx) -> Result { ); // Blame sits beside the file's source: a markdown file's plain view, any other file's own page. let markdown = matches!( - file_name.rsplit_once('.').map(|(_, ext)| ext.to_ascii_lowercase()).as_deref(), + file_name + .rsplit_once('.') + .map(|(_, ext)| ext.to_ascii_lowercase()) + .as_deref(), Some("md" | "markdown") ); let source_href = if markdown { diff --git a/crates/forge-web/src/pages/blob.rs b/crates/forge-web/src/pages/blob.rs index 856d50a..54db834 100644 --- a/crates/forge-web/src/pages/blob.rs +++ b/crates/forge-web/src/pages/blob.rs @@ -4,7 +4,7 @@ use forge_git::browse::EntryKind; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::error::not_found; use topcoat::router::{page, path_param, query_params}; use topcoat::view::{Unescaped, View, component, view}; @@ -91,7 +91,7 @@ pub fn text_lines(text: &str, file_name: &str) -> Vec { } #[component] -async fn file_table(lines: Vec) -> Result { +async fn file_table(cx: &Cx, lines: Vec) -> Result { Ok(view! {
@@ -116,13 +116,13 @@ async fn file_table(lines: Vec) -> Result { #[page("/{owner}/{repo}/blob/{*rest}")] async fn blob_page(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let rest = path_param::(cx).collect::>().join("/"); + let owner = owner(cx); + let name = repo(cx); + let rest = rest(cx).collect::>().join("/"); let plain = query_params::(cx)?.plain.as_deref() == Some("1"); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); let repo = &ctx.repo; @@ -262,7 +262,11 @@ async fn blob_page(cx: &Cx) -> Result { let mut views: Vec<(&'static str, String, bool)> = Vec::new(); if is_markdown { views.push((g::t(lang, K::Rendered), base.clone(), !plain)); - views.push((g::t(lang, K::SourceToggle), format!("{base}?plain=1"), plain)); + views.push(( + g::t(lang, K::SourceToggle), + format!("{base}?plain=1"), + plain, + )); } else if is_text { views.push((g::t(lang, K::SourceToggle), base.clone(), true)); } diff --git a/crates/forge-web/src/pages/branches.rs b/crates/forge-web/src/pages/branches.rs index 0a464a9..f61bdf2 100644 --- a/crates/forge-web/src/pages/branches.rs +++ b/crates/forge-web/src/pages/branches.rs @@ -9,7 +9,7 @@ use forge_git::branches; use forge_git::browse::{self, RefKind}; use serde::Deserialize; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::cookie::{Cookie, Cookies, SameSite, cookies}; use topcoat::router::content::Form; use topcoat::router::error::{SeeOther, forbidden, see_other}; @@ -102,6 +102,7 @@ struct BranchRow { #[component] async fn new_branch_form( + cx: &Cx, lang: Lang, action: String, csrf: String, @@ -134,6 +135,7 @@ async fn new_branch_form( #[component] async fn branch_table( + cx: &Cx, rows: Vec, lang: Lang, csrf: String, @@ -175,10 +177,10 @@ async fn branch_table( #[page("/{owner}/{repo}/branches")] async fn branches_page(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); let repo = &ctx.repo; let now = now_unix(); @@ -322,14 +324,14 @@ fn back(cx: &Cx, ctx: &RepoCtx, word: &'static str) -> SeeOther { /// A protection rule that only accepts pull requests keeps the name closed to direct creation. #[route(POST "/{owner}/{repo}/branches")] async fn branch_create(cx: &Cx, Form(form): Form) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let ctx = load_repo(cx, owner, name).await?; let (user, _) = require_csrf(cx, &form.csrf).await?; if !ctx.can_write() { return Err(forbidden().into()); } - let state = app_context::(cx); + let state = context::(cx); let branch = form.name.trim().to_owned(); let from = match form.from.trim() { "" => ctx.repo.default_branch.clone(), @@ -382,14 +384,14 @@ async fn branch_create(cx: &Cx, Form(form): Form) -> Result) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let ctx = load_repo(cx, owner, name).await?; let (user, _) = require_csrf(cx, &form.csrf).await?; if !ctx.can_write() { return Err(forbidden().into()); } - let state = app_context::(cx); + let state = context::(cx); let branch = form.name.trim().to_owned(); if branch == ctx.repo.default_branch { return Ok(back(cx, &ctx, "default")); diff --git a/crates/forge-web/src/pages/ci_badge.rs b/crates/forge-web/src/pages/ci_badge.rs index e924b21..8c27a29 100644 --- a/crates/forge-web/src/pages/ci_badge.rs +++ b/crates/forge-web/src/pages/ci_badge.rs @@ -11,7 +11,7 @@ use forge_core::ci::{JobState, RunState}; use http::header::{CACHE_CONTROL, CONTENT_TYPE}; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::request::uri; use topcoat::router::response::Response; use topcoat::router::{Body, HeaderValue, StatusCode, path_param, route}; @@ -205,10 +205,10 @@ fn badge_query(cx: &Cx) -> BadgeQuery { /// uses, so a private repo the viewer cannot read is a 404. #[route(GET "/{owner}/{repo}/badge.svg")] async fn ci_badge(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let query = badge_query(cx); let branch = query .branch diff --git a/crates/forge-web/src/pages/ci_fail.rs b/crates/forge-web/src/pages/ci_fail.rs index 15bbe10..3f7f9b9 100644 --- a/crates/forge-web/src/pages/ci_fail.rs +++ b/crates/forge-web/src/pages/ci_fail.rs @@ -3,6 +3,7 @@ //! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text. use topcoat::Result; +use topcoat::context::Cx; use topcoat::view::{View, component, view}; use crate::ci::log_path; @@ -59,14 +60,20 @@ impl FailFirst { /// The `file:line` in a compiler's or test's lines around an error: the first word that ends in /// digits after a colon and holds a dot. fn place_in(lines: &[String]) -> Option { - lines.iter().flat_map(|line| line.split_whitespace()).find_map(|word| { - let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ',')); - let mut parts = word.split(':'); - let file = parts.next()?; - let line = parts.next()?; - (file.contains('.') && !file.contains("::") && !line.is_empty() && line.bytes().all(|b| b.is_ascii_digit())) + lines + .iter() + .flat_map(|line| line.split_whitespace()) + .find_map(|word| { + let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ',')); + let mut parts = word.split(':'); + let file = parts.next()?; + let line = parts.next()?; + (file.contains('.') + && !file.contains("::") + && !line.is_empty() + && line.bytes().all(|b| b.is_ascii_digit())) .then(|| format!("{}:{line}", file.rsplit('/').next().unwrap_or(file))) - }) + }) } /// Reads the failed job's log tail (the same bounded read as the job page) and picks the lines to show. @@ -108,7 +115,7 @@ pub(crate) async fn read( /// The failure row, pinned above the log, which opens at the first error line: why it failed, the /// place in the code, and a link to that line in the job's log. #[component] -pub(crate) async fn fail_first_block(lang: Lang, fail: FailFirst) -> Result { +pub(crate) async fn fail_first_block(cx: &Cx, lang: Lang, fail: FailFirst) -> Result { let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href)); let why = if fail.message.is_empty() { fail.error.clone().unwrap_or_else(|| fail.job_name.clone()) diff --git a/crates/forge-web/src/pages/ci_job.rs b/crates/forge-web/src/pages/ci_job.rs index 28d0046..4d67e60 100644 --- a/crates/forge-web/src/pages/ci_job.rs +++ b/crates/forge-web/src/pages/ci_job.rs @@ -21,7 +21,7 @@ use http_body_util::StreamBody; use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom}; use tokio::sync::watch; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::sse::{Event, last_event_id}; use topcoat::router::error::not_found; use topcoat::router::request::uri; @@ -419,6 +419,7 @@ async fn job_fingerprint_now(store: &Store, job_id: &str) -> Result Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let id = path_param::(cx).to_owned(); + let owner = owner(cx); + let name = repo(cx); + let id = job_id(cx).to_owned(); let ctx = load_repo(cx, owner, name).await?; let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); - let state = app_context::(cx); + let state = context::(cx); let (job, run) = job_of(state, &ctx, &id).await?; let Tail { text: log, @@ -633,11 +634,11 @@ const LOG_EVENT_BYTES: u64 = 64 * 1024; /// this job (see `CiLive`), so a finished page still hears about deleted artifacts or logs. #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/events")] async fn job_events(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let id = path_param::(cx).to_owned(); + let owner = owner(cx); + let name = repo(cx); + let id = job_id(cx).to_owned(); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let (job, _) = job_of(state, &ctx, &id).await?; let offset = last_event_id(cx) .and_then(|id| id.parse::().ok()) @@ -797,11 +798,11 @@ async fn read_log( /// is terminal. #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/log.txt")] async fn job_log(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let id = path_param::(cx).to_owned(); + let owner = owner(cx); + let name = repo(cx); + let id = job_id(cx).to_owned(); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let (job, _) = job_of(state, &ctx, &id).await?; let path = log_path(&state.config.data_dir, &job.id); let chunks = follow_log( @@ -834,12 +835,12 @@ async fn job_log(cx: &Cx) -> Result { /// Downloads an artifact of a job as an attachment. #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/artifacts/{artifact_name}")] async fn artifact_download(cx: &Cx) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); - let id = path_param::(cx).to_owned(); - let file_name = path_param::(cx).to_owned(); + let owner = owner(cx); + let name = repo(cx); + let id = job_id(cx).to_owned(); + let file_name = artifact_name(cx).to_owned(); let ctx = load_repo(cx, owner, name).await?; - let state = app_context::(cx); + let state = context::(cx); let (job, _) = job_of(state, &ctx, &id).await?; let Some(artifact) = state.store.artifact(&job.id, &file_name).await? else { return Err(not_found().into()); diff --git a/crates/forge-web/src/pages/ci_runs.rs b/crates/forge-web/src/pages/ci_runs.rs index 2702774..238ffc9 100644 --- a/crates/forge-web/src/pages/ci_runs.rs +++ b/crates/forge-web/src/pages/ci_runs.rs @@ -23,7 +23,7 @@ use time::format_description::well_known::Rfc3339; use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom}; use tokio::sync::watch; use topcoat::Result; -use topcoat::context::{Cx, app_context}; +use topcoat::context::{Cx, context}; use topcoat::router::content::Form; use topcoat::router::content::sse::{Event, KeepAlive, Sse}; use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; @@ -1408,7 +1408,10 @@ fn job_steps( }) }) .collect(); - let total: u64 = elapsed_of.iter().map(|secs| u64::try_from(*secs).unwrap_or(0)).sum(); + let total: u64 = elapsed_of + .iter() + .map(|secs| u64::try_from(*secs).unwrap_or(0)) + .sum(); for (step, elapsed) in steps.iter().zip(elapsed_of) { let state = step.state(job.state); let running = state == StepState::Running; @@ -1593,6 +1596,7 @@ async fn usernames( /// A small form that POSTs the CSRF token to `action`, with one button. #[component] async fn action_button( + cx: &Cx, action: String, csrf: String, label: &'static str, @@ -1628,11 +1632,11 @@ async fn runs_split( job: Option<&str>, step: Option, ) -> Result { - let owner = path_param::(cx); - let name = path_param::(cx); + let owner = owner(cx); + let name = repo(cx); let ctx = load_repo(cx, owner, name).await?; let lang = i18n::lang(cx, viewer_user(&ctx)); - let state = app_context::(cx); + let state = context::(cx); let title = title_of(&ctx); let base = ci_href(&title); let page = page_from_query(cx); @@ -1743,7 +1747,9 @@ async fn runs_split( }, href: row_href(run.number), // The list page alone draws no run, so it marks none. - current: if number.is_some() && selected.as_ref().is_some_and(|sel| sel.id == run.id) { + current: if number.is_some() + && selected.as_ref().is_some_and(|sel| sel.id == run.id) + { "true" } else { "false" @@ -1937,8 +1943,16 @@ async fn run_detail( } else { None }; - let gantt = (!jobs.is_empty()) - .then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang, picked)); + let gantt = (!jobs.is_empty()).then(|| { + gantt( + &jobs, + origin_of(run, now), + run_end(run, now), + now, + lang, + picked, + ) + }); let writer = header.writer_csrf.is_some(); let rerunnable = writer && header.reachable; let mut lines = Vec::with_capacity(jobs.len()); @@ -2099,7 +2113,11 @@ async fn run_detail( .map_or(job.name.as_str(), |step| step.name.as_str()) }) }, - &duration_text(lang, Some(run.created_at.as_str()), run.finished_at.as_deref()), + &duration_text( + lang, + Some(run.created_at.as_str()), + run.finished_at.as_deref(), + ), ); Ok(RunDetail { number: run.number, @@ -2181,7 +2199,7 @@ fn query_value(cx: &Cx, key: &str) -> Option { /// The head's one action on the runs list: Run workflow, for a writer. Its form sits in its menu. #[component] -async fn ci_menus(lang: Lang, list: &ListView) -> Result { +async fn ci_menus(cx: &Cx, lang: Lang, list: &ListView) -> Result { Ok(view! { if let Some(form) = list.manual.as_ref() { `: the two sides, then, when either has threads or an open form, a /// full-width row holding them. A hunk header spans the table. #[component] -async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result { +async fn diff_split_line(cx: &Cx, row: SplitRow, lang: Lang, anchored: bool) -> Result { let SplitRow { hunk, left, @@ -752,7 +764,7 @@ async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result`: the line itself, then, when it has threads or an open form, a /// full-width row holding them. #[component] -async fn diff_line(row: DiffRow, lang: Lang) -> Result { +async fn diff_line(cx: &Cx, row: DiffRow, lang: Lang) -> Result { let DiffRow { class, old, @@ -803,7 +815,7 @@ async fn diff_line(row: DiffRow, lang: Lang) -> Result { /// The inline comment form under a line. "Add single comment" posts one comment; the review /// button starts a review, or adds to the pending one. #[component] -async fn inline_comment_form(form: InlineForm, lang: Lang) -> Result { +async fn inline_comment_form(cx: &Cx, form: InlineForm, lang: Lang) -> Result { let InlineForm { action, cancel_href, diff --git a/crates/forge-web/src/views/find.rs b/crates/forge-web/src/views/find.rs index f0adc5c..9cdfb7b 100644 --- a/crates/forge-web/src/views/find.rs +++ b/crates/forge-web/src/views/find.rs @@ -5,6 +5,7 @@ //! word as typed. use topcoat::Result; +use topcoat::context::Cx; use topcoat::view::{View, component, view}; use crate::i18n::Lang; @@ -160,6 +161,7 @@ fn distance(a: &[char], b: &[char]) -> usize { /// searches as you type; an option applies the moment it is ticked. #[component] pub async fn finder_field( + cx: &Cx, lang: Lang, finder: Finder, placeholder: &str, diff --git a/crates/forge-web/src/views/heatmap.rs b/crates/forge-web/src/views/heatmap.rs index 9fda1b4..9aa85a0 100644 --- a/crates/forge-web/src/views/heatmap.rs +++ b/crates/forge-web/src/views/heatmap.rs @@ -8,6 +8,7 @@ //! that day's contributions under the calendar, and clicking the selected day again clears it. use std::collections::HashMap; +use topcoat::context::Cx; use forge_core::store::contributions::{ContributionItem, ContributionKind}; use forge_core::time::stamp_to_unix; @@ -346,6 +347,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec, lang: Lang, diff --git a/crates/forge-web/src/views/mod.rs b/crates/forge-web/src/views/mod.rs index 67ea2ea..adaf4e9 100644 --- a/crates/forge-web/src/views/mod.rs +++ b/crates/forge-web/src/views/mod.rs @@ -23,7 +23,7 @@ use http::header::{ use http::{HeaderValue, Uri}; use sha2::{Digest, Sha256}; use topcoat::Result; -use topcoat::context::{Cx, try_app_context}; +use topcoat::context::{Cx, try_context}; use topcoat::router::request::uri; use topcoat::router::response::{Response, response_headers}; use topcoat::router::{Body, Next, layer}; @@ -495,7 +495,7 @@ struct ProfileCorner { /// waits. Its menu holds the name, notifications with their count, the settings and admin links and /// log out. #[component] -async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result { +async fn profile_corner(cx: &Cx, lang: Lang, corner: ProfileCorner) -> Result { let profile_href = user_href(&corner.username); let profile_label = mi::t(lang, MK::YourProfile); let settings_label = o::t(lang, OK::Settings); @@ -542,6 +542,7 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result /// more stylesheet link to the head (such as a repo's generated label colors). #[component] pub async fn shell( + cx: &Cx, title: &str, viewer: Option<&(User, Session)>, #[default] extra_stylesheet: Option<&str>, @@ -552,7 +553,7 @@ pub async fn shell( // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on // them. Signed-in only. let (unread, inbox, runs) = match viewer { - Some((user, _)) => match try_app_context::(__cx) { + Some((user, _)) => match try_context::(cx) { Some(state) => ( state.store.unread_count(&user.id).await?, state.store.inbox_kind_counts(&user.id).await?, @@ -567,26 +568,26 @@ pub async fn shell( // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes // back to the page it was on. let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); - let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); - let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); + let back = uri(cx).path_and_query().map(|p| p.as_str().to_owned()); + let lang = i18n::lang(cx, viewer.map(|(user, _)| user)); // A signed-in viewer's account preferences, read once for the banner, the tree width and the // profile corner. Signed-out visitors keep theirs in the browser. - let prefs = match (viewer, try_app_context::(__cx)) { + let prefs = match (viewer, try_context::(cx)) { (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?), _ => None, }; - let banner = crate::pages::banner::current(__cx, prefs.as_ref()); + let banner = crate::pages::banner::current(cx, prefs.as_ref()); let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref()); let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); // The admin area and the user settings swap the global links for their own list. Signed-in only. let section = if signed_in { - section_for(lang, uri(__cx).path()) + section_for(lang, uri(cx).path()) } else { None }; - let width = page_width(uri(__cx).path()); - let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user)); + let width = page_width(uri(cx).path()); + let theme_attr = crate::theme::data_theme(cx, viewer.map(|(user, _)| user)); // The relative-time wording and the server's clock, for nav.js to keep `