this repo has no description
1use crate::state::AppState; 2use axum::{ 3 body::Body, 4 extract::State, 5 http::StatusCode, 6 http::header, 7 response::{IntoResponse, Response}, 8}; 9use tracing::error; 10 11pub async fn get_logo(State(state): State<AppState>) -> Response { 12 let logo_cid: Option<String> = match sqlx::query_scalar( 13 "SELECT value FROM server_config WHERE key = 'logo_cid'" 14 ) 15 .fetch_optional(&state.db) 16 .await 17 { 18 Ok(cid) => cid, 19 Err(e) => { 20 error!("DB error fetching logo_cid: {:?}", e); 21 return StatusCode::INTERNAL_SERVER_ERROR.into_response(); 22 } 23 }; 24 25 let cid = match logo_cid { 26 Some(c) if !c.is_empty() => c, 27 _ => return StatusCode::NOT_FOUND.into_response(), 28 }; 29 30 let blob = match sqlx::query!( 31 "SELECT storage_key, mime_type FROM blobs WHERE cid = $1", 32 cid 33 ) 34 .fetch_optional(&state.db) 35 .await 36 { 37 Ok(Some(row)) => row, 38 Ok(None) => return StatusCode::NOT_FOUND.into_response(), 39 Err(e) => { 40 error!("DB error fetching blob: {:?}", e); 41 return StatusCode::INTERNAL_SERVER_ERROR.into_response(); 42 } 43 }; 44 45 match state.blob_store.get(&blob.storage_key).await { 46 Ok(data) => Response::builder() 47 .status(StatusCode::OK) 48 .header(header::CONTENT_TYPE, &blob.mime_type) 49 .header(header::CACHE_CONTROL, "public, max-age=3600") 50 .body(Body::from(data)) 51 .unwrap(), 52 Err(e) => { 53 error!("Failed to fetch logo from storage: {:?}", e); 54 StatusCode::NOT_FOUND.into_response() 55 } 56 } 57}