use crate::server::static_assets::Asset;
use serde::Serialize;
#[derive(Serialize)]
pub struct UiAssetResponse {
pub content: Vec<u8>,
pub mime_type: String,
}
pub fn get_ui_asset(path: &str) -> Option<UiAssetResponse> {
let path = if path.is_empty() || path == "/" {
"index.html"
} else {
path
};
let path = path.trim_start_matches('/');
match Asset::get(path) {
Some(content) => {
let mime = mime_guess::from_path(path).first_or_octet_stream();
Some(UiAssetResponse {
content: content.data.into_owned(),
mime_type: mime.as_ref().to_string(),
})
}
None => {
if let Some(content) = Asset::get("index.html") {
Some(UiAssetResponse {
content: content.data.into_owned(),
mime_type: "text/html".to_string(),
})
} else {
None
}
}
}
}