From e3ca2c5781c9d7dbde348a7957422a79094b8260 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 20:30:39 +0000 Subject: [PATCH] Coverart save to filesystem (#67) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/67 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/coverart.rs | 14 +++++++++++++- src/song.rs | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef3fd86..b72049e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.6.4" +version = "0.6.5" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 5f10bcb..a1b9ebd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.6.4" +version = "0.6.5" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" diff --git a/src/coverart.rs b/src/coverart.rs index d6741bf..5444a3e 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -1,3 +1,5 @@ +use std::io::Write; + use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] @@ -26,7 +28,17 @@ pub mod init { } impl CoverArt { - // TODO: Add method to save to filesystem + /// Saves the coverart to the filesystem + pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { + match std::fs::File::create(&self.path) { + Ok(mut file) => match file.write_all(&self.data) { + Ok(_) => Ok(()), + Err(err) => Err(err), + }, + Err(err) => Err(err), + } + } + // TODO: Add method to remove from filesystem } diff --git a/src/song.rs b/src/song.rs index 183d08b..7ebc487 100644 --- a/src/song.rs +++ b/src/song.rs @@ -113,7 +113,7 @@ impl Song { Ok(song_path) => { let p = std::path::Path::new(&song_path); if p.exists() { - match std::fs::remove_file(&p) { + match std::fs::remove_file(p) { Ok(_) => Ok(()), Err(err) => Err(err), }