diff options
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/server.rs b/src/server.rs index 7ed3f87..dd49a54 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,12 +1,31 @@ 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::{server::routes::health_check, state::AppHandle}; +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<Url, AppError> { + 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<AppHandle>) -> Router { Router::new() .merge(routes::users::users_router()) |