Compare commits

..

24 Commits

Author SHA1 Message Date
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
0637a9432e Changes to how song filenames are generated (#63)
Some checks failed
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Check (pull_request) Successful in 38s
Release Tagging / release (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Failing after 33s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 35s
Reviewed-on: #63
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 19:20:57 +00:00
d7c078d95a Song to_data change (#62)
All checks were successful
Rust Build / Check (pull_request) Successful in 35s
Release Tagging / release (pull_request) Successful in 43s
Rust Build / Test Suite (pull_request) Successful in 46s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 50s
Reviewed-on: #62
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 19:02:01 +00:00
00cada74e2 Copy song (#61)
Some checks failed
Rust Build / Check (pull_request) Successful in 42s
Release Tagging / release (pull_request) Successful in 44s
Rust Build / Test Suite (pull_request) Failing after 1m2s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 50s
Reviewed-on: #61
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 18:53:13 +00:00
9436c9033a Added todo
All checks were successful
Release Tagging / release (pull_request) Successful in 44s
Rust Build / Test Suite (pull_request) Successful in 49s
Rust Build / Check (pull_request) Successful in 57s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 47s
Rust Build / build (pull_request) Successful in 59s
2025-10-11 14:23:23 -04:00
85d8f839f1 Code formatting
All checks were successful
Rust Build / Test Suite (pull_request) Successful in 1m38s
Rust Build / Rustfmt (pull_request) Successful in 32s
Release Tagging / release (pull_request) Successful in 2m17s
Rust Build / Check (pull_request) Successful in 2m30s
Rust Build / Clippy (pull_request) Successful in 57s
Rust Build / build (pull_request) Successful in 1m1s
2025-10-11 14:19:45 -04:00
16f633d563 Added test 2025-10-11 14:19:30 -04:00
0b53eb8208 Added more todos 2025-10-11 14:19:21 -04:00
73c8fd2634 Tweaked some changes 2025-10-11 14:17:32 -04:00
fa8643e73a Added function to save song to the filesystem 2025-10-11 14:08:20 -04:00
2d6b550ae6 tsk-57: Adding derive Schema to models (#58)
All checks were successful
Rust Build / Check (push) Successful in 31s
Rust Build / Test Suite (push) Successful in 1m0s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 46s
Closes #57

Reviewed-on: #58
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-24 23:42:04 +00:00
f43bcaa314 Merge pull request 'Release' (#50) from devel into main
All checks were successful
Rust Build / Test Suite (push) Successful in 35s
Rust Build / Rustfmt (push) Successful in 1s
Rust Build / Check (push) Successful in 14s
Rust Build / build (push) Successful in 9s
Rust Build / Clippy (push) Successful in 52s
Reviewed-on: #50
2025-08-17 18:36:04 +00:00
a6ef7d8a62 Removed devel branch references (#56)
All checks were successful
Release Tagging / release (pull_request) Successful in 10s
Rust Build / Check (pull_request) Successful in 12s
Rust Build / Test Suite (pull_request) Successful in 1m3s
Rust Build / Rustfmt (pull_request) Successful in -6s
Rust Build / Clippy (pull_request) Successful in 9s
Rust Build / build (pull_request) Successful in 53s
Reviewed-on: #56
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-17 18:31:05 +00:00
bd793db08e Add Id to token (#55)
All checks were successful
Release Tagging / release (push) Successful in 39s
Rust Build / Check (push) Successful in 41s
Rust Build / Rustfmt (push) Successful in 36s
Rust Build / Test Suite (push) Successful in 37s
Rust Build / Clippy (push) Successful in 33s
Rust Build / build (push) Successful in 34s
Rust Build / Test Suite (pull_request) Successful in 31s
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 31s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / build (pull_request) Successful in 41s
Reviewed-on: #55
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-06 22:45:32 +00:00
569fb632e5 Merge pull request 'v0.5.X release' (#41) from devel into main
All checks were successful
Rust Build / Check (push) Successful in 26s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 27s
Reviewed-on: #41
2025-07-23 21:59:40 +00:00
6aa4c3d741 Merge pull request 'Next release' (#38) from devel into main
All checks were successful
Release Tagging / release (push) Successful in 42s
Rust Build / Check (push) Successful in 33s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 30s
Rust Build / Check (pull_request) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 25s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 26s
Reviewed-on: #38
2025-04-10 23:49:19 +00:00
97853a42c1 Merge pull request 'workflow_tag_fix (#33)' (#34) from devel into main
All checks were successful
Release Tagging / release (push) Successful in 32s
Rust Build / Check (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 30s
Rust Build / build (push) Successful in 33s
Reviewed-on: #34
2025-04-07 01:09:43 +00:00
fdae8056b1 Merge pull request 'Next release' (#30) from devel into main
All checks were successful
Rust Build / Check (push) Successful in 30s
Rust Build / Test Suite (push) Successful in 35s
Rust Build / Rustfmt (push) Successful in 29s
Rust Build / Clippy (push) Successful in 30s
Rust Build / build (push) Successful in 30s
Release Tagging / release (push) Successful in 34s
Reviewed-on: #30
2025-04-05 18:38:37 +00:00
24aa60cb48 Merge pull request 'Next release' (#25) from devel into main
All checks were successful
Rust Build / Check (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 35s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 30s
Release Tagging / release (push) Successful in 34s
Reviewed-on: #25
2025-04-04 04:08:03 +00:00
d8eadb8187 Merge pull request 'v0.2.0 Release' (#20) from devel into main
Some checks failed
Rust Build / Check (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 31s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 28s
Rust Build / build (push) Successful in 27s
Release Tagging / release (push) Failing after 34s
Reviewed-on: phoenix/icarus-models#20
2025-03-30 17:21:27 +00:00
2b2e96c02d Merge pull request 'devel' (#16) from devel into main
All checks were successful
Rust Build / Check (push) Successful in 26s
Rust Build / Test Suite (push) Successful in 26s
Rust Build / Rustfmt (push) Successful in 26s
Rust Build / Clippy (push) Successful in 26s
Rust Build / build (push) Successful in 26s
Release Tagging / release (push) Successful in 28s
Reviewed-on: phoenix/icarus-models#16
2025-03-22 21:24:15 +00:00
11 changed files with 251 additions and 114 deletions

View File

@@ -1,9 +1,9 @@
name: Release Tagging
on:
push:
pull_request:
branches:
- devel
- main
jobs:
release:

View File

@@ -4,11 +4,9 @@ on:
push:
branches:
- main
- devel
pull_request:
branches:
- main
- devel
jobs:
check:

28
Cargo.lock generated
View File

@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]]
name = "icarus_models"
version = "0.5.4"
version = "0.6.5"
dependencies = [
"josekit",
"rand",
@@ -150,6 +150,7 @@ dependencies = [
"serde_json",
"tempfile",
"time",
"utoipa",
"uuid",
]
@@ -161,6 +162,7 @@ checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
@@ -527,6 +529,30 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utoipa"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993"
dependencies = [
"indexmap",
"serde",
"serde_json",
"utoipa-gen",
]
[[package]]
name = "utoipa-gen"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"uuid",
]
[[package]]
name = "uuid"
version = "1.17.0"

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_models"
version = "0.5.4"
version = "0.6.5"
edition = "2024"
rust-version = "1.88"
description = "models used for the icarus project"
@@ -13,6 +13,7 @@ rand = { version = "0.9.1" }
time = { version = "0.3.41", features = ["formatting", "macros", "parsing", "serde"] }
uuid = { version = "1.17.0", features = ["v4", "serde"] }
josekit = { version = "0.10.3" }
utoipa = { version = "5.4.0", features = ["uuid", "time"] }
[dev-dependencies]
tempfile = { version = "3.20.0" }

View File

@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
pub struct AccessLevel {
pub id: uuid::Uuid,
pub level: String,

View File

@@ -1,8 +1,8 @@
use std::io::Read;
use std::io::Write;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct CoverArt {
pub id: uuid::Uuid,
pub title: String,
@@ -28,8 +28,26 @@ 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),
}
}
// TODO: Add method to remove from filesystem
}
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) {

View File

@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
pub struct LoginResult {
pub id: uuid::Uuid,
pub username: String,

View File

@@ -1,13 +1,16 @@
use std::io::Read;
use std::io::Write;
use rand::Rng;
use serde::{Deserialize, Serialize};
use crate::constants;
use crate::init;
use crate::types;
use rand::Rng;
use serde::{Deserialize, Serialize};
/// Length of characters of a filename to be generated
const FILENAME_LENGTH: i32 = 16;
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct Song {
#[serde(skip_serializing_if = "init::is_uuid_nil")]
#[serde(alias = "id")]
@@ -90,10 +93,114 @@ impl Song {
}
}
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
let path_result = self.song_path();
/// 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() {
Ok(song_path) => match std::fs::File::create(&song_path) {
Ok(mut file) => match file.write_all(&self.data) {
Ok(_res) => Ok(()),
Err(err) => Err(err),
},
Err(err) => Err(err),
},
Err(err) => Err(err),
}
}
match path_result {
/// 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 {
Ok(())
}
}
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 {
let file_extension = match typ {
types::MusicTypes::DefaultMusicExtension => {
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
}
types::MusicTypes::WavExtension => {
String::from(constants::file_extensions::audio::WAVEXTENSION)
}
types::MusicTypes::FlacExtension => {
String::from(constants::file_extensions::audio::FLACEXTENSION)
}
types::MusicTypes::MPThreeExtension => {
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
}
};
if randomize {
let mut filename: String = String::new();
let some_chars: String = String::from("abcdefghij0123456789");
let mut rng = rand::rng();
for _ in 0..FILENAME_LENGTH {
let index = rng.random_range(0..=19);
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
filename + &file_extension
} else {
"track-output".to_string() + &file_extension
}
}
/// I/O operations for songs
pub mod io {
use std::io::Read;
/// 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);
if p.exists() {
Err(std::io::Error::other(
"Cannot copy song over to one that already exists",
))
} else {
if song_target.data.is_empty() {
song_target.data = song_source.data.clone();
} else {
song_target.data.clear();
song_target.data = song_source.data.clone();
}
match song_target.save_to_filesystem() {
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
}
Err(err) => Err(err),
}
}
/// Gets the raw file data of a song from the filesystem
pub fn to_data(song: &super::Song) -> Result<Vec<u8>, std::io::Error> {
match song.song_path() {
Ok(path) => {
let mut file = std::fs::File::open(path)?;
let mut buffer: Vec<u8> = Vec::new();
@@ -108,46 +215,4 @@ impl Song {
Err(er) => Err(er),
}
}
pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String {
let mut filename: String = String::new();
let filename_len = 10;
let file_extension = match typ {
types::MusicTypes::DefaultMusicExtension => {
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
}
types::MusicTypes::WavExtension => {
String::from(constants::file_extensions::audio::WAVEXTENSION)
}
types::MusicTypes::FlacExtension => {
String::from(constants::file_extensions::audio::FLACEXTENSION)
}
types::MusicTypes::MPThreeExtension => {
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
}
};
if randomize {
let some_chars: String = String::from("abcdefghij0123456789");
let mut rng = rand::rng();
for _i in 0..filename_len {
let random_number: i32 = rng.random_range(0..=19);
let index = random_number as usize;
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
} else {
filename += "track-output";
}
filename += &file_extension;
filename
}
}

View File

@@ -80,6 +80,7 @@ pub struct TokenResource {
pub message: String,
pub issuer: String,
pub audiences: Vec<String>,
pub id: uuid::Uuid,
}
pub const TOKEN_TYPE: &str = "JWT";
@@ -99,6 +100,14 @@ pub fn create_token(
payload.set_subject(message);
payload.set_issuer(issuer);
payload.set_audience(audiences.clone());
if !token_resource.id.is_nil() {
match payload.set_claim("id", Some(serde_json::json!(token_resource.id))) {
Ok(_) => {}
Err(err) => {
return Err(err);
}
}
}
match get_issued() {
Ok(issued) => {
let expire = issued + duration;
@@ -121,6 +130,19 @@ pub fn create_token(
mod tests {
use super::*;
fn test_key() -> String {
String::from("c3092urmc2219ix320i40m293ic29IM09IN0u879Y8B98YB8yb86TN7B55R4yv4RCVU6Bi8YO8U")
}
fn test_resource() -> TokenResource {
TokenResource {
issuer: String::from("icarus_auth_test"),
message: String::from("Authorization"),
audiences: vec![String::from("icarus_test")],
id: uuid::Uuid::nil(),
}
}
#[test]
fn test_token_scope_check() {
let mut token = Token::default();
@@ -138,14 +160,29 @@ mod tests {
#[test]
fn test_token_creation() {
let key = String::from(
"c3092urmc2219ix320i40m293ic29IM09IN0u879Y8B98YB8yb86TN7B55R4yv4RCVU6Bi8YO8U",
);
let test_token_resource = TokenResource {
issuer: String::from("icarus_auth_test"),
message: String::from("Authorization"),
audiences: vec![String::from("icarus_test")],
};
let key = test_key();
let test_token_resource = test_resource();
let token_expiration_duration = time::Duration::hours(2);
match create_token(&key, &test_token_resource, token_expiration_duration) {
Ok((token, expire_duration)) => {
assert_eq!(false, token.is_empty(), "Error: Token is empty");
assert!(
expire_duration > 0,
"Token expire duration is invalid {expire_duration:?}"
);
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
#[test]
fn test_token_creation_with_id() {
let key = test_key();
let mut test_token_resource = test_resource();
test_token_resource.id = uuid::Uuid::new_v4();
let token_expiration_duration = time::Duration::hours(2);
match create_token(&key, &test_token_resource, token_expiration_duration) {

View File

@@ -4,7 +4,7 @@ use crate::init;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
pub struct User {
#[serde(skip_serializing_if = "init::is_uuid_nil")]
pub id: uuid::Uuid,

View File

@@ -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");
@@ -65,7 +61,7 @@ mod song_tests {
Ok(buffer) => {
assert_eq!(buffer.is_empty(), false);
match song.to_data() {
match song::io::to_data(&song) {
Ok(song_data) => {
println!("Both files match");
assert_eq!(buffer, song_data);
@@ -103,50 +99,47 @@ 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() {
Some(s) => String::from(s),
None => String::new(),
};
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() {
Some(s) => String::from(s),
None => String::new(),
};
assert_eq!(song.directory.is_empty(), false);
song_cpy.filename =
song.generate_filename(types::MusicTypes::FlacExtension, true);
println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename);
assert_eq!(song.directory.is_empty(), false);
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,
Err(err) => {
assert!(false, "Error: {:?}", err);
String::new()
}
};
match song::io::copy_song(&song, &mut song_cpy) {
Ok(_) => {}
Err(err) => {
assert!(false, "Error copying song: Error: {err:?}")
}
}
}
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);
}
};
}
#[test]
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");
let mut copied_song = song::Song {
directory: utils::get_tests_directory(),
filename: String::from("track02-coppied.flac"),
..Default::default()
};
match song::io::copy_song(&song, &mut copied_song) {
Ok(_) => match copied_song.remove_from_filesystem() {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {:?}", err);
assert!(false, "Error: {err:?}")
}
},
Err(err) => {
assert!(false, "Error extracting song data: {:?}", err);
assert!(false, "Error: {err:?}")
}
}
}
@@ -154,7 +147,6 @@ mod song_tests {
#[cfg(test)]
mod album_tests {
use crate::utils;
use icarus_models::album;