jmserver/src/cdn/templates.rs

31 lines
722 B
Rust
Raw Normal View History

2021-12-18 21:15:06 +01:00
use askama::Template;
2021-12-29 18:33:31 +01:00
use axum::body::{Bytes, Full};
2021-12-18 21:15:06 +01:00
use axum::http::{Response, StatusCode};
2021-12-29 18:33:31 +01:00
use axum::response::{Html, IntoResponse};
2021-12-18 21:15:06 +01:00
use std::convert::Infallible;
pub struct HtmlTemplate<T>(pub T);
impl<T> IntoResponse for HtmlTemplate<T>
2021-12-29 18:33:31 +01:00
where
T: Template,
2021-12-18 21:15:06 +01:00
{
type Body = Full<Bytes>;
type BodyError = Infallible;
fn into_response(self) -> Response<Self::Body> {
match self.0.render() {
Ok(html) => Html(html).into_response(),
2021-12-29 18:33:31 +01:00
Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "").into_response(),
2021-12-18 21:15:06 +01:00
}
}
}
#[derive(Template)]
#[template(path = "dir.html")]
pub struct DirTemplate {
pub entries: Vec<String>,
pub prefix: String,
pub suffix: String,
2021-12-29 18:33:31 +01:00
}