feat: user avatar as public asset
This commit is contained in:
parent
23f12904cc
commit
07fff532f7
17 changed files with 172 additions and 21 deletions
27
lib/http_server/src/controllers/api/public_assets.rs
Normal file
27
lib/http_server/src/controllers/api/public_assets.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use axum::{extract::{Path, State}, http::{header, HeaderMap, HeaderValue, StatusCode}, response::{Html, IntoResponse}};
|
||||
use kernel::repositories::users::get_user_asset_by_id;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
pub async fn get_user_asset(
|
||||
State(app_state): State<AppState>,
|
||||
Path(asset_id): Path<String>
|
||||
) -> impl IntoResponse {
|
||||
let user_asset = match get_user_asset_by_id(&app_state.db, &asset_id).await {
|
||||
Err(_) => {
|
||||
return (
|
||||
StatusCode::NOT_FOUND,
|
||||
Html("Could not find user asset")
|
||||
).into_response();
|
||||
},
|
||||
Ok(ua) => ua
|
||||
};
|
||||
|
||||
let mut hm = HeaderMap::new();
|
||||
hm.insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_str(&user_asset.mime_type).expect("Constructing header value.")
|
||||
);
|
||||
|
||||
(hm, user_asset.content).into_response()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue