2025-12-22 20:10:17 +01:00
|
|
|
use crate::http::admin;
|
2026-03-23 17:27:36 +01:00
|
|
|
use crate::http::handlers::{
|
|
|
|
|
catalog, file, index, info, manifest, publisher, search, shard, ui, versions,
|
|
|
|
|
};
|
2025-12-22 20:10:17 +01:00
|
|
|
use crate::repo::DepotRepo;
|
2025-12-08 20:11:05 +01:00
|
|
|
use axum::{
|
|
|
|
|
Router,
|
2026-03-15 22:05:13 +01:00
|
|
|
response::Redirect,
|
2025-12-22 20:10:17 +01:00
|
|
|
routing::{get, post},
|
2025-12-08 20:11:05 +01:00
|
|
|
};
|
2025-12-08 20:50:20 +01:00
|
|
|
use std::sync::Arc;
|
2025-12-22 20:10:17 +01:00
|
|
|
use tower_http::trace::TraceLayer;
|
2025-12-08 20:11:05 +01:00
|
|
|
|
2025-12-08 20:50:20 +01:00
|
|
|
pub fn app_router(state: Arc<DepotRepo>) -> Router {
|
2025-12-08 20:11:05 +01:00
|
|
|
Router::new()
|
2026-03-15 22:05:13 +01:00
|
|
|
.route("/", get(|| async { Redirect::permanent("/ui/") }))
|
2026-01-20 17:44:36 +01:00
|
|
|
.route("/versions/0", get(versions::get_versions))
|
2025-12-08 20:11:05 +01:00
|
|
|
.route("/versions/0/", get(versions::get_versions))
|
2025-12-22 20:10:17 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/catalog/1/{filename}",
|
|
|
|
|
get(catalog::get_catalog_v1).head(catalog::get_catalog_v1),
|
|
|
|
|
)
|
2026-02-04 22:39:42 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/catalog/2/catalog.attrs",
|
|
|
|
|
get(shard::get_shard_index).head(shard::get_shard_index),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/{publisher}/catalog/2/{sha256}",
|
|
|
|
|
get(shard::get_shard_blob).head(shard::get_shard_blob),
|
|
|
|
|
)
|
2025-12-22 20:10:17 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/manifest/0/{fmri}",
|
|
|
|
|
get(manifest::get_manifest).head(manifest::get_manifest),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/{publisher}/manifest/1/{fmri}",
|
|
|
|
|
get(manifest::get_manifest).head(manifest::get_manifest),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/{publisher}/file/0/{algo}/{digest}",
|
|
|
|
|
get(file::get_file).head(file::get_file),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/{publisher}/file/1/{algo}/{digest}",
|
|
|
|
|
get(file::get_file).head(file::get_file),
|
|
|
|
|
)
|
2025-12-22 22:42:56 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/file/1/{digest}",
|
|
|
|
|
get(file::get_file_no_algo).head(file::get_file_no_algo),
|
|
|
|
|
)
|
2025-12-08 20:50:20 +01:00
|
|
|
.route("/{publisher}/info/0/{fmri}", get(info::get_info))
|
2025-12-08 21:36:37 +01:00
|
|
|
.route("/{publisher}/publisher/0", get(publisher::get_publisher_v0))
|
2026-01-25 23:17:49 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/publisher/0/",
|
|
|
|
|
get(publisher::get_publisher_v0),
|
|
|
|
|
)
|
2025-12-08 21:36:37 +01:00
|
|
|
.route("/{publisher}/publisher/1", get(publisher::get_publisher_v1))
|
2026-01-25 23:17:49 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/publisher/1/",
|
|
|
|
|
get(publisher::get_publisher_v1),
|
|
|
|
|
)
|
2026-01-20 17:44:36 +01:00
|
|
|
.route("/publisher/0", get(publisher::get_default_publisher_v0))
|
|
|
|
|
.route("/publisher/0/", get(publisher::get_default_publisher_v0))
|
|
|
|
|
.route("/publisher/1", get(publisher::get_default_publisher_v1))
|
|
|
|
|
.route("/publisher/1/", get(publisher::get_default_publisher_v1))
|
2026-01-18 12:29:44 +01:00
|
|
|
.route("/{publisher}/search/0/{token}", get(search::get_search_v0))
|
|
|
|
|
.route("/{publisher}/search/1/{token}", get(search::get_search_v1))
|
2026-03-23 17:27:36 +01:00
|
|
|
.route("/{publisher}/search/1/", post(search::post_search_v1))
|
2026-04-09 22:06:48 +02:00
|
|
|
.route("/search/0/{token}", get(search::get_default_search_v0))
|
|
|
|
|
.route("/search/1/{token}", get(search::get_default_search_v1))
|
|
|
|
|
.route("/search/1/", post(search::post_default_search_v1))
|
2026-03-23 17:27:36 +01:00
|
|
|
.route(
|
|
|
|
|
"/{publisher}/index/0/{command}",
|
|
|
|
|
get(index::get_index_v0),
|
|
|
|
|
)
|
2025-12-09 20:23:00 +01:00
|
|
|
// Admin API over HTTP
|
|
|
|
|
.route("/admin/health", get(admin::health))
|
|
|
|
|
.route("/admin/auth/check", post(admin::auth_check))
|
2026-03-15 21:55:10 +01:00
|
|
|
// Web UI routes
|
|
|
|
|
.route("/ui/", get(ui::ui_index))
|
|
|
|
|
.route("/ui/packages/{publisher}", get(ui::ui_packages))
|
|
|
|
|
.route("/ui/search", get(ui::ui_search))
|
|
|
|
|
.route("/ui/search/results", get(ui::ui_search_results))
|
|
|
|
|
.route("/ui/package/{publisher}/{*fmri}", get(ui::ui_package_detail))
|
|
|
|
|
.route("/ui/p5i", get(ui::ui_p5i_generate))
|
2026-03-15 22:49:33 +01:00
|
|
|
// Embedded static assets
|
|
|
|
|
.route("/ui/static/js/htmx.min.js", get(ui::static_htmx_js))
|
2025-12-22 20:10:17 +01:00
|
|
|
.layer(TraceLayer::new_for_http())
|
2025-12-08 20:50:20 +01:00
|
|
|
.with_state(state)
|
2025-12-08 20:11:05 +01:00
|
|
|
}
|