This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.9 kB View raw
1use reqwest::Client; 2use tracing::{info, warn, error}; 3use std::env; 4 5pub fn ensure_https(url: &str) -> String { 6 if !url.starts_with("http://") && !url.starts_with("https://") { 7 return format!("https://{}", url); 8 } 9 if let Some(stripped) = url.strip_prefix("http://") { 10 return format!("https://{}", stripped); 11 } 12 url.to_string() 13} 14 15pub async fn is_endpoint_alive(url: &str) -> bool { 16 let health_url = format!("{}/xrpc/_health", url.trim_end_matches('/')); 17 let client = Client::new(); 18 match client.get(&health_url).timeout(std::time::Duration::from_secs(5)).send().await { 19 Ok(response) => { 20 if response.status().is_success() { 21 info!("Endpoint {} is alive and healthy.", url); 22 true 23 } else { 24 warn!("Endpoint {} is not responding correctly: {}", url, response.status()); 25 false 26 } 27 } 28 Err(e) => { 29 error!("Health check failed for {}: {}", health_url, e); 30 false 31 } 32 } 33} 34 35pub struct EnvVars { 36 pub endpoint: String, 37 pub handle: String, 38 pub password: String, 39 pub did: String, 40 pub update_banner: bool, 41} 42 43pub fn validate_environment_variables() -> Option<EnvVars> { 44 let endpoint = env::var("ENDPOINT").ok(); 45 let handle = env::var("HANDLE").ok(); 46 let password = env::var("PASSWORD").ok(); 47 let did = env::var("DID").ok(); 48 let update_banner = env::var("UPDATE_BANNER").unwrap_or_else(|_| "false".to_string()).to_lowercase() == "true"; 49 50 if let (Some(endpoint), Some(handle), Some(password), Some(did)) = (endpoint, handle, password, did) { 51 Some(EnvVars { 52 endpoint, 53 handle, 54 password, 55 did, 56 update_banner, 57 }) 58 } else { 59 error!("Missing environment variables. Ensure ENDPOINT, HANDLE, PASSWORD, and DID are set."); 60 None 61 } 62}