use axum::Router; use axum::middleware::from_fn_with_state; use axum::routing::{delete, get, patch, post, put}; use crate::features::RepoService; use jwt::inject_jwt_ctx; use rate_limit::ratelimit; pub fn router(svc: RepoService) -> Router { let protected: Router = Router::new() .route("/repos", post(super::lifecycle::create::handler)) .route("/repos", get(super::lifecycle::list::handler)) .route( "/repo/:channel_id/:repo_id", get(super::lifecycle::get::handler) .patch(super::lifecycle::update::handler) .delete(super::lifecycle::delete::handler), ) .route( "/repo/:channel_id/:repo_id/transfer", post(super::lifecycle::transfer::handler), ) .route( "/repo/:channel_id/:repo_id/archive", post(super::lifecycle::archive::handler), ) .route( "/repo/:channel_id/:repo_id/rename", post(super::lifecycle::rename::handler), ) .route( "/repo/:channel_id/:repo_id/forks", post(super::lifecycle::fork::handler), ) .route( "/repo/:channel_id/:repo_id/generate", post(super::lifecycle::generate::handler), ) .route( "/repo/:channel_id/:repo_id/branches", get(super::branch::list::handler).post(super::branch::create::handler), ) .route( "/repo/:channel_id/:repo_id/branches/:name", get(super::branch::get::handler) .put(super::branch::update::handler) .delete(super::branch::delete::handler), ) .route( "/repo/:channel_id/:repo_id/branches/:name/rename", patch(super::branch::rename::handler), ) .route( "/repo/:channel_id/:repo_id/merge-upstream", post(super::branch::merge_upstream::handler), ) .route( "/repo/:channel_id/:repo_id/branch_protections", get(super::branch_protection::list::handler) .post(super::branch_protection::create::handler), ) .route( "/repo/:channel_id/:repo_id/branch_protections/priority", post(super::branch_protection::priority::handler), ) .route( "/repo/:channel_id/:repo_id/branch_protections/:policy_id", get(super::branch_protection::get::handler) .patch(super::branch_protection::edit::handler) .delete(super::branch_protection::delete::handler), ) .route( "/repo/:channel_id/:repo_id/tags", get(super::tag::list::handler).post(super::tag::create::handler), ) .route( "/repo/:channel_id/:repo_id/tags/:name", get(super::tag::get::handler).delete(super::tag::delete::handler), ) .route( "/repo/:channel_id/:repo_id/tag_protections", get(super::tag_protection::list::handler).post(super::tag_protection::create::handler), ) .route( "/repo/:channel_id/:repo_id/tag_protections/:policy_id", get(super::tag_protection::get::handler) .patch(super::tag_protection::edit::handler) .delete(super::tag_protection::delete::handler), ) .route( "/repo/:channel_id/:repo_id/releases", get(super::release::list::handler).post(super::release::create::handler), ) .route( "/repo/:channel_id/:repo_id/releases/latest", get(super::release::latest::handler), ) .route( "/repo/:channel_id/:repo_id/releases/tags/:tag", get(super::release::by_tag::handler).delete(super::release::delete_by_tag::handler), ) .route( "/repo/:channel_id/:repo_id/releases/:release_id", get(super::release::get::handler) .patch(super::release::edit::handler) .delete(super::release::delete::handler), ) .route( "/repo/:channel_id/:repo_id/collaborators", get(super::collab::list::handler), ) .route( "/repo/:channel_id/:repo_id/collaborators/:user_id", get(super::collab::is::handler) .put(super::collab::add::handler) .delete(super::collab::delete::handler), ) .route( "/repo/:channel_id/:repo_id/collaborators/:user_id/permission", get(super::collab::permission::handler), ) .route( "/repo/:channel_id/:repo_id/keys", get(super::deploy_key::list::handler).post(super::deploy_key::create::handler), ) .route( "/repo/:channel_id/:repo_id/keys/:key_id", get(super::deploy_key::get::handler).delete(super::deploy_key::delete::handler), ) .route( "/repo/:channel_id/:repo_id/topics", get(super::topic::list::handler).put(super::topic::update::handler), ) .route( "/repo/:channel_id/:repo_id/topics/:topic", put(super::topic::add::handler).delete(super::topic::delete::handler), ) .route("/topics/search", get(super::topic::search::handler)) .route( "/repo/:channel_id/:repo_id/statuses/:sha", get(super::commit_status::list::handler).post(super::commit_status::create::handler), ) .route( "/repo/:channel_id/:repo_id/commits/:ref/statuses", get(super::commit_status::list_by_ref::handler), ) .route( "/repo/:channel_id/:repo_id/commits/:ref/status", get(super::commit_status::combined::handler), ) .route( "/repo/:channel_id/:repo_id/subscribers", get(super::subscriber::list::handler), ) .route( "/repo/:channel_id/:repo_id/contents", get(super::contents::get_list::handler), ) .route( "/repo/:channel_id/:repo_id/contents/change", post(super::contents::change_files::handler), ) .route( "/repo/:channel_id/:repo_id/diffpatch", post(super::contents::diff_patch::handler), ) .route( "/repo/:channel_id/:repo_id/contents/*path", get(super::contents::get::handler) .post(super::contents::create::handler) .put(super::contents::update::handler) .delete(super::contents::delete::handler), ) .route( "/repo/:channel_id/:repo_id/archive/:archive_format/:ref_name", get(super::archive::get::handler), ) .route( "/repo/:channel_id/:repo_id/compare/*spec", get(super::compare::compare::handler), ) .route( "/repo/:channel_id/:repo_id/git/refs", get(super::git_ref::refs::handler), ) .route( "/repo/:channel_id/:repo_id/git/refs/*filter", get(super::git_ref::refs_filter::handler), ) .route( "/repo/:channel_id/:repo_id/git/commits/*sha", get(super::git_ref::commit::handler), ) .route( "/repo/:channel_id/:repo_id/git/tags/*sha", get(super::git_ref::annotated_tag::handler), ) .route( "/repo/:channel_id/:repo_id/git/trees/*sha", get(super::git_ref::tree::handler), ) .route( "/repo/:channel_id/:repo_id/git/blobs/*sha", get(super::git_ref::blob::handler), ) .route( "/repo/:channel_id/:repo_id/git/notes/*sha", get(super::git_ref::notes::handler), ) .route( "/repo/:channel_id/:repo_id/sync", get(super::sync::get::handler), ) .route( "/repo/:channel_id/:repo_id/sync/run", post(super::sync::run::handler), ) .route("/repos/search", get(super::extras::search::handler)) .route("/repositories/:id", get(super::extras::repo_by_id::handler)) .route( "/repo/:channel_id/:repo_id/avatar", post(super::extras::avatar::post_handler).delete(super::extras::avatar::delete_handler), ) .route( "/repo/:channel_id/:repo_id/issue_templates", get(super::extras::issue_template::handler), ) .route( "/repo/:channel_id/:repo_id/issue_config", get(super::extras::repo_extra::get_handler), ) .route( "/repo/:channel_id/:repo_id/issue_config/validate", get(super::extras::repo_extra::validate_handler), ) .route( "/repo/:channel_id/:repo_id/languages", get(super::extras::language::handler), ) .route( "/repo/:channel_id/:repo_id/licenses", get(super::extras::license::handler), ) .route( "/repo/:channel_id/:repo_id/stargazers", get(super::extras::stargazer::handler), ) .route( "/repo/:channel_id/:repo_id/assignees/:assignee", get(super::extras::assigns::check_handler), ) .route( "/repo/:channel_id/:repo_id/reviewers", get(super::extras::reviews::handler), ) .route( "/repo/:channel_id/:repo_id/new_pin_allowed", get(super::extras::pin::handler), ) .route( "/repo/:channel_id/:repo_id/file-contents", get(super::extras::file_contents::get_handler) .post(super::extras::file_contents::post_handler), ) .route( "/repo/:channel_id/:repo_id/contents-ext", get(super::extras::contents_ext::list_handler), ) .route( "/repo/:channel_id/:repo_id/contents-ext/*path", get(super::extras::contents_ext::get_handler), ) .route( "/repo/:channel_id/:repo_id/raw/*filepath", get(super::extras::raw::handler), ) .route( "/repo/:channel_id/:repo_id/media/*filepath", get(super::extras::media::handler), ) .route( "/repo/:channel_id/:repo_id/editorconfig/*filename", get(super::extras::editorconfig::handler), ) .route( "/repo/:channel_id/:repo_id/commits", get(super::extras::commits::list_handler), ) .route( "/repo/:channel_id/:repo_id/git/commits/*sha", get(super::extras::commits::get_handler), ) .route( "/repo/:channel_id/:repo_id/git/commits/*sha_diff", get(super::extras::commits::diff_handler), ) .route( "/repo/:channel_id/:repo_id/commits/:ref/statuses", get(super::extras::commit_status_ref::list_by_ref_handler), ) .route( "/repo/:channel_id/:repo_id/commits/:ref/status", get(super::extras::commit_status_ref::combined_handler), ) .route( "/repo/:channel_id/:repo_id/forks", get(super::extras::fork::list_handler), ) .route( "/repo/:channel_id/:repo_id/subscription", get(super::extras::subscription::get_handler) .put(super::extras::subscription::put_handler) .delete(super::extras::subscription::delete_handler), ) .route( "/repo/:channel_id/:repo_id/signing-key.gpg", get(super::extras::signing_key::gpg_handler), ) .route( "/repo/:channel_id/:repo_id/signing-key.pub", get(super::extras::signing_key::ssh_handler), ) .route( "/repo/:channel_id/:repo_id/releases/:release_id/assets", get(super::extras::release_attachment::list_handler), ) .route( "/repo/:channel_id/:repo_id/releases/:release_id/assets/:attachment_id", get(super::extras::release_attachment::get_handler), ) .layer(from_fn_with_state( svc.clone(), inject_jwt_ctx::, )); Router::new() .merge(protected) .layer(from_fn_with_state(svc.clone(), ratelimit::)) .with_state(svc) }