Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8becd9a49c
|
||
|
|
6ec7c4e212 | ||
|
|
5c98486f75 | ||
|
|
8e91af657e | ||
|
|
d751622bac | ||
|
|
6022347cb7 | ||
|
|
e6ab0bcd83 | ||
|
|
94d97cb81d | ||
|
|
d6d7197419 | ||
|
|
fe9d101bd0 | ||
|
|
859b0fb1b3 | ||
|
|
c04f27570e | ||
|
|
0a1949c706 | ||
|
|
e2995fd223 |
No files matched your search
@@ -10,18 +10,19 @@ on:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # Important for git describe --tags
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
components: cargo
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Extract Version from Cargo.toml
|
||||
id: version
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Rust Build
|
||||
name: simodels Build
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -8,55 +8,65 @@ on:
|
||||
branches:
|
||||
- main
|
||||
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo check
|
||||
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo test
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add rustfmt
|
||||
- run: cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add clippy
|
||||
- run: cargo clippy -- -D warnings
|
||||
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-26.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.99.1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo build
|
||||
+3
-28
@@ -6,7 +6,7 @@ stages:
|
||||
|
||||
build:
|
||||
stage: build
|
||||
image: rust:1.85
|
||||
image: rust:1.95
|
||||
script:
|
||||
- cargo build --release
|
||||
- ls -R target/release/
|
||||
@@ -22,7 +22,7 @@ build:
|
||||
|
||||
test:
|
||||
stage: test
|
||||
image: rust:1.85
|
||||
image: rust:1.95
|
||||
script:
|
||||
- cargo test
|
||||
cache:
|
||||
@@ -33,7 +33,7 @@ test:
|
||||
|
||||
test_variable:
|
||||
stage: test
|
||||
image: rust:1.85
|
||||
image: rust:1.95
|
||||
script:
|
||||
- echo "Checking CARGO_LOGIN_TOKEN..."
|
||||
- if [[ -z "$CARGO_LOGIN_TOKEN" ]]; then echo "CARGO_LOGIN_TOKEN is empty!"; exit 1; else echo "CARGO_LOGIN_TOKEN is set."; fi
|
||||
@@ -56,28 +56,3 @@ extract_version:
|
||||
artifacts:
|
||||
reports:
|
||||
dotenv: version.env
|
||||
|
||||
tag_release:
|
||||
stage: deploy
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
rules:
|
||||
- if: '($CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main") && $CI_PIPELINE_SOURCE == "push"'
|
||||
dependencies:
|
||||
- extract_version
|
||||
script:
|
||||
- release-cli create --name "Release $CI_COMMIT_BRANCH-v$VERSION" --tag-name "$CI_COMMIT_BRANCH-v$VERSION"
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
image: rust:1.85
|
||||
script:
|
||||
- echo "Deployment will be configured when this is ready for use"
|
||||
# - env
|
||||
# Uncomment when you are ready for this to be published
|
||||
# - cargo login "$CARGO_LOGIN_TOKEN"
|
||||
# - cargo publish
|
||||
dependencies:
|
||||
- build
|
||||
rules:
|
||||
- if: '$CI_COMMIT_TAG'
|
||||
|
||||
Generated
+210
-393
File diff suppressed because it is too large.
Load diff
+27
-10
@@ -1,19 +1,36 @@
|
||||
[package]
|
||||
name = "icarus_models"
|
||||
version = "0.10.0"
|
||||
name = "simodels"
|
||||
version = "0.11.20"
|
||||
edition = "2024"
|
||||
rust-version = "1.95"
|
||||
description = "models used for the icarus project"
|
||||
description = "Models used for the soaricarus project"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = { version = "1.0.145" }
|
||||
rand = { version = "0.9.2" }
|
||||
time = { version = "0.3.44", features = ["formatting", "macros", "parsing", "serde"] }
|
||||
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||
serde = { version = "1.0.229", features = ["derive"] }
|
||||
serde_json = { version = "1.0.154" }
|
||||
rand = { version = "0.10.4" }
|
||||
time = { version = "0.3.55", features = ["formatting", "macros", "parsing", "serde"] }
|
||||
uuid = { version = "1.29.3", features = ["v4", "serde"] }
|
||||
josekit = { version = "0.10.3" }
|
||||
utoipa = { version = "5.4.0", features = ["uuid", "time"] }
|
||||
utoipa = { version = "6.0.0", features = ["uuid", "time"] }
|
||||
|
||||
[features]
|
||||
default = ["full"]
|
||||
full = ["access_level", "album", "constants", "coverart", "ledger", "login_result", "song", "token", "types", "user", "util"]
|
||||
auth = ["constants", "login_result", "register_result", "token", "user"]
|
||||
access_level = ["constants"]
|
||||
album = []
|
||||
constants = []
|
||||
coverart = ["constants", "types"]
|
||||
ledger = ["constants", "song", "types", "user"]
|
||||
login_result = ["constants", "token", "user"]
|
||||
register_result = []
|
||||
song = ["constants", "types"]
|
||||
token = []
|
||||
types = []
|
||||
user = []
|
||||
util = []
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = { version = "3.23.0" }
|
||||
tempfile = { version = "3.27.0" }
|
||||
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2026 Kun Deng.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,3 +1,4 @@
|
||||
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.
|
||||
# simodels
|
||||
Library containing structs, functions, enums, constants and other code
|
||||
that is used throughout the soaricarus projects. Code from this library serves as the model
|
||||
for other projects in the soaricarus project.
|
||||
+9
-7
@@ -2,6 +2,8 @@ use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DEFAULT_ACCESS_LEVEL: &str = super::constants::access_level::PUBLIC;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct AccessLevel {
|
||||
pub id: uuid::Uuid,
|
||||
@@ -13,8 +15,8 @@ impl Default for AccessLevel {
|
||||
fn default() -> Self {
|
||||
AccessLevel {
|
||||
id: uuid::Uuid::nil(),
|
||||
level: String::new(),
|
||||
song_id: uuid::Uuid::new_v4(),
|
||||
level: DEFAULT_ACCESS_LEVEL.to_string(),
|
||||
song_id: uuid::Uuid::nil(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,16 +24,16 @@ impl Default for AccessLevel {
|
||||
pub fn default_level() -> AccessLevel {
|
||||
AccessLevel {
|
||||
id: uuid::Uuid::nil(),
|
||||
level: String::from("Public"),
|
||||
song_id: uuid::Uuid::new_v4(),
|
||||
level: DEFAULT_ACCESS_LEVEL.to_string(),
|
||||
song_id: uuid::Uuid::nil(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn private_level() -> AccessLevel {
|
||||
AccessLevel {
|
||||
id: uuid::Uuid::new_v4(),
|
||||
level: String::from("Private"),
|
||||
song_id: uuid::Uuid::new_v4(),
|
||||
id: uuid::Uuid::nil(),
|
||||
level: super::constants::access_level::PRIVATE.to_string(),
|
||||
song_id: uuid::Uuid::nil(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-1
@@ -37,7 +37,42 @@ pub mod collection {
|
||||
pub artist: String,
|
||||
pub disc: i32,
|
||||
pub track: i32,
|
||||
// In seconds
|
||||
/// In seconds
|
||||
pub duration: f64,
|
||||
}
|
||||
|
||||
pub fn deserialize_json(json_data: &str, album: &mut Album) -> Result<(), serde_json::Error> {
|
||||
match serde_json::from_str::<Album>(json_data) {
|
||||
Ok(parsed_album) => {
|
||||
*album = parsed_album;
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_deserilize_album_collection_json() {
|
||||
let album_file_path = "tests/album.json";
|
||||
let album_file_content = match std::fs::read_to_string(album_file_path) {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
|
||||
let mut album = super::collection::Album::default();
|
||||
match super::collection::deserialize_json(&album_file_content, &mut album) {
|
||||
Ok(_) => {
|
||||
assert_eq!(3, album.tracks.len(), "Track count do not match");
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,22 @@ pub mod file_extensions {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod song_event {
|
||||
/// Song Event Type - Play
|
||||
pub const SONG_EVENT_TYPE_PLAY: &str = "PLAY";
|
||||
/// Song Event Type - PAUSE
|
||||
pub const SONG_EVENT_TYPE_PAUSE: &str = "PAUSE";
|
||||
}
|
||||
|
||||
pub mod access_level {
|
||||
pub const PUBLIC: &str = "PUBLIC";
|
||||
pub const PRIVATE: &str = "PRIVATE";
|
||||
}
|
||||
|
||||
pub mod token {
|
||||
pub const TOKEN_TYPE: &str = "JWT";
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
use std::io::Write;
|
||||
|
||||
use rand::Rng;
|
||||
use rand::RngExt;
|
||||
|
||||
const FILENAME_LENGTH: i32 = 16;
|
||||
|
||||
@@ -12,6 +12,7 @@ pub struct CoverArt {
|
||||
pub directory: String,
|
||||
pub filename: String,
|
||||
pub file_type: String,
|
||||
pub file_key: String,
|
||||
#[serde(skip)]
|
||||
pub data: Vec<u8>,
|
||||
pub song_id: uuid::Uuid,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct SongEvent {
|
||||
pub id: uuid::Uuid,
|
||||
pub song_id: uuid::Uuid,
|
||||
pub user_id: uuid::Uuid,
|
||||
pub event_type: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub event_time: Option<time::OffsetDateTime>,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub date_created: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
impl SongEvent {
|
||||
pub fn is_event_type_valid(&self) -> bool {
|
||||
matches!(
|
||||
self.event_type.as_str(),
|
||||
super::constants::song_event::SONG_EVENT_TYPE_PLAY
|
||||
| super::constants::song_event::SONG_EVENT_TYPE_PAUSE
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ pub mod access_level;
|
||||
pub mod album;
|
||||
pub mod constants;
|
||||
pub mod coverart;
|
||||
pub mod ledger;
|
||||
pub mod login_result;
|
||||
pub mod playback_queue;
|
||||
pub mod register_result;
|
||||
pub mod song;
|
||||
pub mod token;
|
||||
pub mod types;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// Playback queue device type - Browser
|
||||
pub const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
|
||||
/// Playback queue device type - Mobile
|
||||
pub const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||
pub struct PlaybackQueue {
|
||||
pub id: uuid::Uuid,
|
||||
pub name: String,
|
||||
pub device_type: String,
|
||||
pub user_id: uuid::Uuid,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub date_created: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||
pub struct PlaybackQueueItem {
|
||||
pub id: uuid::Uuid,
|
||||
pub queue_index: i32,
|
||||
pub playback_queue_id: uuid::Uuid,
|
||||
pub song_id: uuid::Uuid,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub date_created: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct RegisterResult {
|
||||
pub id: uuid::Uuid,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub date_created: Option<time::OffsetDateTime>,
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
use std::io::Write;
|
||||
|
||||
use rand::Rng;
|
||||
use rand::RngExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::constants;
|
||||
@@ -49,6 +49,7 @@ pub struct Song {
|
||||
pub data: Vec<u8>,
|
||||
#[serde(skip)]
|
||||
pub directory: String,
|
||||
pub file_key: String,
|
||||
// TODO: Think about what to do with this
|
||||
// #[serde(skip)]
|
||||
// pub album_id: i32,
|
||||
|
||||
+3
-5
@@ -111,15 +111,13 @@ pub struct TokenResource {
|
||||
pub id: uuid::Uuid,
|
||||
}
|
||||
|
||||
pub const TOKEN_TYPE: &str = "JWT";
|
||||
|
||||
pub fn create_token(
|
||||
key: &String,
|
||||
token_resource: &TokenResource,
|
||||
duration: time::Duration,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
let mut header = josekit::jws::JwsHeader::new();
|
||||
header.set_token_type(TOKEN_TYPE);
|
||||
header.set_token_type(super::constants::token::TOKEN_TYPE);
|
||||
|
||||
let mut payload = josekit::jwt::JwtPayload::new();
|
||||
let message = &token_resource.message;
|
||||
@@ -164,9 +162,9 @@ mod tests {
|
||||
|
||||
fn test_resource() -> TokenResource {
|
||||
TokenResource {
|
||||
issuer: String::from("icarus_auth_test"),
|
||||
issuer: String::from("soaricarus_auth_test"),
|
||||
message: String::from("Authorization"),
|
||||
audiences: vec![String::from("icarus_test")],
|
||||
audiences: vec![String::from("soaricarus_test")],
|
||||
id: uuid::Uuid::nil(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,14 @@ pub struct User {
|
||||
pub salt_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct UserProfile {
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
User {
|
||||
|
||||
+3
-3
@@ -33,8 +33,8 @@ mod song_tests {
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::utils;
|
||||
use icarus_models::song;
|
||||
use icarus_models::types;
|
||||
use simodels::song;
|
||||
use simodels::types;
|
||||
|
||||
#[test]
|
||||
fn test_song_to_data() {
|
||||
@@ -157,7 +157,7 @@ mod song_tests {
|
||||
#[cfg(test)]
|
||||
mod album_tests {
|
||||
use crate::utils;
|
||||
use icarus_models::album;
|
||||
use simodels::album;
|
||||
|
||||
#[test]
|
||||
fn parse_album() {
|
||||
|
||||
Reference in new issue
Block a user