Compare commits
3 Commits
a867f65a26
...
dd4a2acce0
Author | SHA1 | Date | |
---|---|---|---|
dd4a2acce0
|
|||
7c867695b5
|
|||
cdcb64b742
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
||||
|
||||
[[package]]
|
||||
name = "icarus_models"
|
||||
version = "0.5.6"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"josekit",
|
||||
"rand",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "icarus_models"
|
||||
version = "0.5.6"
|
||||
version = "0.6.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.88"
|
||||
description = "models used for the icarus project"
|
||||
|
16
src/song.rs
16
src/song.rs
@@ -1,12 +1,12 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::constants;
|
||||
use crate::init;
|
||||
use crate::types;
|
||||
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct Song {
|
||||
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||
@@ -170,8 +170,13 @@ impl Song {
|
||||
// TODO: Add function to remove file from the filesystem
|
||||
}
|
||||
|
||||
/// Copies a song using the source song's data
|
||||
pub fn copy_song(song_source: &Song, song_target: &mut Song) -> Result<(), std::io::Error> {
|
||||
/// I/O operations for songs
|
||||
pub mod io {
|
||||
/// Copies a song using the source song's data
|
||||
pub fn copy_song(
|
||||
song_source: &super::Song,
|
||||
song_target: &mut super::Song,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match song_target.song_path() {
|
||||
Ok(songpath) => {
|
||||
let p = std::path::Path::new(&songpath);
|
||||
@@ -195,4 +200,5 @@ pub fn copy_song(song_source: &Song, song_target: &mut Song) -> Result<(), std::
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,16 +30,12 @@ mod utils {
|
||||
|
||||
#[cfg(test)]
|
||||
mod song_tests {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::utils;
|
||||
use icarus_models::song;
|
||||
use icarus_models::types;
|
||||
|
||||
use crate::utils;
|
||||
|
||||
#[test]
|
||||
fn test_song_to_data() {
|
||||
println!("Test");
|
||||
@@ -103,9 +99,6 @@ mod song_tests {
|
||||
song.directory = utils::get_tests_directory();
|
||||
song.filename = String::from("track01.flac");
|
||||
|
||||
match song.song_path() {
|
||||
Ok(songpath) => match utils::extract_data_from_file(&songpath) {
|
||||
Ok(buffer) => {
|
||||
let mut song_cpy = song.clone();
|
||||
let temp_dir = tempdir().expect("Failed to create temp dir");
|
||||
song_cpy.directory = match temp_dir.path().to_str() {
|
||||
@@ -114,39 +107,14 @@ mod song_tests {
|
||||
};
|
||||
|
||||
assert_eq!(song.directory.is_empty(), false);
|
||||
song_cpy.filename =
|
||||
song.generate_filename(types::MusicTypes::FlacExtension, true);
|
||||
song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true);
|
||||
println!("Directory: {:?}", song_cpy.directory);
|
||||
println!("File to be created: {:?}", song_cpy.filename);
|
||||
|
||||
let path = match song_cpy.song_path() {
|
||||
Ok(s_path) => s_path,
|
||||
match song::copy_song(&song, &mut song_cpy) {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
|
||||
match File::create(path) {
|
||||
Ok(mut file_cpy) => match file_cpy.write_all(&buffer) {
|
||||
Ok(success) => {
|
||||
println!("Success: {:?}", success);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error saving file: {:?}", err);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
assert!(false, "Error extracting song data: {:?}", err);
|
||||
assert!(false, "Error copying song: Error: {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user