Compare commits

...

6 Commits

Author SHA1 Message Date
668d371f7f Merge pull request 'Coverart changes' (#65) from coverart_changes into main
All checks were successful
Rust Build / Check (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 31s
Rust Build / Test Suite (push) Successful in 33s
Release Tagging / release (pull_request) Successful in 31s
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 12m55s
Rust Build / Rustfmt (pull_request) Successful in 26m11s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 35s
Reviewed-on: #65
2025-10-11 22:18:24 +00:00
eac7562b80 Coverart remove file (#68)
All checks were successful
Release Tagging / release (pull_request) Successful in 31s
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 34s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 31s
Reviewed-on: #68
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 22:14:10 +00:00
e3ca2c5781 Coverart save to filesystem (#67)
All checks were successful
Release Tagging / release (pull_request) Successful in 36s
Rust Build / Check (pull_request) Successful in 41s
Rust Build / Test Suite (pull_request) Successful in 43s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 2m12s
Rust Build / build (pull_request) Successful in 2m18s
Reviewed-on: #67
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 20:30:39 +00:00
440caca7c2 Moved to_data (#66)
Some checks failed
Rust Build / Check (pull_request) Successful in 33s
Release Tagging / release (pull_request) Successful in 36s
Rust Build / Test Suite (pull_request) Successful in 45s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Failing after 44s
Rust Build / build (pull_request) Successful in 1m7s
Reviewed-on: #66
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 20:11:39 +00:00
0c0b4ba7ca Merge pull request 'Song changes' (#60) from song_changes into main
Some checks failed
Rust Build / Check (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Clippy (push) Failing after 36s
Rust Build / build (push) Successful in 35s
Rust Build / Check (pull_request) Successful in 32s
Release Tagging / release (pull_request) Failing after 36s
Rust Build / Test Suite (pull_request) Successful in 34s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / build (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Failing after 34s
Reviewed-on: #60
2025-10-11 19:49:52 +00:00
c263cedf28 Remove song (#64)
Some checks failed
Release Tagging / release (pull_request) Successful in 33s
Rust Build / Check (pull_request) Successful in 43s
Rust Build / Test Suite (pull_request) Successful in 44s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Failing after 32s
Rust Build / build (pull_request) Successful in 38s
Reviewed-on: #64
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 19:46:00 +00:00
5 changed files with 63 additions and 14 deletions

2
Cargo.lock generated
View File

@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]]
name = "icarus_models"
version = "0.6.2"
version = "0.6.6"
dependencies = [
"josekit",
"rand",

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_models"
version = "0.6.2"
version = "0.6.6"
edition = "2024"
rust-version = "1.88"
description = "models used for the icarus project"

View File

@@ -1,4 +1,4 @@
use std::io::Read;
use std::io::Write;
use serde::{Deserialize, Serialize};
@@ -28,8 +28,39 @@ pub mod init {
}
impl CoverArt {
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
let path: &String = &self.path;
/// 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),
}
}
/// 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 buffer = Vec::new();
match file.read_to_end(&mut buffer) {
@@ -37,9 +68,6 @@ impl CoverArt {
Err(err) => Err(err),
}
}
// TODO: Add method to save to filesystem
// TODO: Add method to remove from filesystem
}
#[cfg(test)]

View File

@@ -7,6 +7,7 @@ use crate::constants;
use crate::init;
use crate::types;
/// Length of characters of a filename to be generated
const FILENAME_LENGTH: i32 = 16;
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
@@ -92,7 +93,6 @@ impl Song {
}
}
/// Saves the song to the filesystem using the song's data
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
match self.song_path() {
@@ -107,10 +107,27 @@ impl Song {
}
}
// TODO: Add function to remove file from the filesystem
/// Removes the song from the filesystem
pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> {
match self.song_path() {
Ok(song_path) => {
let p = std::path::Path::new(&song_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",
))
}
}
Err(err) => Err(err),
}
}
}
/// Generates a filename. In order to save a song to the filesystem, the song must have
/// a directory and filename
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {

View File

@@ -120,7 +120,7 @@ mod song_tests {
}
#[test]
fn test_save_song_to_filesystem() {
fn test_save_song_to_filesystem_and_remove() {
let mut song = song::Song::default();
song.directory = utils::get_tests_directory();
song.filename = String::from("track02.flac");
@@ -132,7 +132,12 @@ mod song_tests {
};
match song::io::copy_song(&song, &mut copied_song) {
Ok(_) => {}
Ok(_) => match copied_song.remove_from_filesystem() {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}")
}
},
Err(err) => {
assert!(false, "Error: {err:?}")
}
@@ -142,7 +147,6 @@ mod song_tests {
#[cfg(test)]
mod album_tests {
use crate::utils;
use icarus_models::album;