use activitypub_federation::config::{FederationConfig, FederationMiddleware}; use axum::{Router, routing::get}; use nanoid::nanoid; use stack_up::Environment; use tower_http::trace::TraceLayer; use url::Url; use crate::{error::AppError, server::routes::health_check, state::AppHandle}; pub mod activities; pub mod routes; const ALPHABET: [char; 36] = [ '2', '3', '4', '5', '6', '7', '8', '9', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-', ]; pub fn generate_object_id(domain: &str, env: Environment) -> Result { let id = nanoid!(21, &ALPHABET); Ok(Url::parse(&format!( "{}://{domain}/objects/{id}", match env { Environment::Development => "http", Environment::Production => "https", }, ))?) } pub fn router(state: FederationConfig) -> Router { Router::new() .merge(routes::users::users_router()) .route("/", get(health_check)) .layer(TraceLayer::new_for_http()) .layer(FederationMiddleware::new(state)) } #[cfg(test)] pub(crate) fn test_config() -> stack_up::Configuration { use stack_up::Configuration; let config_path = "sellershut.toml"; let config = config::Config::builder() .add_source(config::File::new(config_path, config::FileFormat::Toml)) .build() .unwrap(); config.try_deserialize::().unwrap() }