63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
use super::{files::get_file_wrapper, templates::ErrorTemplate};
|
|
use rocket::{http::Status, response::content::RawCss};
|
|
use std::borrow::Cow;
|
|
|
|
#[derive(Responder)]
|
|
#[response(status = 200, content_type = "font/woff2")]
|
|
pub struct RawWoff2Font(pub Cow<'static, [u8]>);
|
|
|
|
#[derive(Responder)]
|
|
#[response(status = 200, content_type = "font/woff")]
|
|
pub struct RawWoffFont(pub Cow<'static, [u8]>);
|
|
|
|
#[derive(Responder)]
|
|
pub struct ErrorTemplateResponder<'a> {
|
|
template: ErrorTemplate<'a>,
|
|
}
|
|
|
|
#[get("/css/<style>")]
|
|
pub fn style(style: &str) -> Result<RawCss<String>, Status> {
|
|
let style_file = &get_file_wrapper()?.style;
|
|
let hyperlegible_file = &get_file_wrapper()?.hyperlegible;
|
|
|
|
let style_name = style_file.metadata.get_hash_filename();
|
|
let hyperlegible_name = hyperlegible_file.metadata.get_hash_filename();
|
|
|
|
if style == style_name {
|
|
Ok(RawCss::<String>(style_file.text.clone()))
|
|
} else if style == hyperlegible_name {
|
|
Ok(RawCss::<String>(hyperlegible_file.text.clone()))
|
|
} else {
|
|
Err(Status::NotFound)
|
|
}
|
|
}
|
|
|
|
#[get("/woff2/<font>")]
|
|
pub fn woff2_font(font: &str) -> Result<RawWoff2Font, Status> {
|
|
let latin_file = &get_file_wrapper()?.atkinson_latin_woff2;
|
|
let latin_ext_file = &get_file_wrapper()?.atkinson_latin_ext_woff2;
|
|
|
|
let latin = latin_file.metadata.get_hash_filename();
|
|
let latin_ext = latin_file.metadata.get_hash_filename();
|
|
|
|
if font == latin {
|
|
Ok(RawWoff2Font(latin_file.data.clone()))
|
|
} else if font == latin_ext {
|
|
Ok(RawWoff2Font(latin_ext_file.data.clone()))
|
|
} else {
|
|
Err(Status::NotFound)
|
|
}
|
|
}
|
|
|
|
#[get("/woff/<font>")]
|
|
pub fn woff_font(font: &str) -> Result<RawWoffFont, Status> {
|
|
let all_file = &get_file_wrapper()?.atkinson_all_woff;
|
|
let all = all_file.metadata.get_hash_filename();
|
|
|
|
if font == all {
|
|
Ok(RawWoffFont(all_file.data.clone()))
|
|
} else {
|
|
Err(Status::NotFound)
|
|
}
|
|
}
|