Refactor - use better style
This commit is contained in:
parent
85a81c55f6
commit
970bdb8652
1 changed files with 14 additions and 19 deletions
|
|
@ -331,23 +331,18 @@ fn torrent_file_mime_type(
|
|||
info: &TorrentMetaV1Info<ByteBufOwned>,
|
||||
file_idx: usize,
|
||||
) -> Result<&'static str> {
|
||||
let file_name = info
|
||||
.iter_filenames_and_lengths()?
|
||||
.enumerate()
|
||||
.find_map(|(idx, (f, _))| {
|
||||
if idx == file_idx {
|
||||
f.iter_components()
|
||||
.last()
|
||||
.and_then(|r| r.ok())
|
||||
.and_then(|s| mime_guess::from_path(s).first_raw())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
file_name.ok_or_else(|| {
|
||||
ApiError::new_from_text(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"cannot determine mime type for file",
|
||||
)
|
||||
})
|
||||
info.iter_filenames_and_lengths()?
|
||||
.nth(file_idx)
|
||||
.and_then(|(f, _)| {
|
||||
f.iter_components()
|
||||
.last()
|
||||
.and_then(|r| r.ok())
|
||||
.and_then(|s| mime_guess::from_path(s).first_raw())
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
ApiError::new_from_text(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"cannot determine mime type for file",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue