♻️ Adding space for a Markdown preview
parent
63abdc3a16
commit
13b816fd6e
|
@ -98,6 +98,8 @@ pub enum StatusCode {
|
|||
NotFound, // 404
|
||||
MethodNotAllowed, // 405
|
||||
RangeNotSatisfiable, // 416
|
||||
|
||||
InternalServerError, // 500
|
||||
}
|
||||
|
||||
impl Default for StatusCode {
|
||||
|
@ -120,6 +122,8 @@ impl From <StatusCode> for hyper::StatusCode {
|
|||
StatusCode::NotFound => Self::NOT_FOUND,
|
||||
StatusCode::MethodNotAllowed => Self::METHOD_NOT_ALLOWED,
|
||||
StatusCode::RangeNotSatisfiable => Self::RANGE_NOT_SATISFIABLE,
|
||||
|
||||
StatusCode::InternalServerError => Self::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,12 +228,15 @@ async fn serve_root (
|
|||
) -> Response
|
||||
{
|
||||
let s = handlebars.render ("file_server_root", &server_info).unwrap ();
|
||||
let body = s.into_bytes ();
|
||||
|
||||
serve_html (s)
|
||||
}
|
||||
|
||||
fn serve_html (s: String) -> Response {
|
||||
let mut resp = Response::default ();
|
||||
resp
|
||||
.header ("content-type".to_string (), "text/html".to_string ().into_bytes ())
|
||||
.body_bytes (body)
|
||||
.body_bytes (s.into_bytes ())
|
||||
;
|
||||
resp
|
||||
}
|
||||
|
@ -259,14 +262,8 @@ async fn serve_dir (
|
|||
entries,
|
||||
server_info,
|
||||
}).unwrap ();
|
||||
let body = s.into_bytes ();
|
||||
|
||||
let mut resp = Response::default ();
|
||||
resp
|
||||
.header ("content-type".to_string (), "text/html".to_string ().into_bytes ())
|
||||
.body_bytes (body)
|
||||
;
|
||||
resp
|
||||
serve_html (s)
|
||||
}
|
||||
|
||||
#[instrument (level = "debug", skip (f))]
|
||||
|
@ -414,6 +411,9 @@ enum InternalResponse {
|
|||
Root,
|
||||
ServeDir (ServeDirParams),
|
||||
ServeFile (ServeFileParams),
|
||||
|
||||
MarkdownError,
|
||||
ServeMarkdownPreview (String),
|
||||
}
|
||||
|
||||
async fn internal_serve_all (
|
||||
|
@ -550,6 +550,8 @@ pub async fn serve_all (
|
|||
range,
|
||||
range_requested,
|
||||
}) => serve_file (file.into_inner (), send_body, range, range_requested).await,
|
||||
MarkdownError => serve_error (StatusCode::InternalServerError, "Error while rendering Markdown preview"),
|
||||
ServeMarkdownPreview (s) => serve_html (s),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue