From f5e6ac567e199f302b9523eaf03dafc8ad92d7b1 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 6 Nov 2025 15:52:46 +0000 Subject: [PATCH] tsk-49: Initialize FileType with file type of the media (#51) Closes #49 Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/51 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/detection/mod.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3669f4..663a929 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,7 +104,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.3" +version = "0.4.4" dependencies = [ "imghdr", "infer", diff --git a/Cargo.toml b/Cargo.toml index 8090b6c..b98b2eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.4.3" +version = "0.4.4" edition = "2024" rust-version = "1.90" diff --git a/src/detection/mod.rs b/src/detection/mod.rs index ad6601e..026e209 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -6,3 +6,29 @@ pub struct FileType { pub mime: String, pub file_type: String, } + +/// Initializes a FileType given a filetype passed. +pub fn init_filetype(filetype: &str) -> Result { + if filetype == song::constants::FLAC_TYPE { + Ok(FileType { + mime: String::from(song::constants::mime::FLAC), + file_type: String::from(song::constants::FLAC_TYPE), + }) + } else if filetype == coverart::constants::PNG_TYPE { + Ok(FileType { + mime: String::from(coverart::constants::mime::PNG), + file_type: String::from(coverart::constants::PNG_TYPE), + }) + } else if filetype == coverart::constants::JPEG_TYPE + || filetype == coverart::constants::JPG_TYPE + { + Ok(FileType { + mime: String::from(coverart::constants::mime::JPEG), + file_type: String::from(coverart::constants::JPEG_TYPE), + }) + } else { + Err(std::io::Error::other(format!( + "Unsupported FileType: {filetype:?}" + ))) + } +}