♻️ refactor: flatten out indentation
parent
ac289e18f7
commit
e5bf5f7d1f
|
@ -119,6 +119,8 @@ async fn serve_file (
|
||||||
)
|
)
|
||||||
-> Result <Response, FileServerError>
|
-> Result <Response, FileServerError>
|
||||||
{
|
{
|
||||||
|
use range::Parsed::*;
|
||||||
|
|
||||||
let file_md = file.metadata ().await.map_err (FileServerError::CantGetFileMetadata)?;
|
let file_md = file.metadata ().await.map_err (FileServerError::CantGetFileMetadata)?;
|
||||||
|
|
||||||
#[cfg (unix)]
|
#[cfg (unix)]
|
||||||
|
@ -134,41 +136,40 @@ async fn serve_file (
|
||||||
|
|
||||||
let range_header = headers.get ("range").and_then (|v| std::str::from_utf8 (v).ok ());
|
let range_header = headers.get ("range").and_then (|v| std::str::from_utf8 (v).ok ());
|
||||||
|
|
||||||
Ok (match range::check (range_header, file_len) {
|
let range = match range::check (range_header, file_len) {
|
||||||
range::Parsed::NotSatisfiable (file_len) => Response::RangeNotSatisfiable (file_len),
|
NotSatisfiable (file_len) => return Ok (Response::RangeNotSatisfiable (file_len)),
|
||||||
range::Parsed::Valid (range) => {
|
Valid (range) => range,
|
||||||
if uri.query () == Some ("as_markdown") {
|
};
|
||||||
const MAX_BUF_SIZE: u32 = 1_000_000;
|
|
||||||
|
|
||||||
if range.range_requested {
|
if uri.query () == Some ("as_markdown") {
|
||||||
return Ok (Response::InvalidQuery);
|
const MAX_BUF_SIZE: u32 = 1_000_000;
|
||||||
}
|
|
||||||
|
|
||||||
if file_len > MAX_BUF_SIZE.into () {
|
if range.range_requested {
|
||||||
Response::MarkdownErr (markdown::Error::TooBig)
|
return Ok (Response::InvalidQuery);
|
||||||
}
|
}
|
||||||
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) {
|
if file_len > MAX_BUF_SIZE.into () {
|
||||||
Ok (x) => Response::MarkdownPreview (x),
|
return Ok (Response::MarkdownErr (markdown::Error::TooBig));
|
||||||
Err (x) => Response::MarkdownErr (x),
|
}
|
||||||
}
|
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?;
|
||||||
else {
|
buffer.truncate (bytes_read);
|
||||||
let file = file.into ();
|
|
||||||
|
|
||||||
Response::ServeFile (ServeFileParams {
|
return Ok (match render_styled (&buffer) {
|
||||||
file,
|
Ok (x) => Response::MarkdownPreview (x),
|
||||||
send_body,
|
Err (x) => Response::MarkdownErr (x),
|
||||||
range,
|
});
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
let file = file.into ();
|
||||||
|
|
||||||
|
Ok (Response::ServeFile (ServeFileParams {
|
||||||
|
file,
|
||||||
|
send_body,
|
||||||
|
range,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve_api (
|
async fn serve_api (
|
||||||
|
|
Loading…
Reference in New Issue