use axum::response::{Html, IntoResponse}; use serde::{Deserialize, Serialize}; use tower_cookies::{Cookie, Cookies}; use crate::svc::auth::{AuthError, Claims}; mod html; pub mod servek; #[derive(Debug, Clone, Serialize)] struct Timeline { pub show_postbox: bool, pub notes: Vec, } #[derive(Debug, Clone, Serialize)] struct Note { pub profile: Box, pub content: Option, } impl Note { fn new(profile: Box, content: Option) -> Self { Self { profile, content } } } #[derive(Debug, Clone, Serialize)] struct Profile { pub display_name: String, pub username: String, pub avatar_url: String, } impl Profile { fn new(username: String) -> Self { let display_name = username .strip_prefix('@') .unwrap() .split_once('@') .unwrap() .0 .to_string(); Profile { display_name, username, avatar_url: "/favicon.svg".to_string(), } } } #[derive(Debug, Clone, Serialize)] struct Notification { pub message: String, pub tag_name: String, } #[derive(Debug, Clone, Deserialize)] pub struct LoginRequest { pub username: String, pub password: String, } #[derive(Debug, Clone, Deserialize)] pub struct CreateProfileRequest { pub username: String, pub password: String, pub email: String, } // pub enum HtmlOrRedirect { // Html(Html), // Redirect(()), // } #[derive(Debug, Clone, Serialize)] pub struct Redirect { pub location: String, } #[derive(Debug, Clone, Serialize)] pub enum NavType { LoggedIn, LoggedOut, } impl From> for NavType { fn from(claims: Result) -> Self { if claims.map(|c| c.expired()).unwrap_or(true) { NavType::LoggedOut } else { NavType::LoggedIn } } } impl From for NavType { fn from(c: Claims) -> Self { if c.expired() { NavType::LoggedOut } else { NavType::LoggedIn } } } #[derive(Debug, Clone, Serialize)] pub struct WithNav { pub nav_type: NavType, pub obj: T, } impl WithNav { pub fn new(obj: T, nav_type: NavType) -> WithNav { WithNav { nav_type, obj } } } impl Into for WithNav where T: Serialize, { fn into(self) -> serde_json::Value { serde_json::json!(self) } }