tsk-83: Add None value for MusicTypes and CoverArtTypes (#87)
All checks were successful
Release Tagging / release (push) Successful in 33s
Rust Build / Check (push) Successful in 34s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 32s
Rust Build / build (push) Successful in 32s

Closes #83

Reviewed-on: #87
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit was merged in pull request #87.
This commit is contained in:
2025-10-28 17:05:13 +00:00
committed by phoenix
parent 0a27b8ccb1
commit 432078e3c2
6 changed files with 42 additions and 20 deletions

View File

@@ -1,11 +1,10 @@
use std::io::Write;
use rand::Rng;
use serde::{Deserialize, Serialize};
const FILENAME_LENGTH: i32 = 16;
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct CoverArt {
pub id: uuid::Uuid,
pub title: String,
@@ -18,11 +17,9 @@ pub struct CoverArt {
}
pub mod init {
use super::CoverArt;
/// Initializes the CoverArt with just the directory and filename
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> CoverArt {
CoverArt {
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> super::CoverArt {
super::CoverArt {
directory: String::from(directory),
filename: String::from(filename),
..Default::default()
@@ -88,7 +85,10 @@ impl CoverArt {
}
/// Generates filename for a CoverArt
pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> String {
pub fn generate_filename(
typ: crate::types::CoverArtTypes,
randomize: bool,
) -> Result<String, std::io::Error> {
let file_extension = match typ {
crate::types::CoverArtTypes::PngExtension => {
String::from(crate::constants::file_extensions::image::PNGEXTENSION)
@@ -99,9 +99,12 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
crate::types::CoverArtTypes::JpgExtension => {
String::from(crate::constants::file_extensions::image::JPGEXTENSION)
}
crate::types::CoverArtTypes::None => {
return Err(std::io::Error::other("Unsupported CoverArtTypes"));
}
};
if randomize {
let filename: String = if randomize {
let mut filename: String = String::from("coverart-");
let some_chars: String = String::from("abcdefghij0123456789");
let some_chars_length = some_chars.len();
@@ -115,10 +118,12 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
filename.push(c);
}
}
filename + &file_extension
format!("{filename}{file_extension}")
} else {
"coverart-output".to_string() + &file_extension
}
format!("coverart-output{file_extension}")
};
Ok(filename)
}
pub mod io {