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>,
|
info: &TorrentMetaV1Info<ByteBufOwned>,
|
||||||
file_idx: usize,
|
file_idx: usize,
|
||||||
) -> Result<&'static str> {
|
) -> Result<&'static str> {
|
||||||
let file_name = info
|
info.iter_filenames_and_lengths()?
|
||||||
.iter_filenames_and_lengths()?
|
.nth(file_idx)
|
||||||
.enumerate()
|
.and_then(|(f, _)| {
|
||||||
.find_map(|(idx, (f, _))| {
|
f.iter_components()
|
||||||
if idx == file_idx {
|
.last()
|
||||||
f.iter_components()
|
.and_then(|r| r.ok())
|
||||||
.last()
|
.and_then(|s| mime_guess::from_path(s).first_raw())
|
||||||
.and_then(|r| r.ok())
|
})
|
||||||
.and_then(|s| mime_guess::from_path(s).first_raw())
|
.ok_or_else(|| {
|
||||||
} else {
|
ApiError::new_from_text(
|
||||||
None
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
"cannot determine mime type for file",
|
||||||
});
|
)
|
||||||
file_name.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