Compare commits

..

3 Commits

Author SHA1 Message Date
2f82ae0740 tsk-79: Version bump
All checks were successful
Rust Build / Check (pull_request) Successful in 55s
Rust Build / Test Suite (pull_request) Successful in 1m1s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 1m0s
Rust Build / build (pull_request) Successful in 26s
2025-10-24 12:12:44 -04:00
2be2680447 tsk-79: Code cleanup 2025-10-24 12:12:11 -04:00
ecf128ee91 tsk-79: Added function to generate filename 2025-10-24 12:09:47 -04:00
8 changed files with 36 additions and 55 deletions

2
Cargo.lock generated
View File

@@ -149,7 +149,7 @@ checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
[[package]]
name = "icarus_models"
version = "0.8.3"
version = "0.8.1"
dependencies = [
"josekit",
"rand",

View File

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

View File

@@ -1,3 +1,2 @@
A library containing commonly used structs, functions, enums, constants and other code
that is used throughout the icarus projects. Code from this library serves as the model
for other projects in the icarus project.
A library containing commonly used models and functions that is used throughout
icarus projects. This reduces the amount of duplicated code without a benefit.

View File

@@ -12,9 +12,3 @@ pub mod file_extensions {
pub const PNGEXTENSION: &str = ".png";
}
}
pub mod error {
pub const DIRECTORY_NOT_INITIALIZED: &str = "Directory has not been initialized";
pub const FILENAME_NOT_INITIALIZED: &str = "Filename has not bee initialized";
pub const LAST_CHARACTER_IN_DIRECTORY: &str = "Could not access last character of directory";
}

View File

@@ -68,21 +68,26 @@ impl CoverArt {
/// Gets the path of the CoverArt
pub fn get_path(&self) -> Result<String, std::io::Error> {
if self.directory.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::DIRECTORY_NOT_INITIALIZED,
));
return Err(std::io::Error::other("Directory has not been initialized"));
} else if self.filename.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::FILENAME_NOT_INITIALIZED,
));
return Err(std::io::Error::other("Filename has not bee initialized"));
}
let directory = &self.directory;
let last_index = directory.len() - 1;
match crate::util::concatenate_path(directory, &self.filename, last_index) {
Ok(path) => Ok(path),
Err(err) => Err(err),
if let Some(character) = directory.chars().nth(last_index) {
let buffer = if character != '/' {
directory.clone() + "/"
} else {
directory.clone()
};
Ok(buffer + &self.filename.clone())
} else {
Err(std::io::Error::other(
"Could not access last character of directory",
))
}
}
}
@@ -102,7 +107,7 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
};
if randomize {
let mut filename: String = String::from("coverart-");
let mut filename: String = String::new();
let some_chars: String = String::from("abcdefghij0123456789");
let some_chars_length = some_chars.len();
let mut rng = rand::rng();
@@ -117,7 +122,7 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
}
filename + &file_extension
} else {
"coverart-output".to_string() + &file_extension
"track-output".to_string() + &file_extension
}
}

View File

@@ -7,7 +7,6 @@ pub mod song;
pub mod token;
pub mod types;
pub mod user;
pub mod util;
pub mod init {
pub fn is_id_valid(num: &i32) -> bool {

View File

@@ -69,24 +69,28 @@ impl Song {
}
}
/// Gets the path of a Song
pub fn song_path(&self) -> Result<String, std::io::Error> {
if self.directory.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::DIRECTORY_NOT_INITIALIZED,
));
return Err(std::io::Error::other("Directory has not been initialized"));
} else if self.filename.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::FILENAME_NOT_INITIALIZED,
));
return Err(std::io::Error::other("Filename has not bee initialized"));
}
let directory = &self.directory;
let last_index = directory.len() - 1;
match crate::util::concatenate_path(directory, &self.filename, last_index) {
Ok(path) => Ok(path),
Err(err) => Err(err),
if let Some(character) = directory.chars().nth(last_index) {
let buffer: String = if character != '/' {
directory.clone() + "/"
} else {
directory.clone()
};
Ok(buffer + &self.filename.clone())
} else {
Err(std::io::Error::other(
"Could not access last character of directory",
))
}
}
@@ -143,13 +147,12 @@ pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
};
if randomize {
let mut filename: String = String::from("track-");
let mut filename: String = String::new();
let some_chars: String = String::from("abcdefghij0123456789");
let some_chars_length = some_chars.len();
let mut rng = rand::rng();
for _ in 0..FILENAME_LENGTH {
let index = rng.random_range(0..=some_chars_length);
let index = rng.random_range(0..=19);
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {

View File

@@ -1,19 +0,0 @@
pub fn concatenate_path(
directory: &str,
filename: &str,
last_index: usize,
) -> Result<String, std::io::Error> {
if let Some(character) = directory.chars().nth(last_index) {
let buffer: String = if character != '/' {
format!("{directory}/")
} else {
String::from(directory)
};
Ok(format!("{buffer}{filename}"))
} else {
Err(std::io::Error::other(
crate::constants::error::LAST_CHARACTER_IN_DIRECTORY,
))
}
}