ctb_io_webui/
routes.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Defines the web routes for the application.
21
22use axum::{Router, routing::get, routing::post};
23
24use crate::AppState;
25#[expect(
26    clippy::wildcard_imports,
27    reason = "controllers glob import pattern"
28)]
29use crate::controllers::*;
30use crate::debug;
31
32pub fn build_routes(state: AppState) -> Router {
33    debug!("Building router");
34    // Build router
35    Router::new()
36        // --- web controller routes ---
37        .route("/", get(web::get_index))
38        .route("/robots.txt", get(web::robots_txt))
39        .route("/security.txt", get(web::security_txt))
40        .route("/.well-known/security.txt", get(web::security_txt))
41        .route("/llms.txt", get(web::llms_txt))
42        .route("/privacy-policy", get(web::privacy_policy))
43        .route("/security-report-policy", get(web::security_report_policy))
44        .route("/subscribe", get(web::subscribe_newsletter))
45        .route(
46            "/home/subscribe",
47            get(web::subscribe_account).post(web::post_subscribe_account),
48        )
49        // --- newsletter controller routes ---
50        .route("/newsletters", get(newsletter::get_newsletters_intro))
51        .route(
52            "/newsletters/newsletters.{format}",
53            get(newsletter::get_newsletters_syndication),
54        )
55        .route("/newsletters/{date}", get(newsletter::get_newsletter))
56        // --- auth controller routes ---
57        .route("/login", get(auth::get_login).post(auth::post_login))
58        .route("/login-password", post(auth::post_login_password))
59        .route("/registration", post(auth::post_registration))
60        .route("/logout", get(auth::get_logout))
61        .route("/rename", get(auth::get_rename).post(auth::post_rename))
62        // --- pc_settings controller routes ---
63        .route(
64            "/pc-settings",
65            get(pc_settings::get_public_pc_settings)
66                .post(pc_settings::post_public_pc_settings),
67        )
68        // --- app controller routes ---
69        .route("/home", get(app::get_home))
70        // --- v86 controller routes ---
71        .route("/v86", get(v86::get_v86))
72        .route("/v86/{profile}", get(v86::get_v86_profile))
73        .route("/vendor/v86/v86.css", get(v86::get_v86_css))
74        // --- tool routes ---
75        .route("/tools/eite-edit-tool", get(eite::get_edit_tool))
76        .route("/tools/calculator", get(calculator::get_calculator))
77        .route(
78            "/tools/center-of-gravity",
79            get(calculator::get_center_of_gravity),
80        )
81        // --- consolidated RPC controller route ---
82        .route("/api/rpc/{service}", post(rpc::post_rpc_call))
83        // --- admin controller routes ---
84        .route("/debug/db-tables", get(debug::get_db_tables))
85        .route(
86            "/debug/db-tables/{table_name}",
87            get(debug::get_db_table_data),
88        )
89        // --- search controller routes ---
90        .route("/search", get(search::get_index))
91        // --- graph controller routes ---
92        .route("/nodes", get(graph::get_nodes_index))
93        .route("/nodes/view", get(graph::get_nodes_view))
94        .route(
95            "/nodes/create",
96            get(graph::get_nodes_create).post(graph::post_nodes_create),
97        )
98        .route(
99            "/nodes/upload",
100            get(graph::get_nodes_upload).post(graph::post_nodes_upload),
101        )
102        .route(
103            "/nodes/{graph_id}/{node_id}/publish",
104            get(graph::get_nodes_publish).post(graph::post_nodes_publish),
105        )
106        .route(
107            "/nodes/{graph_id}/{node_id}/publish-as",
108            get(graph::get_nodes_publish_as),
109        )
110        .route("/nodes/download", get(graph::get_nodes_download))
111        .route(
112            "/nodes/{graph_id}/{node_id}/download",
113            get(graph::get_nodes_download_path),
114        )
115        .route(
116            "/api/nodes/{graph_id}/{node_id}/publish",
117            post(graph::post_publish_node),
118        )
119        .route(
120            "/api/nodes/{graph_id}/{node_id}/checksum",
121            get(graph::get_node_checksum),
122        )
123        // --- releases controller routes ---
124        .route(
125            "/releases/{platform}/latest.json",
126            get(releases::get_latest_manifest),
127        )
128        // NOTE: axum/matchit only allows one parameter per path segment.
129        // Routes like `/{version}.json` or `/{hash}.json` are invalid. We keep
130        // those URL shapes by routing through dispatchers.
131        .route(
132            "/releases/{platform}/{*artifact}",
133            get(releases::get_platform_dispatch),
134        )
135        // Chunk routes use two-level prefix: /releases/chunks/{prefix1}/{prefix2}/{hash}
136        .route(
137            "/releases/chunks/{prefix1}/{prefix2}/{*tail}",
138            get(releases::get_chunks_dispatch),
139        )
140        .route("/releases/public-key", get(releases::get_public_key))
141        .route(
142            "/releases/public-key.pem",
143            get(releases::get_public_key_pem),
144        )
145        // --- Sync controller routes ---
146        .route("/api/tokens/issue", post(sync::post_tokens_issue))
147        .route("/api/sync/start", post(sync::post_sync_start))
148        .route("/api/sync/reserve-ids", post(sync::post_reserve_ids))
149        .route("/api/sync/chunks", post(sync::post_upload_chunks))
150        .route("/api/sync/chunks/{hash}", get(sync::get_download_chunks))
151        .route("/api/user/register", post(auth::post_api_user_register))
152        .route(
153            "/api/sync/setup-global-user",
154            post(admin::post_setup_global_user),
155        )
156        // --- CRLite controller routes ---
157        .route("/api/crlite/status", get(crlite::get_crlite_status))
158        .route("/crlite/manifest.json", get(crlite::get_crlite_manifest))
159        .route(
160            "/crlite/artifacts/{*path}",
161            get(crlite::get_crlite_artifact),
162        )
163        // --- updates controller routes ---
164        .route("/api/update-status", get(updates::get_update_status))
165        // --- environment IP controller route ---
166        .route("/api/ip", get(web::get_client_ip))
167        // --- base controller routes (docs, css, static, fallback) ---
168        .route("/app.css", get(base::get_app_css))
169        .route("/docs", get(base::get_doc_index))
170        .route("/docs/{*path}", get(base::get_doc_page))
171        .route("/src.zip", get(base::get_src_zip_redirect))
172        .route("/src.tar.gz", get(base::get_src_tar_gz))
173        .route(
174            "/dependencies.zip",
175            get(base::get_dependencies_zip_redirect),
176        )
177        .route("/dependencies.tar.gz", get(base::get_dependencies_tar_gz))
178        .route(
179            "/releases/src/{filename}",
180            get(base::get_versioned_release_source),
181        )
182        .route("/installer-linux-x64", get(base::get_installer_linux_x64))
183        .route("/installer-linux-x86", get(base::get_installer_linux_x86))
184        .route(
185            "/installer-windows-x64",
186            get(base::get_installer_windows_x64),
187        )
188        .route(
189            "/installer-freebsd-x64",
190            get(base::get_installer_freebsd_x64),
191        )
192        // static files or 404 page fallback
193        .fallback(get(base::static_or_404))
194        .with_state(state)
195}
196
197pub fn base_url() -> String {
198    // TODO: Load from settings. See webui.rs for how to do this
199    "http://localhost:8080".to_string()
200}