tsk-45: Some changes

This commit is contained in:
2025-10-21 20:08:41 -04:00
parent fa5203013c
commit fef43b9799
3 changed files with 22 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
/// Gets the file type of a CoverArt given it's path
pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error> {
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<String, std::io::Error>
/// Gets the file type of a CoverArt given it's data
pub fn file_type_from_data(data: &Vec<u8>) -> Result<String, std::io::Error> {
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]

View File

@@ -1 +1,9 @@
pub mod coverart;
pub mod song;
pub struct FileType {
pub mime: String
}
pub enum FileTypeDef {
}

View File

@@ -13,3 +13,7 @@ pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error>
}
}
}
pub mod constants {
pub const FLAC_TYPE: &str = "flac";
}