tsk-45: Code formatting
All checks were successful
Rust Build / Rustfmt (pull_request) Successful in 42s
Rust Build / build (pull_request) Successful in 1m8s
Rust Build / Clippy (pull_request) Successful in 1m17s
Rust Build / Test Suite (pull_request) Successful in 59s
Rust Build / Check (pull_request) Successful in 45s
All checks were successful
Rust Build / Rustfmt (pull_request) Successful in 42s
Rust Build / build (pull_request) Successful in 1m8s
Rust Build / Clippy (pull_request) Successful in 1m17s
Rust Build / Test Suite (pull_request) Successful in 59s
Rust Build / Check (pull_request) Successful in 45s
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
/// Gets the file type of a CoverArt given it's path
|
/// Gets the file type of a CoverArt given it's path
|
||||||
pub fn file_type_from_filepath(filepath: &str) -> Result<crate::detection::FileType, std::io::Error> {
|
pub fn file_type_from_filepath(
|
||||||
|
filepath: &str,
|
||||||
|
) -> Result<crate::detection::FileType, std::io::Error> {
|
||||||
match imghdr::from_file(filepath) {
|
match imghdr::from_file(filepath) {
|
||||||
Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}),
|
Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType {
|
||||||
Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType {mime: String::from("image/png"),
|
mime: String::from("image/jpeg"),
|
||||||
file_type: String::from(constants::PNG_TYPE)}),
|
file_type: String::from(constants::JPEG_TYPE),
|
||||||
|
}),
|
||||||
|
Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType {
|
||||||
|
mime: String::from("image/png"),
|
||||||
|
file_type: String::from(constants::PNG_TYPE),
|
||||||
|
}),
|
||||||
Ok(None) => Err(std::io::Error::other("Image file not supported")),
|
Ok(None) => Err(std::io::Error::other("Image file not supported")),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
_ => Err(std::io::Error::other("Image file not supported")),
|
_ => Err(std::io::Error::other("Image file not supported")),
|
||||||
@@ -13,22 +20,25 @@ pub fn file_type_from_filepath(filepath: &str) -> Result<crate::detection::FileT
|
|||||||
/// Gets the file type of a CoverArt given it's data
|
/// Gets the file type of a CoverArt given it's data
|
||||||
pub fn file_type_from_data(data: &Vec<u8>) -> Result<crate::detection::FileType, std::io::Error> {
|
pub fn file_type_from_data(data: &Vec<u8>) -> Result<crate::detection::FileType, std::io::Error> {
|
||||||
match imghdr::from_bytes(data) {
|
match imghdr::from_bytes(data) {
|
||||||
Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}),
|
Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType {
|
||||||
Some(imghdr::Type::Png) => Ok(crate::detection::FileType {mime: String::from("image/png"),
|
mime: String::from("image/jpeg"),
|
||||||
file_type: String::from(constants::PNG_TYPE)}),
|
file_type: String::from(constants::JPEG_TYPE),
|
||||||
|
}),
|
||||||
|
Some(imghdr::Type::Png) => Ok(crate::detection::FileType {
|
||||||
|
mime: String::from("image/png"),
|
||||||
|
file_type: String::from(constants::PNG_TYPE),
|
||||||
|
}),
|
||||||
None => Err(std::io::Error::other("Image file not supported")),
|
None => Err(std::io::Error::other("Image file not supported")),
|
||||||
_ => Err(std::io::Error::other("Image file not supported")),
|
_ => Err(std::io::Error::other("Image file not supported")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub mod constants {
|
pub mod constants {
|
||||||
pub const PNG_TYPE: &str = "png";
|
pub const PNG_TYPE: &str = "png";
|
||||||
pub const JPEG_TYPE: &str = "jpeg";
|
pub const JPEG_TYPE: &str = "jpeg";
|
||||||
pub const JPG_TYPE: &str = "jpg";
|
pub const JPG_TYPE: &str = "jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
@@ -40,7 +50,8 @@ mod tests {
|
|||||||
match super::file_type_from_filepath(&filepath) {
|
match super::file_type_from_filepath(&filepath) {
|
||||||
Ok(filetype) => {
|
Ok(filetype) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filetype.file_type, super::constants::PNG_TYPE,
|
filetype.file_type,
|
||||||
|
super::constants::PNG_TYPE,
|
||||||
"The file type of the CoverArt should have been png"
|
"The file type of the CoverArt should have been png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -60,7 +71,8 @@ mod tests {
|
|||||||
match super::file_type_from_data(&data) {
|
match super::file_type_from_data(&data) {
|
||||||
Ok(filetype) => {
|
Ok(filetype) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filetype.file_type, super::constants::PNG_TYPE,
|
filetype.file_type,
|
||||||
|
super::constants::PNG_TYPE,
|
||||||
"The file type of the CoverArt should have been png"
|
"The file type of the CoverArt should have been png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
pub fn file_type_from_filepath(filepath: &str) -> Result<crate::detection::FileType, std::io::Error> {
|
pub fn file_type_from_filepath(
|
||||||
|
filepath: &str,
|
||||||
|
) -> Result<crate::detection::FileType, std::io::Error> {
|
||||||
match infer::get_from_path(filepath) {
|
match infer::get_from_path(filepath) {
|
||||||
Ok(Some(kind)) => {
|
Ok(Some(kind)) => {
|
||||||
let mime = kind.mime_type();
|
let mime = kind.mime_type();
|
||||||
if mime == "audio/x-flac" {
|
if mime == "audio/x-flac" {
|
||||||
Ok(crate::detection::FileType {
|
Ok(crate::detection::FileType {
|
||||||
mime: String::from(mime),
|
mime: String::from(mime),
|
||||||
file_type: String::from(constants::FLAC_TYPE)
|
file_type: String::from(constants::FLAC_TYPE),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other("Unsupported file type"))
|
Err(std::io::Error::other("Unsupported file type"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => Err(std::io::Error::other("File type not determined")),
|
||||||
Err(std::io::Error::other("File type not determined"))
|
Err(err) => Err(err),
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user