Compare commits
7 Commits
v0.5.5
...
v0.5.6-60-
Author | SHA1 | Date | |
---|---|---|---|
9436c9033a
|
|||
85d8f839f1
|
|||
16f633d563
|
|||
0b53eb8208
|
|||
73c8fd2634
|
|||
fa8643e73a
|
|||
2d6b550ae6 |
28
Cargo.lock
generated
28
Cargo.lock
generated
@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
||||
|
||||
[[package]]
|
||||
name = "icarus_models"
|
||||
version = "0.5.5"
|
||||
version = "0.5.6"
|
||||
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"
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "icarus_models"
|
||||
version = "0.5.5"
|
||||
version = "0.5.6"
|
||||
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" }
|
||||
|
@@ -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,
|
||||
|
@@ -2,7 +2,7 @@ use std::io::Read;
|
||||
|
||||
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,
|
||||
@@ -37,6 +37,9 @@ impl CoverArt {
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add method to save to filesystem
|
||||
// TODO: Add method to remove from filesystem
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@@ -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,
|
||||
|
23
src/song.rs
23
src/song.rs
@@ -1,4 +1,4 @@
|
||||
use std::io::Read;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::constants;
|
||||
use crate::init;
|
||||
@@ -7,7 +7,7 @@ use crate::types;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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,6 +90,7 @@ impl Song {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this available as a function
|
||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
||||
let path_result = self.song_path();
|
||||
|
||||
@@ -109,6 +110,7 @@ impl Song {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this available as a function
|
||||
pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String {
|
||||
let mut filename: String = String::new();
|
||||
let filename_len = 10;
|
||||
@@ -150,4 +152,21 @@ impl Song {
|
||||
|
||||
filename
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add function to remove file from the filesystem
|
||||
}
|
||||
|
||||
// TODO: Add function to copy song
|
||||
|
@@ -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,
|
||||
|
@@ -150,6 +150,39 @@ mod song_tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_save_song_to_filesystem() {
|
||||
let mut song = song::Song::default();
|
||||
song.directory = utils::get_tests_directory();
|
||||
song.filename = String::from("track02.flac");
|
||||
|
||||
match song.song_path() {
|
||||
Ok(song_path) => match utils::extract_data_from_file(&song_path) {
|
||||
Ok(data) => {
|
||||
let copied_song = song::Song {
|
||||
directory: utils::get_tests_directory(),
|
||||
filename: String::from("track02-coppied.flac"),
|
||||
data: data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match copied_song.save_to_filesystem() {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}")
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user