Refactor - use better style

This commit is contained in:
Ivan 2024-08-02 13:29:20 +02:00
parent 85a81c55f6
commit 970bdb8652

View file

@ -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",
)
})
} }