//! User embed handlers: tip button. use axum::{ extract::{Path, State}, response::{IntoResponse, Response}, }; use crate::{ config::Config, db::{self, Username}, error::{AppError, Result}, }; use sqlx::PgPool; use super::item::set_embed_headers; #[tracing::instrument(skip_all, name = "embed::tip_button")] /// GET /embed/u/{username}/tip pub(super) async fn tip_button( State(db): State, State(config): State, Path(username): Path, ) -> Result { let username = Username::new(&username).map_err(|_| AppError::NotFound)?; let user = db::users::get_user_by_username(&db, &username) .await? .ok_or(AppError::NotFound)?; if user.is_suspended() || user.is_deactivated() || !user.tips_enabled { return Err(AppError::NotFound); } let display_name = user .display_name .as_deref() .unwrap_or(&user.username) .to_string(); let tip_url = format!("{}/u/{}/tip", config.host_url, user.username); let mut response = crate::templates::EmbedTipButtonTemplate { display_name, username: user.username.to_string(), tip_url, avatar_url: user.avatar_url, theme_css: crate::templates::embed_theme_css(), geometry_css: crate::templates::EMBED_GEOMETRY_CSS, } .into_response(); set_embed_headers(&mut response); Ok(response) }