From c211a975fd0b342ec2485c67caa0e98865bcb6d2 Mon Sep 17 00:00:00 2001 From: Clément Date: Sun, 07 Jun 2026 17:08:41 +0000 Subject: [PATCH] misc: move routes --- crates/knotty-knot/src/main.rs | 2 +- crates/knotty-knot/src/router.rs | 2 +- crates/knotty-knot/src/routes/mod.rs | 9 +++++++++ crates/knotty-knot/src/xrpc/create_repo.rs | 18 ------------------ crates/knotty-knot/src/xrpc/delete_repo.rs | 14 -------------- crates/knotty-knot/src/xrpc/mod.rs | 18 ------------------ crates/knotty-knot/src/xrpc/owner.rs | 14 -------------- crates/knotty-knot/src/routes/xrpc/create_repo.rs | 18 ++++++++++++++++++ crates/knotty-knot/src/routes/xrpc/delete_repo.rs | 14 ++++++++++++++ crates/knotty-knot/src/routes/xrpc/mod.rs | 18 ++++++++++++++++++ crates/knotty-knot/src/routes/xrpc/owner.rs | 14 ++++++++++++++ 11 file(s) changed, 75 insertion(s)(+), 66 deletion(s)(-) diff --git a/crates/knotty-knot/src/main.rs b/crates/knotty-knot/src/main.rs --- a/crates/knotty-knot/src/main.rs +++ b/crates/knotty-knot/src/main.rs @@ -1,8 +1,8 @@ mod error; mod keypair; mod router; +mod routes; mod state; -mod xrpc; use std::path::PathBuf; diff --git a/crates/knotty-knot/src/router.rs b/crates/knotty-knot/src/router.rs --- a/crates/knotty-knot/src/router.rs +++ b/crates/knotty-knot/src/router.rs @@ -6,7 +6,7 @@ pub fn router(state: KnotState) -> Router { let did_doc = state.did_doc.clone(); - crate::xrpc::router() + crate::routes::router() .with_state(state) .merge(did_web::did_web_router(did_doc)) .layer(TraceLayer::new_for_http()) diff --git a/crates/knotty-knot/src/routes/mod.rs b/crates/knotty-knot/src/routes/mod.rs new file mode 100644 --- /dev/null +++ b/crates/knotty-knot/src/routes/mod.rs @@ -0,0 +1,9 @@ +use axum::Router; + +use crate::state::KnotState; + +mod xrpc; + +pub fn router() -> Router { + Router::new().merge(xrpc::router()) +} diff --git a/crates/knotty-knot/src/xrpc/create_repo.rs b/crates/knotty-knot/src/xrpc/create_repo.rs deleted file mode 100644 --- a/crates/knotty-knot/src/xrpc/create_repo.rs +++ /dev/null @@ -1,18 +0,0 @@ -use axum::{extract::State, http::StatusCode}; -use jacquard::api::sh_tangled::repo::create::CreateRequest; -use jacquard_axum::{ExtractXrpc, service_auth::ExtractServiceAuth}; - -use crate::{error::KnotError, state::KnotState}; - -#[axum::debug_handler(state = KnotState)] -pub async fn handler( - State(_state): State, - ExtractServiceAuth(_auth): ExtractServiceAuth, - ExtractXrpc(_req): ExtractXrpc, -) -> Result<(), KnotError> { - Err(KnotError::new( - StatusCode::UNAUTHORIZED, - "cannot create mirrors through tangled directly", - None, - )) -} diff --git a/crates/knotty-knot/src/xrpc/delete_repo.rs b/crates/knotty-knot/src/xrpc/delete_repo.rs deleted file mode 100644 --- a/crates/knotty-knot/src/xrpc/delete_repo.rs +++ /dev/null @@ -1,14 +0,0 @@ -use axum::extract::State; -use jacquard::api::sh_tangled::repo::delete::DeleteRequest; -use jacquard_axum::{ExtractXrpc, service_auth::ExtractServiceAuth}; - -use crate::{error::KnotError, state::KnotState}; - -#[axum::debug_handler(state = KnotState)] -pub async fn handler( - State(_state): State, - ExtractServiceAuth(_auth): ExtractServiceAuth, - ExtractXrpc(_req): ExtractXrpc, -) -> Result<(), KnotError> { - Err(KnotError::not_implemented()) -} diff --git a/crates/knotty-knot/src/xrpc/mod.rs b/crates/knotty-knot/src/xrpc/mod.rs deleted file mode 100644 --- a/crates/knotty-knot/src/xrpc/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -use axum::Router; -use jacquard::api::sh_tangled::owner::OwnerRequest; -use jacquard::api::sh_tangled::repo::create::CreateRequest; -use jacquard::api::sh_tangled::repo::delete::DeleteRequest; -use jacquard_axum::IntoRouter; - -use crate::state::KnotState; - -mod create_repo; -mod delete_repo; -mod owner; - -pub fn router() -> Router { - Router::new() - .merge(OwnerRequest::into_router(owner::handler)) - .merge(CreateRequest::into_router(create_repo::handler)) - .merge(DeleteRequest::into_router(delete_repo::handler)) -} diff --git a/crates/knotty-knot/src/xrpc/owner.rs b/crates/knotty-knot/src/xrpc/owner.rs deleted file mode 100644 --- a/crates/knotty-knot/src/xrpc/owner.rs +++ /dev/null @@ -1,14 +0,0 @@ -use axum::{Json, extract::State}; -use jacquard::api::sh_tangled::owner::OwnerOutput; - -use crate::{error::KnotError, state::KnotState}; - -#[axum::debug_handler(state = KnotState)] -pub async fn handler( - State(state): State, -) -> Result>, KnotError> { - Ok(Json(OwnerOutput { - owner: state.owner, - extra_data: Default::default(), - })) -} diff --git a/crates/knotty-knot/src/routes/xrpc/create_repo.rs b/crates/knotty-knot/src/routes/xrpc/create_repo.rs new file mode 100644 --- /dev/null +++ b/crates/knotty-knot/src/routes/xrpc/create_repo.rs @@ -0,0 +1,18 @@ +use axum::{extract::State, http::StatusCode}; +use jacquard::api::sh_tangled::repo::create::CreateRequest; +use jacquard_axum::{ExtractXrpc, service_auth::ExtractServiceAuth}; + +use crate::{error::KnotError, state::KnotState}; + +#[axum::debug_handler(state = KnotState)] +pub async fn handler( + State(_state): State, + ExtractServiceAuth(_auth): ExtractServiceAuth, + ExtractXrpc(_req): ExtractXrpc, +) -> Result<(), KnotError> { + Err(KnotError::new( + StatusCode::UNAUTHORIZED, + "cannot create mirrors through tangled directly", + None, + )) +} diff --git a/crates/knotty-knot/src/routes/xrpc/delete_repo.rs b/crates/knotty-knot/src/routes/xrpc/delete_repo.rs new file mode 100644 --- /dev/null +++ b/crates/knotty-knot/src/routes/xrpc/delete_repo.rs @@ -0,0 +1,14 @@ +use axum::extract::State; +use jacquard::api::sh_tangled::repo::delete::DeleteRequest; +use jacquard_axum::{ExtractXrpc, service_auth::ExtractServiceAuth}; + +use crate::{error::KnotError, state::KnotState}; + +#[axum::debug_handler(state = KnotState)] +pub async fn handler( + State(_state): State, + ExtractServiceAuth(_auth): ExtractServiceAuth, + ExtractXrpc(_req): ExtractXrpc, +) -> Result<(), KnotError> { + Err(KnotError::not_implemented()) +} diff --git a/crates/knotty-knot/src/routes/xrpc/mod.rs b/crates/knotty-knot/src/routes/xrpc/mod.rs new file mode 100644 --- /dev/null +++ b/crates/knotty-knot/src/routes/xrpc/mod.rs @@ -0,0 +1,18 @@ +use axum::Router; +use jacquard::api::sh_tangled::owner::OwnerRequest; +use jacquard::api::sh_tangled::repo::create::CreateRequest; +use jacquard::api::sh_tangled::repo::delete::DeleteRequest; +use jacquard_axum::IntoRouter; + +use crate::state::KnotState; + +mod create_repo; +mod delete_repo; +mod owner; + +pub fn router() -> Router { + Router::new() + .merge(OwnerRequest::into_router(owner::handler)) + .merge(CreateRequest::into_router(create_repo::handler)) + .merge(DeleteRequest::into_router(delete_repo::handler)) +} diff --git a/crates/knotty-knot/src/routes/xrpc/owner.rs b/crates/knotty-knot/src/routes/xrpc/owner.rs new file mode 100644 --- /dev/null +++ b/crates/knotty-knot/src/routes/xrpc/owner.rs @@ -0,0 +1,14 @@ +use axum::{Json, extract::State}; +use jacquard::api::sh_tangled::owner::OwnerOutput; + +use crate::{error::KnotError, state::KnotState}; + +#[axum::debug_handler(state = KnotState)] +pub async fn handler( + State(state): State, +) -> Result>, KnotError> { + Ok(Json(OwnerOutput { + owner: state.owner, + extra_data: Default::default(), + })) +} -- tangled.sh