this repo has no description
1use crate::state::AppState; 2use axum::{Json, extract::State, http::StatusCode, response::IntoResponse}; 3use serde_json::json; 4use tracing::error; 5 6fn get_available_comms_channels() -> Vec<&'static str> { 7 let mut channels = vec!["email"]; 8 if std::env::var("DISCORD_WEBHOOK_URL").is_ok() { 9 channels.push("discord"); 10 } 11 if std::env::var("TELEGRAM_BOT_TOKEN").is_ok() { 12 channels.push("telegram"); 13 } 14 if std::env::var("SIGNAL_CLI_PATH").is_ok() && std::env::var("SIGNAL_SENDER_NUMBER").is_ok() { 15 channels.push("signal"); 16 } 17 channels 18} 19 20pub async fn robots_txt() -> impl IntoResponse { 21 ( 22 StatusCode::OK, 23 [("content-type", "text/plain")], 24 "# Hello!\n\n# Crawling the public API is allowed\nUser-agent: *\nAllow: /\n", 25 ) 26} 27pub async fn describe_server() -> impl IntoResponse { 28 let pds_hostname = std::env::var("PDS_HOSTNAME").unwrap_or_else(|_| "localhost".to_string()); 29 let domains_str = 30 std::env::var("AVAILABLE_USER_DOMAINS").unwrap_or_else(|_| pds_hostname.clone()); 31 let domains: Vec<&str> = domains_str.split(',').map(|s| s.trim()).collect(); 32 let invite_code_required = std::env::var("INVITE_CODE_REQUIRED") 33 .map(|v| v == "true" || v == "1") 34 .unwrap_or(false); 35 Json(json!({ 36 "availableUserDomains": domains, 37 "inviteCodeRequired": invite_code_required, 38 "did": format!("did:web:{}", pds_hostname), 39 "version": env!("CARGO_PKG_VERSION"), 40 "availableCommsChannels": get_available_comms_channels() 41 })) 42} 43pub async fn health(State(state): State<AppState>) -> impl IntoResponse { 44 match sqlx::query!("SELECT 1 as one").fetch_one(&state.db).await { 45 Ok(_) => (StatusCode::OK, "OK"), 46 Err(e) => { 47 error!("Health check failed: {:?}", e); 48 (StatusCode::SERVICE_UNAVAILABLE, "Service Unavailable") 49 } 50 } 51}