Compare commits

..

4 Commits

Author SHA1 Message Date
1c1826ff32 tsk-57: Added schema to models
All checks were successful
Rust Build / Test Suite (pull_request) Successful in 36s
Release Tagging / release (pull_request) Successful in 38s
Rust Build / Check (pull_request) Successful in 49s
Rust Build / Rustfmt (pull_request) Successful in 36s
Rust Build / Clippy (pull_request) Successful in 51s
Rust Build / build (pull_request) Successful in 43s
2025-08-19 18:24:55 -04:00
57fd5c3029 tsk-57: Added time feature to utoipa 2025-08-19 18:24:26 -04:00
0950267a48 tsk-57: Added uuid feature for utoipa 2025-08-19 18:21:06 -04:00
abfec8d287 tsk-57: Adding utoipia crate for documentation
All checks were successful
Release Tagging / release (pull_request) Successful in 39s
Rust Build / Test Suite (pull_request) Successful in 57s
Rust Build / Check (pull_request) Successful in 59s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 51s
2025-08-19 18:08:10 -04:00
14 changed files with 378 additions and 563 deletions

View File

@@ -1,9 +1,6 @@
name: Release Tagging name: Release Tagging
on: on:
push:
branches:
- main
pull_request: pull_request:
branches: branches:
- main - main
@@ -13,14 +10,14 @@ jobs:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v5 uses: actions/checkout@v3
with: with:
fetch-depth: 0 # Important for git describe --tags fetch-depth: 0 # Important for git describe --tags
- name: Install Rust - name: Install Rust
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
components: cargo components: cargo
- name: Extract Version from Cargo.toml - name: Extract Version from Cargo.toml
@@ -28,15 +25,12 @@ jobs:
run: | run: |
VERSION=$(grep '^version = "' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') VERSION=$(grep '^version = "' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10) PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
BRANCH_REF="${{ gitea.ref }}" BRANCH_REF="${GITHUB_REF}"
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3) BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-111" PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-111"
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
echo "Version: $VERSION" echo "Version: $VERSION"
echo "Hash: $PROJECT_COMMIT_HASH" echo "Hash: $PROJECT_COMMIT_HASH"
echo "Branh ref: $BRANCH_REF"
echo "Branch: $BRANCH_NAME" echo "Branch: $BRANCH_NAME"
echo "Tag Release: $PROJECT_TAG_RELEASE" echo "Tag Release: $PROJECT_TAG_RELEASE"

View File

@@ -13,30 +13,30 @@ jobs:
name: Check name: Check
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
- run: cargo check - run: cargo check
test: test:
name: Test Suite name: Test Suite
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
- run: cargo test - run: cargo test
fmt: fmt:
name: Rustfmt name: Rustfmt
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
- run: rustup component add rustfmt - run: rustup component add rustfmt
- run: cargo fmt --all -- --check - run: cargo fmt --all -- --check
@@ -44,10 +44,10 @@ jobs:
name: Clippy name: Clippy
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
- run: rustup component add clippy - run: rustup component add clippy
- run: cargo clippy -- -D warnings - run: cargo clippy -- -D warnings
@@ -55,8 +55,10 @@ jobs:
name: build name: build
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.90.0 toolchain: 1.88.0
- run: cargo build - run: cargo build

322
Cargo.lock generated
View File

@@ -10,18 +10,18 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "1.1.4" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.100" version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
[[package]] [[package]]
name = "base64" name = "base64"
@@ -31,9 +31,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.10.0" version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
@@ -43,19 +43,18 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.43" version = "1.2.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2" checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
dependencies = [ dependencies = [
"find-msvc-tools",
"shlex", "shlex",
] ]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.4" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
@@ -68,12 +67,12 @@ dependencies = [
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.5.5" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
dependencies = [ dependencies = [
"powerfmt", "powerfmt",
"serde_core", "serde",
] ]
[[package]] [[package]]
@@ -84,9 +83,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.14" version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys", "windows-sys",
@@ -98,17 +97,11 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "find-msvc-tools"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.5" version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@@ -131,25 +124,25 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.3.4" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"r-efi", "r-efi",
"wasip2", "wasi",
] ]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.16.0" version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]] [[package]]
name = "icarus_models" name = "icarus_models"
version = "0.9.2" version = "0.5.5"
dependencies = [ dependencies = [
"josekit", "josekit",
"rand", "rand",
@@ -163,14 +156,13 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.12.0" version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
"serde", "serde",
"serde_core",
] ]
[[package]] [[package]]
@@ -198,9 +190,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.82" version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -208,21 +200,27 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.177" version = "0.2.171"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.11.0" version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.6" version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
@@ -231,7 +229,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [ dependencies = [
"adler2", "adler2",
"simd-adler32",
] ]
[[package]] [[package]]
@@ -248,9 +245,9 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.74" version = "0.10.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ad14dd45412269e1a30f52ad8f0664f0f4f4a89ee8fe28c3b3527021ebb654" checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
@@ -274,9 +271,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.110" version = "0.9.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a9f0075ba3c21b09f8e8b2026584b1d18d49388648f2fbbf3c97ea8deced8e2" checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@@ -307,33 +304,33 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.103" version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.41" version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]] [[package]]
name = "r-efi" name = "r-efi"
version = "5.3.0" version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.9.2" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
dependencies = [ dependencies = [
"rand_chacha", "rand_chacha",
"rand_core", "rand_core",
@@ -360,9 +357,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.12.2" version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -372,9 +369,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.13" version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -383,15 +380,15 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.8" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "1.1.2" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" checksum = "e56a18552996ac8d29ecc3b190b4fdbb2d91ca4ec396de7bbffaf43f3d637e96"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"errno", "errno",
@@ -402,9 +399,9 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.22" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
[[package]] [[package]]
name = "ryu" name = "ryu"
@@ -414,28 +411,18 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.228" version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.228" version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -444,16 +431,15 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.145" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"itoa", "itoa",
"memchr", "memchr",
"ryu", "ryu",
"serde", "serde",
"serde_core",
] ]
[[package]] [[package]]
@@ -462,17 +448,11 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "simd-adler32"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.108" version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -481,9 +461,9 @@ dependencies = [
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.23.0" version = "3.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
dependencies = [ dependencies = [
"fastrand", "fastrand",
"getrandom", "getrandom",
@@ -494,18 +474,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.17" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.17" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -514,9 +494,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.44" version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
@@ -529,15 +509,15 @@ dependencies = [
[[package]] [[package]]
name = "time-core" name = "time-core"
version = "0.1.6" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.24" version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
dependencies = [ dependencies = [
"num-conv", "num-conv",
"time-core", "time-core",
@@ -545,9 +525,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.20" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]] [[package]]
name = "utoipa" name = "utoipa"
@@ -575,9 +555,9 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.18.1" version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"js-sys", "js-sys",
@@ -592,32 +572,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "wasip2" name = "wasi"
version = "1.0.1+wasi-0.2.4" version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [ dependencies = [
"wit-bindgen", "wit-bindgen-rt",
] ]
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
"rustversion", "rustversion",
"wasm-bindgen-macro", "wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -625,61 +618,122 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [ dependencies = [
"bumpalo",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.61.2" version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [ dependencies = [
"windows-link", "windows-targets",
] ]
[[package]] [[package]]
name = "wit-bindgen" name = "windows-targets"
version = "0.46.0" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.27" version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.8.27" version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@@ -1,19 +1,19 @@
[package] [package]
name = "icarus_models" name = "icarus_models"
version = "0.9.2" version = "0.5.5"
edition = "2024" edition = "2024"
rust-version = "1.90" rust-version = "1.88"
description = "models used for the icarus project" description = "models used for the icarus project"
license = "MIT" license = "MIT"
[dependencies] [dependencies]
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.219", features = ["derive"] }
serde_json = { version = "1.0.145" } serde_json = { version = "1.0.140" }
rand = { version = "0.9.2" } rand = { version = "0.9.1" }
time = { version = "0.3.44", features = ["formatting", "macros", "parsing", "serde"] } time = { version = "0.3.41", features = ["formatting", "macros", "parsing", "serde"] }
uuid = { version = "1.18.1", features = ["v4", "serde"] } uuid = { version = "1.17.0", features = ["v4", "serde"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "5.4.0", features = ["uuid", "time"] } utoipa = { version = "5.4.0", features = ["uuid", "time"] }
[dev-dependencies] [dev-dependencies]
tempfile = { version = "3.23.0" } tempfile = { version = "3.20.0" }

View File

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

View File

@@ -12,9 +12,3 @@ pub mod file_extensions {
pub const PNGEXTENSION: &str = ".png"; 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

@@ -1,146 +1,39 @@
use std::io::Write; use std::io::Read;
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 struct CoverArt {
pub id: uuid::Uuid, pub id: uuid::Uuid,
pub title: String, pub title: String,
#[serde(skip)] #[serde(skip)]
pub directory: String, pub path: String,
pub filename: String,
pub file_type: String,
#[serde(skip)] #[serde(skip)]
pub data: Vec<u8>, pub data: Vec<u8>,
pub song_id: uuid::Uuid, pub song_id: uuid::Uuid,
} }
pub mod init { pub mod init {
/// Initializes the CoverArt with just the directory and filename use crate::coverart::CoverArt;
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> super::CoverArt {
super::CoverArt { pub fn init_coverart_only_path(path: String) -> CoverArt {
directory: String::from(directory), CoverArt {
filename: String::from(filename), id: uuid::Uuid::nil(),
..Default::default() title: String::new(),
path: path.clone(),
data: Vec::new(),
song_id: uuid::Uuid::nil(),
} }
} }
} }
impl CoverArt { impl CoverArt {
/// Saves the coverart to the filesystem pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { let path: &String = &self.path;
match self.get_path() { let mut file = std::fs::File::open(path)?;
Ok(path) => match std::fs::File::create(&path) { let mut buffer = Vec::new();
Ok(mut file) => match file.write_all(&self.data) { match file.read_to_end(&mut buffer) {
Ok(_) => Ok(()), Ok(_) => Ok(buffer),
Err(err) => Err(err),
},
Err(err) => Err(err),
},
Err(err) => Err(err),
}
}
/// Removes the coverart from the filesystem
pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> {
match self.get_path() {
Ok(path) => {
let p = std::path::Path::new(&path);
if p.exists() {
match std::fs::remove_file(p) {
Ok(_) => Ok(()),
Err(err) => Err(err),
}
} else {
Err(std::io::Error::other(
"Cannot delete file that does not exist",
))
}
}
Err(err) => Err(err),
}
}
/// 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,
));
} else if self.filename.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::FILENAME_NOT_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),
}
}
}
/// Generates filename for a CoverArt
pub fn generate_filename(
typ: crate::types::CoverArtType,
randomize: bool,
) -> Result<String, std::io::Error> {
let file_extension = match typ {
crate::types::CoverArtType::PngExtension => {
String::from(crate::constants::file_extensions::image::PNGEXTENSION)
}
crate::types::CoverArtType::JpegExtension => {
String::from(crate::constants::file_extensions::image::JPEGEXTENSION)
}
crate::types::CoverArtType::JpgExtension => {
String::from(crate::constants::file_extensions::image::JPGEXTENSION)
}
crate::types::CoverArtType::None => {
return Err(std::io::Error::other("Unsupported CoverArtTypes"));
}
};
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();
let mut rng = rand::rng();
for _ in 0..FILENAME_LENGTH {
let index = rng.random_range(0..=some_chars_length);
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
format!("{filename}{file_extension}")
} else {
format!("coverart-output{file_extension}")
};
Ok(filename)
}
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> {
match coverart.get_path() {
Ok(path) => {
let mut file = std::fs::File::open(path)?;
let mut buffer = Vec::new();
match file.read_to_end(&mut buffer) {
Ok(_) => Ok(buffer),
Err(err) => Err(err),
}
}
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
@@ -152,11 +45,9 @@ mod tests {
#[test] #[test]
fn test_cover_art_image() { fn test_cover_art_image() {
let dir = String::from("./"); let path: String = String::from("somepath");
let filename = String::from("CoverArt.png"); let coverart = coverart::init::init_coverart_only_path(path.clone());
let coverart = coverart::init::init_coverart_dir_and_filename(&dir, &filename);
assert_eq!(dir, coverart.directory); assert_eq!(path, coverart.path);
assert_eq!(filename, coverart.filename);
} }
} }

View File

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

View File

@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] #[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
pub struct LoginResult { pub struct LoginResult {
pub id: uuid::Uuid, pub id: uuid::Uuid,
pub username: String, pub username: String,
@@ -12,14 +12,20 @@ pub struct LoginResult {
pub expiration: i64, pub expiration: i64,
} }
impl LoginResult { impl Default for LoginResult {
pub fn to_json(&self) -> Result<String, serde_json::Error> { fn default() -> Self {
serde_json::to_string_pretty(&self) LoginResult {
} id: uuid::Uuid::nil(),
username: String::new(),
pub fn token_expired(&self) -> bool { token: String::new(),
let current_time = time::OffsetDateTime::now_utc(); token_type: String::new(),
let expired = time::OffsetDateTime::from_unix_timestamp(self.expiration).unwrap(); expiration: -1,
current_time > expired }
}
}
impl LoginResult {
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(&self)
} }
} }

View File

@@ -1,14 +1,11 @@
use std::io::Write; use std::io::Read;
use rand::Rng;
use serde::{Deserialize, Serialize};
use crate::constants; use crate::constants;
use crate::init; use crate::init;
use crate::types; use crate::types;
/// Length of characters of a filename to be generated use rand::Rng;
const FILENAME_LENGTH: i32 = 16; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct Song { pub struct Song {
@@ -39,8 +36,8 @@ pub struct Song {
pub track_count: i32, pub track_count: i32,
#[serde(skip_serializing_if = "String::is_empty")] #[serde(skip_serializing_if = "String::is_empty")]
pub audio_type: String, pub audio_type: String,
#[serde(with = "time::serde::rfc3339::option")] #[serde(skip_serializing_if = "String::is_empty")]
pub date_created: Option<time::OffsetDateTime>, pub date_created: String,
#[serde(skip_serializing_if = "String::is_empty")] #[serde(skip_serializing_if = "String::is_empty")]
pub filename: String, pub filename: String,
#[serde(skip_serializing_if = "init::is_uuid_nil")] #[serde(skip_serializing_if = "init::is_uuid_nil")]
@@ -69,139 +66,34 @@ impl Song {
} }
} }
/// Gets the path of a Song
pub fn song_path(&self) -> Result<String, std::io::Error> { pub fn song_path(&self) -> Result<String, std::io::Error> {
if self.directory.is_empty() { if self.directory.is_empty() {
return Err(std::io::Error::other( return Err(std::io::Error::other("Directory does not exist"));
crate::constants::error::DIRECTORY_NOT_INITIALIZED,
));
} else if self.filename.is_empty() {
return Err(std::io::Error::other(
crate::constants::error::FILENAME_NOT_INITIALIZED,
));
} }
let directory = &self.directory; let directory = &self.directory;
let mut buffer: String = directory.clone();
let last_index = directory.len() - 1; let last_index = directory.len() - 1;
match crate::util::concatenate_path(directory, &self.filename, last_index) { if let Some(character) = directory.chars().nth(last_index) {
Ok(path) => Ok(path), if character != '/' {
Err(err) => Err(err), buffer += "/";
}
}
/// 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),
}
}
/// 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 {
Err(std::io::Error::other(
"Cannot delete file that does not exist",
))
}
} }
Err(err) => Err(err),
}
}
}
/// Generates a filename. In order to save a song to the filesystem buffer += &self.filename.clone();
pub fn generate_filename(typ: types::MusicType, randomize: bool) -> Result<String, std::io::Error> {
let file_extension = match typ {
types::MusicType::DefaultMusicExtension => {
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
}
types::MusicType::WavExtension => {
String::from(constants::file_extensions::audio::WAVEXTENSION)
}
types::MusicType::FlacExtension => {
String::from(constants::file_extensions::audio::FLACEXTENSION)
}
types::MusicType::MPThreeExtension => {
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
}
types::MusicType::None => return Err(std::io::Error::other("Unsupported MusicTypes")),
};
let filename: String = if randomize { Ok(buffer)
let mut filename: String = String::from("track-"); } else {
let some_chars: String = String::from("abcdefghij0123456789"); Err(std::io::Error::other(
let some_chars_length = some_chars.len(); "Could not access last character of directory",
let mut rng = rand::rng(); ))
for _ in 0..FILENAME_LENGTH {
let index = rng.random_range(0..=some_chars_length);
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
format!("{filename}{file_extension}")
} else {
format!("track-output{file_extension}")
};
Ok(filename)
}
/// 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(&self) -> Result<Vec<u8>, std::io::Error> {
pub fn to_data(song: &super::Song) -> Result<Vec<u8>, std::io::Error> { let path_result = self.song_path();
match song.song_path() {
match path_result {
Ok(path) => { Ok(path) => {
let mut file = std::fs::File::open(path)?; let mut file = std::fs::File::open(path)?;
let mut buffer: Vec<u8> = Vec::new(); let mut buffer: Vec<u8> = Vec::new();
@@ -216,4 +108,46 @@ pub mod io {
Err(er) => Err(er), 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

@@ -1,8 +1,8 @@
use std::default::Default; use std::default::Default;
use serde::Deserialize; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, serde::Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Token { pub struct Token {
pub scope: String, pub scope: String,
pub expiration: i64, pub expiration: i64,
@@ -11,7 +11,7 @@ pub struct Token {
pub issued: i64, pub issued: i64,
} }
#[derive(Clone, Debug, Deserialize, serde::Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccessToken { pub struct AccessToken {
#[serde(alias = "init::is_uuid_nil")] #[serde(alias = "init::is_uuid_nil")]
pub user_id: uuid::Uuid, pub user_id: uuid::Uuid,
@@ -27,31 +27,23 @@ pub struct AccessToken {
pub message: String, pub message: String,
} }
#[derive(Clone, Debug, serde::Serialize, Deserialize)] impl Default for Token {
pub struct UserClaims { fn default() -> Self {
pub iss: String, Token {
pub aud: String, // Audience scope: String::new(),
pub sub: String, // Subject (user ID) expiration: -1,
#[serde(deserialize_with = "deserialize_i64_from_f64")] audience: String::new(),
pub exp: i64, // Expiration time (UTC timestamp) issuer: String::new(),
#[serde(deserialize_with = "deserialize_i64_from_f64")] issued: -1,
pub iat: i64, // Issued at (UTC timestamp) }
// pub azp: String, }
// pub gty: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub roles: Option<Vec<String>>, // Optional roles
} }
impl AccessToken { impl AccessToken {
/// Get the token fit for Bearer authentication
pub fn bearer_token(&self) -> String { pub fn bearer_token(&self) -> String {
format!("Bearer {}", self.token) let mut token: String = String::from("Bearer ");
} token += &self.token.clone();
token
pub fn token_expired(&self) -> bool {
let current_time = time::OffsetDateTime::now_utc();
let expired = time::OffsetDateTime::from_unix_timestamp(self.expiration).unwrap();
current_time > expired
} }
} }
@@ -60,10 +52,9 @@ impl Token {
serde_json::to_string_pretty(&self) serde_json::to_string_pretty(&self)
} }
// TODO: Implement
pub fn token_expired(&self) -> bool { pub fn token_expired(&self) -> bool {
let current_time = time::OffsetDateTime::now_utc(); false
let expired = time::OffsetDateTime::from_unix_timestamp(self.expiration).unwrap();
current_time > expired
} }
pub fn contains_scope(&self, des_scope: &String) -> bool { pub fn contains_scope(&self, des_scope: &String) -> bool {
@@ -71,25 +62,6 @@ impl Token {
} }
} }
fn deserialize_i64_from_f64<'de, D>(deserializer: D) -> Result<i64, D::Error>
where
D: serde::Deserializer<'de>,
{
let val = f64::deserialize(deserializer)?;
// Handle NaN and infinity cases
if val.is_nan() || val.is_infinite() {
return Err(serde::de::Error::custom("invalid float value"));
}
// Round to nearest integer and convert
let rounded = val.round();
// Check if the rounded value can fit in i64
if rounded < (i64::MIN as f64) || rounded > (i64::MAX as f64) {
Err(serde::de::Error::custom("float out of i64 range"))
} else {
Ok(rounded as i64)
}
}
pub fn get_issued() -> time::Result<time::OffsetDateTime> { pub fn get_issued() -> time::Result<time::OffsetDateTime> {
Ok(time::OffsetDateTime::now_utc()) Ok(time::OffsetDateTime::now_utc())
} }

View File

@@ -1,16 +1,6 @@
#[derive(Debug)] pub enum MusicTypes {
pub enum MusicType {
DefaultMusicExtension, DefaultMusicExtension,
WavExtension, WavExtension,
FlacExtension, FlacExtension,
MPThreeExtension, MPThreeExtension,
None,
}
#[derive(Debug)]
pub enum CoverArtType {
PngExtension,
JpegExtension,
JpgExtension,
None,
} }

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,
))
}
}

View File

@@ -30,12 +30,16 @@ mod utils {
#[cfg(test)] #[cfg(test)]
mod song_tests { mod song_tests {
use std::fs::File;
use std::io::Write;
use tempfile::tempdir; use tempfile::tempdir;
use crate::utils;
use icarus_models::song; use icarus_models::song;
use icarus_models::types; use icarus_models::types;
use crate::utils;
#[test] #[test]
fn test_song_to_data() { fn test_song_to_data() {
println!("Test"); println!("Test");
@@ -61,7 +65,7 @@ mod song_tests {
Ok(buffer) => { Ok(buffer) => {
assert_eq!(buffer.is_empty(), false); assert_eq!(buffer.is_empty(), false);
match song::io::to_data(&song) { match song.to_data() {
Ok(song_data) => { Ok(song_data) => {
println!("Both files match"); println!("Both files match");
assert_eq!(buffer, song_data); assert_eq!(buffer, song_data);
@@ -99,56 +103,50 @@ mod song_tests {
song.directory = utils::get_tests_directory(); song.directory = utils::get_tests_directory();
song.filename = String::from("track01.flac"); song.filename = String::from("track01.flac");
let mut song_cpy = song.clone(); match song.song_path() {
let temp_dir = tempdir().expect("Failed to create temp dir"); Ok(songpath) => match utils::extract_data_from_file(&songpath) {
song_cpy.directory = match temp_dir.path().to_str() { Ok(buffer) => {
Some(s) => String::from(s), let mut song_cpy = song.clone();
None => String::new(), 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); assert_eq!(song.directory.is_empty(), false);
match song::generate_filename(types::MusicType::FlacExtension, true) { song_cpy.filename =
Ok(filename) => { song.generate_filename(types::MusicTypes::FlacExtension, true);
song_cpy.filename = filename; println!("Directory: {:?}", song_cpy.directory);
} println!("File to be created: {:?}", song_cpy.filename);
Err(err) => {
assert!(false, "Error generatig filename: {err:?}");
}
};
println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename);
match song::io::copy_song(&song, &mut song_cpy) { let path = match song_cpy.song_path() {
Ok(_) => { Ok(s_path) => s_path,
println!("Song copied"); Err(err) => {
} assert!(false, "Error: {:?}", err);
Err(err) => { String::new()
assert!(false, "Error copying song: Error: {err:?}") }
} };
}
}
#[test] match File::create(path) {
fn test_save_song_to_filesystem_and_remove() { Ok(mut file_cpy) => match file_cpy.write_all(&buffer) {
let mut song = song::Song::default(); Ok(success) => {
song.directory = utils::get_tests_directory(); println!("Success: {:?}", success);
song.filename = String::from("track02.flac"); }
Err(err) => {
let mut copied_song = song::Song { assert!(false, "Error saving file: {:?}", err);
directory: utils::get_tests_directory(), }
filename: String::from("track02-coppied.flac"), },
..Default::default() Err(err) => {
}; assert!(false, "Error: {:?}", err);
}
match song::io::copy_song(&song, &mut copied_song) { };
Ok(_) => match copied_song.remove_from_filesystem() { }
Ok(_) => {}
Err(err) => { Err(err) => {
assert!(false, "Error: {err:?}") assert!(false, "Error: {:?}", err);
} }
}, },
Err(err) => { Err(err) => {
assert!(false, "Error: {err:?}") assert!(false, "Error extracting song data: {:?}", err);
} }
} }
} }
@@ -156,6 +154,7 @@ mod song_tests {
#[cfg(test)] #[cfg(test)]
mod album_tests { mod album_tests {
use crate::utils; use crate::utils;
use icarus_models::album; use icarus_models::album;