♻️ refactor: flatten out indentation

main
_ 2021-04-03 14:27:17 +00:00
parent ac289e18f7
commit e5bf5f7d1f
1 changed files with 36 additions and 35 deletions

View File

@ -119,6 +119,8 @@ async fn serve_file (
)
-> Result <Response, FileServerError>
{
use range::Parsed::*;
let file_md = file.metadata ().await.map_err (FileServerError::CantGetFileMetadata)?;
#[cfg (unix)]
@ -134,9 +136,11 @@ async fn serve_file (
let range_header = headers.get ("range").and_then (|v| std::str::from_utf8 (v).ok ());
Ok (match range::check (range_header, file_len) {
range::Parsed::NotSatisfiable (file_len) => Response::RangeNotSatisfiable (file_len),
range::Parsed::Valid (range) => {
let range = match range::check (range_header, file_len) {
NotSatisfiable (file_len) => return Ok (Response::RangeNotSatisfiable (file_len)),
Valid (range) => range,
};
if uri.query () == Some ("as_markdown") {
const MAX_BUF_SIZE: u32 = 1_000_000;
@ -145,30 +149,27 @@ async fn serve_file (
}
if file_len > MAX_BUF_SIZE.into () {
Response::MarkdownErr (markdown::Error::TooBig)
return Ok (Response::MarkdownErr (markdown::Error::TooBig));
}
else {
let mut buffer = vec! [0_u8; MAX_BUF_SIZE.try_into ().expect ("Couldn't fit u32 into usize")];
let bytes_read = file.read (&mut buffer).await?;
buffer.truncate (bytes_read);
match render_styled (&buffer) {
return Ok (match render_styled (&buffer) {
Ok (x) => Response::MarkdownPreview (x),
Err (x) => Response::MarkdownErr (x),
});
}
}
}
else {
let file = file.into ();
Response::ServeFile (ServeFileParams {
Ok (Response::ServeFile (ServeFileParams {
file,
send_body,
range,
})
}
},
})
}))
}
async fn serve_api (