Add ISO catalog
This commit is contained in:
		@@ -3,6 +3,27 @@ pub use serve_static_debug::{root_index, serve_static_content};
 | 
			
		||||
#[cfg(not(debug_assertions))]
 | 
			
		||||
pub use serve_static_release::{root_index, serve_static_content};
 | 
			
		||||
 | 
			
		||||
/// Static API assets hosting
 | 
			
		||||
pub mod serve_assets {
 | 
			
		||||
    use actix_web::{HttpResponse, web};
 | 
			
		||||
    use rust_embed::RustEmbed;
 | 
			
		||||
 | 
			
		||||
    #[derive(RustEmbed)]
 | 
			
		||||
    #[folder = "assets/"]
 | 
			
		||||
    struct Asset;
 | 
			
		||||
 | 
			
		||||
    /// Serve API assets
 | 
			
		||||
    pub async fn serve_api_assets(file: web::Path<String>) -> HttpResponse {
 | 
			
		||||
        match Asset::get(&file) {
 | 
			
		||||
            None => HttpResponse::NotFound().body("File not found"),
 | 
			
		||||
            Some(asset) => HttpResponse::Ok()
 | 
			
		||||
                .content_type(asset.metadata.mimetype())
 | 
			
		||||
                .body(asset.data),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Web asset hosting placeholder in debug mode
 | 
			
		||||
#[cfg(debug_assertions)]
 | 
			
		||||
mod serve_static_debug {
 | 
			
		||||
    use actix_web::{HttpResponse, Responder};
 | 
			
		||||
@@ -16,6 +37,7 @@ mod serve_static_debug {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Web asset hosting in release mode
 | 
			
		||||
#[cfg(not(debug_assertions))]
 | 
			
		||||
mod serve_static_release {
 | 
			
		||||
    use actix_web::{HttpResponse, Responder, web};
 | 
			
		||||
@@ -23,12 +45,12 @@ mod serve_static_release {
 | 
			
		||||
 | 
			
		||||
    #[derive(RustEmbed)]
 | 
			
		||||
    #[folder = "static/"]
 | 
			
		||||
    struct Asset;
 | 
			
		||||
    struct WebAsset;
 | 
			
		||||
 | 
			
		||||
    fn handle_embedded_file(path: &str, can_fallback: bool) -> HttpResponse {
 | 
			
		||||
        match (Asset::get(path), can_fallback) {
 | 
			
		||||
        match (WebAsset::get(path), can_fallback) {
 | 
			
		||||
            (Some(content), _) => HttpResponse::Ok()
 | 
			
		||||
                .content_type(mime_guess::from_path(path).first_or_octet_stream().as_ref())
 | 
			
		||||
                .content_type(content.metadata.mimetype())
 | 
			
		||||
                .body(content.data.into_owned()),
 | 
			
		||||
            (None, false) => HttpResponse::NotFound().body("404 Not Found"),
 | 
			
		||||
            (None, true) => handle_embedded_file("index.html", false),
 | 
			
		||||
 
 | 
			
		||||
@@ -337,6 +337,11 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
                web::delete().to(api_tokens_controller::delete),
 | 
			
		||||
            )
 | 
			
		||||
            // Static assets
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/assets/{tail:.*}",
 | 
			
		||||
                web::get().to(static_controller::serve_assets::serve_api_assets),
 | 
			
		||||
            )
 | 
			
		||||
            // Static web frontend
 | 
			
		||||
            .route("/", web::get().to(static_controller::root_index))
 | 
			
		||||
            .route(
 | 
			
		||||
                "/{tail:.*}",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user