diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index e5d86de..fc5cc39 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,8 +1,8 @@ /// Gets the file type of a CoverArt given it's path pub fn file_type_from_filepath(filepath: &str) -> Result { match imghdr::from_file(filepath) { - Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")), - Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")), + Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from(constants::JPEG_TYPE)), + Ok(Some(imghdr::Type::Png)) => Ok(String::from(constants::PNG_TYPE)), Ok(None) => Err(std::io::Error::other("Image file not supported")), Err(err) => Err(err), _ => Err(std::io::Error::other("Image file not supported")), @@ -12,13 +12,19 @@ pub fn file_type_from_filepath(filepath: &str) -> Result /// Gets the file type of a CoverArt given it's data pub fn file_type_from_data(data: &Vec) -> Result { match imghdr::from_bytes(data) { - Some(imghdr::Type::Jpeg) => Ok(String::from("jpeg")), - Some(imghdr::Type::Png) => Ok(String::from("png")), + Some(imghdr::Type::Jpeg) => Ok(String::from(constants::JPEG_TYPE)), + Some(imghdr::Type::Png) => Ok(String::from(constants::PNG_TYPE)), None => Err(std::io::Error::other("Image file not supported")), _ => Err(std::io::Error::other("Image file not supported")), } } +pub mod constants { + pub const PNG_TYPE: &str = "png"; + pub const JPEG_TYPE: &str = "jpeg"; + pub const JPG_TYPE: &str = "jpg"; +} + #[cfg(test)] mod tests { #[test] diff --git a/src/detection/mod.rs b/src/detection/mod.rs index 165fc86..b1ecbb7 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -1 +1,9 @@ pub mod coverart; +pub mod song; + +pub struct FileType { + pub mime: String +} + +pub enum FileTypeDef { +} diff --git a/src/detection/song.rs b/src/detection/song.rs index 03563a6..ed0099e 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -13,3 +13,7 @@ pub fn file_type_from_filepath(filepath: &str) -> Result } } } + +pub mod constants { + pub const FLAC_TYPE: &str = "flac"; +}