Coverart changes #65
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.3"
|
version = "0.6.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"josekit",
|
"josekit",
|
||||||
"rand",
|
"rand",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.3"
|
version = "0.6.6"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
use std::io::Read;
|
use std::io::Write;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -28,8 +28,39 @@ pub mod init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CoverArt {
|
impl CoverArt {
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
/// Saves the coverart to the filesystem
|
||||||
let path: &String = &self.path;
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the coverart from the filesystem
|
||||||
|
pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> {
|
||||||
|
let p = std::path::Path::new(&self.path);
|
||||||
|
if p.exists() {
|
||||||
|
match std::fs::remove_file(p) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other(
|
||||||
|
"Cannot delete file that does not exist",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod io {
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
/// Gets the raw data of the cover art
|
||||||
|
pub fn to_data(coverart: &super::CoverArt) -> Result<Vec<u8>, std::io::Error> {
|
||||||
|
let path: &String = &coverart.path;
|
||||||
let mut file = std::fs::File::open(path)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
match file.read_to_end(&mut buffer) {
|
match file.read_to_end(&mut buffer) {
|
||||||
@@ -37,9 +68,6 @@ impl CoverArt {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add method to save to filesystem
|
|
||||||
// TODO: Add method to remove from filesystem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@@ -113,12 +113,14 @@ impl Song {
|
|||||||
Ok(song_path) => {
|
Ok(song_path) => {
|
||||||
let p = std::path::Path::new(&song_path);
|
let p = std::path::Path::new(&song_path);
|
||||||
if p.exists() {
|
if p.exists() {
|
||||||
match std::fs::remove_file(&p) {
|
match std::fs::remove_file(p) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Err(std::io::Error::other(
|
||||||
|
"Cannot delete file that does not exist",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
Reference in New Issue
Block a user