Compare commits
62 Commits
v0.1.14-de
...
v0.7.0-70-
Author | SHA1 | Date | |
---|---|---|---|
f0a716b243
|
|||
93ca002dc0
|
|||
daaa224eee
|
|||
4e649fa390 | |||
668d371f7f | |||
eac7562b80 | |||
e3ca2c5781 | |||
440caca7c2 | |||
0c0b4ba7ca | |||
c263cedf28 | |||
0637a9432e | |||
d7c078d95a | |||
00cada74e2 | |||
9436c9033a
|
|||
85d8f839f1
|
|||
16f633d563
|
|||
0b53eb8208
|
|||
73c8fd2634
|
|||
fa8643e73a
|
|||
2d6b550ae6 | |||
f43bcaa314 | |||
a6ef7d8a62 | |||
bd793db08e | |||
1e95822b5a | |||
228ca67a16 | |||
d3251f935e | |||
1c5de9dc26 | |||
569fb632e5 | |||
7839c64561 | |||
655d05dabb | |||
7958b89abc | |||
c0d23e0640 | |||
1a64b512f4 | |||
e5082ea07d | |||
f37c445908 | |||
6aa4c3d741 | |||
47475639b0 | |||
73c17840ff | |||
2dbed9fec9 | |||
97853a42c1 | |||
6467521a02 | |||
6411133c95 | |||
8a08672423 | |||
fdae8056b1 | |||
c555110367 | |||
4b6f6cb67d | |||
e9d73c391e | |||
d476b128cb | |||
255aff414a | |||
24aa60cb48 | |||
6a0135c6fa | |||
8fbd92620e | |||
61ad88a258 | |||
d8eadb8187 | |||
a64d35d153 | |||
f6fdb717e9 | |||
e5c1eabe8c | |||
a8ffe80297 | |||
56384fb371 | |||
bf5808a06a | |||
2b2e96c02d | |||
1c5c0ca70c |
@@ -1,26 +1,23 @@
|
|||||||
name: Release Tagging
|
name: Release Tagging
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- devel
|
|
||||||
tags:
|
|
||||||
- 'v*' # Trigger on tags matching v*
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
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.85.0
|
toolchain: 1.90.0
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
@@ -52,6 +49,3 @@ jobs:
|
|||||||
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
||||||
body: |
|
body: |
|
||||||
Release of version ${{ steps.version.outputs.project_tag_release }}
|
Release of version ${{ steps.version.outputs.project_tag_release }}
|
||||||
# draft: false
|
|
||||||
# prerelease: ${{ startsWith(github.ref, 'v') == false }} # prerelease if not a valid release tag
|
|
||||||
|
|
||||||
|
@@ -4,63 +4,61 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- devel
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- devel
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.90.0
|
||||||
- run: cargo check
|
- run: cargo check
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test Suite
|
name: Test Suite
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.90.0
|
||||||
- run: cargo test
|
- run: cargo test
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.90.0
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: cargo fmt --all -- --check
|
- run: cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.90.0
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: cargo clippy -- -D warnings
|
- run: cargo clippy -- -D warnings
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: build
|
name: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.90.0
|
||||||
- run: cargo build
|
- run: cargo build
|
||||||
|
|
||||||
|
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
/target
|
/target
|
||||||
Cargo.lock
|
|
||||||
|
716
Cargo.lock
generated
Normal file
716
Cargo.lock
generated
Normal file
@@ -0,0 +1,716 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler2"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.19.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7"
|
||||||
|
dependencies = [
|
||||||
|
"find-msvc-tools",
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc32fast"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fastrand"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "find-msvc-tools"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||||
|
dependencies = [
|
||||||
|
"foreign-types-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types-shared"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icarus_models"
|
||||||
|
version = "0.7.0"
|
||||||
|
dependencies = [
|
||||||
|
"josekit",
|
||||||
|
"rand",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tempfile",
|
||||||
|
"time",
|
||||||
|
"utoipa",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.11.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "josekit"
|
||||||
|
version = "0.10.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a808e078330e6af222eb0044b71d4b1ff981bfef43e7bc8133a88234e0c86a0c"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"base64",
|
||||||
|
"flate2",
|
||||||
|
"openssl",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.81"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.177"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.8.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
||||||
|
dependencies = [
|
||||||
|
"adler2",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl"
|
||||||
|
version = "0.10.73"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cfg-if",
|
||||||
|
"foreign-types",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"openssl-macros",
|
||||||
|
"openssl-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-sys"
|
||||||
|
version = "0.9.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.101"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a52d8d02cacdb176ef4678de6c052efb4b3da14b78e4db683a4252762be5433"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "722166aa0d7438abbaa4d5cc2c649dac844e8c56d82fb3d33e9c34b5cd268fc6"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3160422bbd54dd5ecfdca71e5fd59b7b8fe2b1697ab2baf64f6d05dcc66d298"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustix"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustversion"
|
||||||
|
version = "1.0.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
|
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 = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.145"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simd-adler32"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.106"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tempfile"
|
||||||
|
version = "3.23.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
|
||||||
|
dependencies = [
|
||||||
|
"fastrand",
|
||||||
|
"getrandom",
|
||||||
|
"once_cell",
|
||||||
|
"rustix",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"itoa",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde",
|
||||||
|
"time-core",
|
||||||
|
"time-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3"
|
||||||
|
dependencies = [
|
||||||
|
"num-conv",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
||||||
|
|
||||||
|
[[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.18.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
"js-sys",
|
||||||
|
"serde",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.7+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
|
||||||
|
dependencies = [
|
||||||
|
"wasip2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasip2"
|
||||||
|
version = "1.0.1+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"rustversion",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.61.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen"
|
||||||
|
version = "0.46.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
19
Cargo.toml
19
Cargo.toml
@@ -1,12 +1,19 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus-models"
|
name = "icarus_models"
|
||||||
version = "0.1.14"
|
version = "0.7.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
rust-version = "1.90"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.218", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.139" }
|
serde_json = { version = "1.0.145" }
|
||||||
rand = { version = "0.9" }
|
rand = { version = "0.9.2" }
|
||||||
tempfile = { version = "3.19.1" }
|
time = { version = "0.3.44", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
|
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||||
|
josekit = { version = "0.10.3" }
|
||||||
|
utoipa = { version = "5.4.0", features = ["uuid", "time"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = { version = "3.23.0" }
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
A library containing commonly used models and functions that is used throughout
|
||||||
|
icarus projects. This reduces the amount of duplicated code without a benefit.
|
||||||
|
@@ -2,36 +2,36 @@ use std::default::Default;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct AccessLevel {
|
pub struct AccessLevel {
|
||||||
pub id: i32,
|
pub id: uuid::Uuid,
|
||||||
pub level: String,
|
pub level: String,
|
||||||
pub song_id: i32,
|
pub song_id: uuid::Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AccessLevel {
|
impl Default for AccessLevel {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
AccessLevel {
|
AccessLevel {
|
||||||
id: -1,
|
id: uuid::Uuid::nil(),
|
||||||
level: String::new(),
|
level: String::new(),
|
||||||
song_id: -1,
|
song_id: uuid::Uuid::new_v4(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_level() -> AccessLevel {
|
pub fn default_level() -> AccessLevel {
|
||||||
AccessLevel {
|
AccessLevel {
|
||||||
id: -1,
|
id: uuid::Uuid::nil(),
|
||||||
level: String::from("Public"),
|
level: String::from("Public"),
|
||||||
song_id: -1,
|
song_id: uuid::Uuid::new_v4(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn private_level() -> AccessLevel {
|
pub fn private_level() -> AccessLevel {
|
||||||
AccessLevel {
|
AccessLevel {
|
||||||
id: -1,
|
id: uuid::Uuid::new_v4(),
|
||||||
level: String::from("Private"),
|
level: String::from("Private"),
|
||||||
song_id: -1,
|
song_id: uuid::Uuid::new_v4(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/album.rs
22
src/album.rs
@@ -1,25 +1,37 @@
|
|||||||
pub mod collection {
|
pub mod collection {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::default::Default;
|
||||||
|
|
||||||
fn is_set(num: &i32) -> bool {
|
use std::fs::File;
|
||||||
*num >= 0
|
use std::io::BufReader;
|
||||||
|
|
||||||
|
use crate::init;
|
||||||
|
|
||||||
|
pub fn parse_album(filepath: &String) -> Result<Album, serde_json::Error> {
|
||||||
|
let file = File::open(filepath).expect("Failed to open file");
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
serde_json::from_reader(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
pub struct Album {
|
pub struct Album {
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
#[serde(alias = "album")]
|
#[serde(alias = "album")]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
|
#[serde(alias = "album_artist")]
|
||||||
|
pub artist: String,
|
||||||
pub genre: String,
|
pub genre: String,
|
||||||
pub year: i32,
|
pub year: i32,
|
||||||
pub track_count: i32,
|
pub track_count: i32,
|
||||||
#[serde(skip_serializing_if = "is_set")]
|
#[serde(skip_serializing_if = "init::is_set")]
|
||||||
pub disc_count: i32,
|
pub disc_count: i32,
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
pub tracks: Vec<Track>,
|
pub tracks: Vec<Track>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
pub struct Track {
|
pub struct Track {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub artist: String,
|
pub artist: String,
|
||||||
|
@@ -1,5 +1,14 @@
|
|||||||
pub const DEFAULTMUSICEXTENSION: &str = FLACEXTENSION;
|
pub mod file_extensions {
|
||||||
pub const FLACEXTENSION: &str = ".flac";
|
pub mod audio {
|
||||||
pub const WAVEXTENSION: &str = ".wav";
|
pub const DEFAULTMUSICEXTENSION: &str = FLACEXTENSION;
|
||||||
pub const MPTHREEEXTENSION: &str = ".mp3";
|
pub const FLACEXTENSION: &str = ".flac";
|
||||||
pub const JPGEXTENSION: &str = ".jpg";
|
pub const WAVEXTENSION: &str = ".wav";
|
||||||
|
pub const MPTHREEEXTENSION: &str = ".mp3";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod image {
|
||||||
|
pub const JPGEXTENSION: &str = ".jpg";
|
||||||
|
pub const JPEGEXTENSION: &str = ".jpeg";
|
||||||
|
pub const PNGEXTENSION: &str = ".png";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,18 +1,66 @@
|
|||||||
use std::io::Read;
|
use std::io::Write;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct CoverArt {
|
pub struct CoverArt {
|
||||||
pub id: i32,
|
pub id: uuid::Uuid,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
#[serde(skip)]
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
#[serde(skip)]
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
|
pub song_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod init {
|
||||||
|
use crate::coverart::CoverArt;
|
||||||
|
|
||||||
|
pub fn init_coverart_only_path(path: String) -> CoverArt {
|
||||||
|
CoverArt {
|
||||||
|
id: uuid::Uuid::nil(),
|
||||||
|
title: String::new(),
|
||||||
|
path: path.clone(),
|
||||||
|
data: Vec::new(),
|
||||||
|
song_id: uuid::Uuid::nil(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoverArt {
|
impl CoverArt {
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
/// Saves the coverart to the filesystem
|
||||||
let path: &String = &self.path;
|
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
||||||
|
match std::fs::File::create(&self.path) {
|
||||||
|
Ok(mut file) => match file.write_all(&self.data) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the coverart from the filesystem
|
||||||
|
pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> {
|
||||||
|
let p = std::path::Path::new(&self.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",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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> {
|
||||||
|
let path: &String = &coverart.path;
|
||||||
let mut file = std::fs::File::open(path)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
match file.read_to_end(&mut buffer) {
|
match file.read_to_end(&mut buffer) {
|
||||||
@@ -21,3 +69,16 @@ impl CoverArt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::coverart;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cover_art_image() {
|
||||||
|
let path: String = String::from("somepath");
|
||||||
|
let coverart = coverart::init::init_coverart_only_path(path.clone());
|
||||||
|
|
||||||
|
assert_eq!(path, coverart.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
22
src/lib.rs
22
src/lib.rs
@@ -7,3 +7,25 @@ pub mod song;
|
|||||||
pub mod token;
|
pub mod token;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
|
pub mod init {
|
||||||
|
pub fn is_id_valid(num: &i32) -> bool {
|
||||||
|
*num > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_uuid_nil(uuid: &uuid::Uuid) -> bool {
|
||||||
|
uuid.is_nil()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero(num: &i32) -> bool {
|
||||||
|
*num == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_dur_not_set(num: &i32) -> bool {
|
||||||
|
*num == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_set(num: &i32) -> bool {
|
||||||
|
*num >= 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -2,20 +2,20 @@ use std::default::Default;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct LoginResult {
|
pub struct LoginResult {
|
||||||
pub id: i32,
|
pub id: uuid::Uuid,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
#[serde(alias = "token_type")]
|
#[serde(alias = "token_type")]
|
||||||
pub token_type: String,
|
pub token_type: String,
|
||||||
pub expiration: i32,
|
pub expiration: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LoginResult {
|
impl Default for LoginResult {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
LoginResult {
|
LoginResult {
|
||||||
id: -1,
|
id: uuid::Uuid::nil(),
|
||||||
username: String::new(),
|
username: String::new(),
|
||||||
token: String::new(),
|
token: String::new(),
|
||||||
token_type: String::new(),
|
token_type: String::new(),
|
||||||
|
359
src/song.rs
359
src/song.rs
@@ -1,16 +1,20 @@
|
|||||||
use std::io::Read;
|
use std::io::Write;
|
||||||
|
|
||||||
use crate::constants;
|
|
||||||
use crate::types;
|
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
use crate::constants;
|
||||||
|
use crate::init;
|
||||||
|
use crate::types;
|
||||||
|
|
||||||
|
/// Length of characters of a filename to be generated
|
||||||
|
const FILENAME_LENGTH: i32 = 16;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
#[serde(alias = "id")]
|
#[serde(alias = "id")]
|
||||||
pub id: i32,
|
pub id: uuid::Uuid,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
@@ -21,17 +25,17 @@ pub struct Song {
|
|||||||
pub album_artist: String,
|
pub album_artist: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub genre: String,
|
pub genre: String,
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_zero")]
|
||||||
pub year: i32,
|
pub year: i32,
|
||||||
#[serde(skip_serializing_if = "is_dur_not_set")]
|
#[serde(skip_serializing_if = "init::is_dur_not_set")]
|
||||||
pub duration: i32,
|
pub duration: i32,
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_zero")]
|
||||||
pub track: i32,
|
pub track: i32,
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_zero")]
|
||||||
pub disc: i32,
|
pub disc: i32,
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_zero")]
|
||||||
pub disc_count: i32,
|
pub disc_count: i32,
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_zero")]
|
||||||
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,
|
||||||
@@ -39,12 +43,13 @@ pub struct Song {
|
|||||||
pub date_created: String,
|
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 = "is_zero")]
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
pub user_id: i32,
|
pub user_id: uuid::Uuid,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub directory: String,
|
pub directory: String,
|
||||||
|
// TODO: Think about what to do with this
|
||||||
// #[serde(skip)]
|
// #[serde(skip)]
|
||||||
// pub album_id: i32,
|
// pub album_id: i32,
|
||||||
// #[serde(skip)]
|
// #[serde(skip)]
|
||||||
@@ -55,14 +60,6 @@ pub struct Song {
|
|||||||
// pub coverart_id: i32,
|
// pub coverart_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_zero(num: &i32) -> bool {
|
|
||||||
*num == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_dur_not_set(num: &i32) -> bool {
|
|
||||||
*num == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Song {
|
impl Song {
|
||||||
pub fn to_metadata_json(&self, pretty: bool) -> Result<String, serde_json::Error> {
|
pub fn to_metadata_json(&self, pretty: bool) -> Result<String, serde_json::Error> {
|
||||||
if pretty {
|
if pretty {
|
||||||
@@ -74,10 +71,7 @@ impl 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::new(
|
return Err(std::io::Error::other("Directory does not exist"));
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Directory does not exist",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let directory = &self.directory;
|
let directory = &self.directory;
|
||||||
@@ -93,27 +87,129 @@ impl Song {
|
|||||||
|
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::new(
|
Err(std::io::Error::other(
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Could not access last character of directory",
|
"Could not access last character of directory",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
/// Saves the song to the filesystem using the song's data
|
||||||
let path_result = self.song_path();
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match path_result {
|
/// 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, the song must have
|
||||||
|
/// a directory and filename
|
||||||
|
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
||||||
|
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 mut filename: String = String::new();
|
||||||
|
let some_chars: String = String::from("abcdefghij0123456789");
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
|
for _ in 0..FILENAME_LENGTH {
|
||||||
|
let index = rng.random_range(0..=19);
|
||||||
|
let rando_char = some_chars.chars().nth(index);
|
||||||
|
|
||||||
|
if let Some(c) = rando_char {
|
||||||
|
filename.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filename + &file_extension
|
||||||
|
} else {
|
||||||
|
"track-output".to_string() + &file_extension
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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(song: &super::Song) -> Result<Vec<u8>, std::io::Error> {
|
||||||
|
match song.song_path() {
|
||||||
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();
|
||||||
file.read_to_end(&mut buffer)?;
|
file.read_to_end(&mut buffer)?;
|
||||||
|
|
||||||
if buffer.is_empty() {
|
if buffer.is_empty() {
|
||||||
Err(std::io::Error::new(
|
Err(std::io::Error::other("File is empty"))
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"File is empty",
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
@@ -121,195 +217,4 @@ impl Song {
|
|||||||
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::DEFAULTMUSICEXTENSION)
|
|
||||||
}
|
|
||||||
|
|
||||||
types::MusicTypes::WavExtension => String::from(constants::WAVEXTENSION),
|
|
||||||
types::MusicTypes::FlacExtension => String::from(constants::FLACEXTENSION),
|
|
||||||
types::MusicTypes::MPThreeExtension => String::from(constants::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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
mod embedded {
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
impl Song {
|
|
||||||
pub fn to_metadata_json(&self, pretty: bool) -> Result<String, serde_json::Error> {
|
|
||||||
if pretty {
|
|
||||||
serde_json::to_string_pretty(&self)
|
|
||||||
} else {
|
|
||||||
serde_json::to_string(&self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn song_path(&self) -> Result<String, std::io::Error> {
|
|
||||||
if self.directory.is_empty() {
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Directory does not exist",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let directory = &self.directory;
|
|
||||||
let mut buffer: String = directory.clone();
|
|
||||||
let last_index = directory.len() - 1;
|
|
||||||
|
|
||||||
if let Some(character) = directory.chars().nth(last_index) {
|
|
||||||
if character != '/' {
|
|
||||||
buffer += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += &self.filename.clone();
|
|
||||||
|
|
||||||
Ok(buffer)
|
|
||||||
} else {
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Could not access last character of directory",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_data(&self) -> Result<Vec<u8>, std::io::Error> {
|
|
||||||
let path_result = self.song_path();
|
|
||||||
|
|
||||||
match path_result {
|
|
||||||
Ok(path) => {
|
|
||||||
let mut file = std::fs::File::open(path)?;
|
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
|
||||||
file.read_to_end(&mut buffer)?;
|
|
||||||
|
|
||||||
if buffer.is_empty() {
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"File is empty",
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Ok(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(er) => Err(er),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The song's duration is a floating point in seconds
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Song {
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
#[serde(alias = "id")]
|
|
||||||
pub id: i32,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub title: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub artist: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub album: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub album_artist: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub genre: String,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub year: i32,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_dur_not_set")]
|
|
||||||
pub duration: f64,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub track: i32,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub disc: i32,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub disc_count: i32,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub track_count: i32,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub audio_type: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub date_created: String,
|
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub filename: String,
|
|
||||||
#[serde(skip_serializing_if = "is_embed_zero")]
|
|
||||||
pub user_id: i32,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub data: Vec<u8>,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub directory: String,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub album_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub artist_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub genre_id: i32,
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub coverart_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_embed_zero(num: &i32) -> bool {
|
|
||||||
*num == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_embed_dur_not_set(num: &f64) -> bool {
|
|
||||||
*num == 0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Song {
|
|
||||||
fn default() -> Self {
|
|
||||||
Song {
|
|
||||||
id: 0,
|
|
||||||
title: String::new(),
|
|
||||||
artist: String::new(),
|
|
||||||
album: String::new(),
|
|
||||||
album_artist: String::new(),
|
|
||||||
genre: String::new(),
|
|
||||||
year: 0,
|
|
||||||
duration: 0.0,
|
|
||||||
track: 0,
|
|
||||||
disc: 0,
|
|
||||||
disc_count: 0,
|
|
||||||
track_count: 0,
|
|
||||||
audio_type: String::new(),
|
|
||||||
date_created: String::new(),
|
|
||||||
filename: String::new(),
|
|
||||||
user_id: 0,
|
|
||||||
data: Vec::new(),
|
|
||||||
directory: String::new(),
|
|
||||||
// album_id: 0,
|
|
||||||
// artist_id: 0,
|
|
||||||
// genre_id: 0,
|
|
||||||
// coverart_id: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
157
src/token.rs
157
src/token.rs
@@ -5,16 +5,16 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Token {
|
pub struct Token {
|
||||||
pub scope: String,
|
pub scope: String,
|
||||||
pub expiration: i32,
|
pub expiration: i64,
|
||||||
pub audience: String,
|
pub audience: String,
|
||||||
pub issuer: String,
|
pub issuer: String,
|
||||||
pub issued: i32,
|
pub issued: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct AccessToken {
|
pub struct AccessToken {
|
||||||
#[serde(alias = "user_id")]
|
#[serde(alias = "init::is_uuid_nil")]
|
||||||
pub user_id: i32,
|
pub user_id: uuid::Uuid,
|
||||||
#[serde(alias = "username")]
|
#[serde(alias = "username")]
|
||||||
pub username: String,
|
pub username: String,
|
||||||
#[serde(alias = "token")]
|
#[serde(alias = "token")]
|
||||||
@@ -22,7 +22,7 @@ pub struct AccessToken {
|
|||||||
#[serde(alias = "token_type")]
|
#[serde(alias = "token_type")]
|
||||||
pub token_type: String,
|
pub token_type: String,
|
||||||
#[serde(alias = "expiration")]
|
#[serde(alias = "expiration")]
|
||||||
pub expiration: i32,
|
pub expiration: i64,
|
||||||
#[serde(alias = "message")]
|
#[serde(alias = "message")]
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
@@ -57,14 +57,145 @@ impl Token {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
pub fn contains_scope(&self, des_scope: &String) -> bool {
|
pub fn contains_scope(&self, des_scope: &String) -> bool {
|
||||||
let extracted_token: String = String::from("Token");
|
self.scope.contains(des_scope)
|
||||||
|
}
|
||||||
if extracted_token == *des_scope {
|
}
|
||||||
return true;
|
|
||||||
}
|
pub fn get_issued() -> time::Result<time::OffsetDateTime> {
|
||||||
|
Ok(time::OffsetDateTime::now_utc())
|
||||||
false
|
}
|
||||||
|
|
||||||
|
mod util {
|
||||||
|
pub fn time_to_std_time(
|
||||||
|
provided_time: &time::OffsetDateTime,
|
||||||
|
) -> Result<std::time::SystemTime, std::time::SystemTimeError> {
|
||||||
|
let converted = std::time::SystemTime::from(*provided_time);
|
||||||
|
Ok(converted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct TokenResource {
|
||||||
|
pub message: String,
|
||||||
|
pub issuer: String,
|
||||||
|
pub audiences: Vec<String>,
|
||||||
|
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);
|
||||||
|
|
||||||
|
let mut payload = josekit::jwt::JwtPayload::new();
|
||||||
|
let message = &token_resource.message;
|
||||||
|
let issuer = &token_resource.issuer;
|
||||||
|
let audiences: &Vec<String> = &token_resource.audiences;
|
||||||
|
payload.set_subject(message);
|
||||||
|
payload.set_issuer(issuer);
|
||||||
|
payload.set_audience(audiences.clone());
|
||||||
|
if !token_resource.id.is_nil() {
|
||||||
|
match payload.set_claim("id", Some(serde_json::json!(token_resource.id))) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match get_issued() {
|
||||||
|
Ok(issued) => {
|
||||||
|
let expire = issued + duration;
|
||||||
|
payload.set_issued_at(&util::time_to_std_time(&issued).unwrap());
|
||||||
|
payload.set_expires_at(&util::time_to_std_time(&expire).unwrap());
|
||||||
|
|
||||||
|
let signer = josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256
|
||||||
|
.signer_from_bytes(key.as_bytes())
|
||||||
|
.unwrap();
|
||||||
|
Ok((
|
||||||
|
josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
|
||||||
|
(expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn test_key() -> String {
|
||||||
|
String::from("c3092urmc2219ix320i40m293ic29IM09IN0u879Y8B98YB8yb86TN7B55R4yv4RCVU6Bi8YO8U")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_resource() -> TokenResource {
|
||||||
|
TokenResource {
|
||||||
|
issuer: String::from("icarus_auth_test"),
|
||||||
|
message: String::from("Authorization"),
|
||||||
|
audiences: vec![String::from("icarus_test")],
|
||||||
|
id: uuid::Uuid::nil(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_token_scope_check() {
|
||||||
|
let mut token = Token::default();
|
||||||
|
token.scope = String::from("song:read song:upload song:download");
|
||||||
|
|
||||||
|
let check_scope = String::from("song:download");
|
||||||
|
let result = token.contains_scope(&check_scope);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
result,
|
||||||
|
"Error: The scope {:?} was not found in the token's scope {:?}",
|
||||||
|
check_scope, token.scope
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_token_creation() {
|
||||||
|
let key = test_key();
|
||||||
|
let test_token_resource = test_resource();
|
||||||
|
let token_expiration_duration = time::Duration::hours(2);
|
||||||
|
|
||||||
|
match create_token(&key, &test_token_resource, token_expiration_duration) {
|
||||||
|
Ok((token, expire_duration)) => {
|
||||||
|
assert_eq!(false, token.is_empty(), "Error: Token is empty");
|
||||||
|
assert!(
|
||||||
|
expire_duration > 0,
|
||||||
|
"Token expire duration is invalid {expire_duration:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_token_creation_with_id() {
|
||||||
|
let key = test_key();
|
||||||
|
let mut test_token_resource = test_resource();
|
||||||
|
test_token_resource.id = uuid::Uuid::new_v4();
|
||||||
|
let token_expiration_duration = time::Duration::hours(2);
|
||||||
|
|
||||||
|
match create_token(&key, &test_token_resource, token_expiration_duration) {
|
||||||
|
Ok((token, expire_duration)) => {
|
||||||
|
assert_eq!(false, token.is_empty(), "Error: Token is empty");
|
||||||
|
assert!(
|
||||||
|
expire_duration > 0,
|
||||||
|
"Token expire duration is invalid {expire_duration:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
src/user.rs
55
src/user.rs
@@ -1,11 +1,13 @@
|
|||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::init;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
#[serde(skip_serializing_if = "is_id_valid")]
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
pub id: i32,
|
pub id: uuid::Uuid,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub username: String,
|
pub username: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
@@ -19,22 +21,20 @@ pub struct User {
|
|||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub lastname: String,
|
pub lastname: String,
|
||||||
pub email_verified: bool,
|
pub email_verified: bool,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub date_created: String,
|
pub date_created: Option<time::OffsetDateTime>,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub status: String,
|
pub status: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub last_login: String,
|
pub last_login: Option<time::OffsetDateTime>,
|
||||||
}
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
|
pub salt_id: uuid::Uuid,
|
||||||
fn is_id_valid(num: &i32) -> bool {
|
|
||||||
*num > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for User {
|
impl Default for User {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
User {
|
User {
|
||||||
id: -1,
|
id: uuid::Uuid::new_v4(),
|
||||||
username: String::new(),
|
username: String::new(),
|
||||||
password: String::new(),
|
password: String::new(),
|
||||||
email: String::new(),
|
email: String::new(),
|
||||||
@@ -42,9 +42,10 @@ impl Default for User {
|
|||||||
firstname: String::new(),
|
firstname: String::new(),
|
||||||
lastname: String::new(),
|
lastname: String::new(),
|
||||||
email_verified: false,
|
email_verified: false,
|
||||||
date_created: String::new(),
|
date_created: None,
|
||||||
status: String::new(),
|
status: String::new(),
|
||||||
last_login: String::new(),
|
last_login: None,
|
||||||
|
salt_id: uuid::Uuid::nil(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,3 +59,29 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod salt {
|
||||||
|
use std::default::Default;
|
||||||
|
|
||||||
|
use crate::init;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub struct Salt {
|
||||||
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
|
pub salt: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Salt {
|
||||||
|
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
|
||||||
|
if output_pretty {
|
||||||
|
serde_json::to_string_pretty(&self)
|
||||||
|
} else {
|
||||||
|
serde_json::to_string(&self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Binary file not shown.
137
tests/tests.rs
137
tests/tests.rs
@@ -1,19 +1,13 @@
|
|||||||
mod song_tests {
|
mod utils {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::io::Read;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use tempfile::tempdir;
|
pub fn get_tests_directory() -> String {
|
||||||
|
|
||||||
use icarus_models::song;
|
|
||||||
use icarus_models::types;
|
|
||||||
|
|
||||||
fn get_tests_directory() -> String {
|
|
||||||
String::from(env!("CARGO_MANIFEST_DIR").to_owned() + "/tests/")
|
String::from(env!("CARGO_MANIFEST_DIR").to_owned() + "/tests/")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn does_directory_exists(directory: &String) -> bool {
|
pub fn does_directory_exists(directory: &String) -> bool {
|
||||||
let path = Path::new(directory);
|
let path = Path::new(directory);
|
||||||
if let Ok(dir_i) = fs::metadata(path) {
|
if let Ok(dir_i) = fs::metadata(path) {
|
||||||
dir_i.is_dir()
|
dir_i.is_dir()
|
||||||
@@ -22,7 +16,7 @@ mod song_tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_data_from_file(filepath: &String) -> Result<Vec<u8>, std::io::Error> {
|
pub fn extract_data_from_file(filepath: &String) -> Result<Vec<u8>, std::io::Error> {
|
||||||
match std::fs::File::open(filepath) {
|
match std::fs::File::open(filepath) {
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
@@ -32,6 +26,15 @@ mod song_tests {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod song_tests {
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
use crate::utils;
|
||||||
|
use icarus_models::song;
|
||||||
|
use icarus_models::types;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_song_to_data() {
|
fn test_song_to_data() {
|
||||||
@@ -43,22 +46,22 @@ mod song_tests {
|
|||||||
|
|
||||||
println!("Getting track");
|
println!("Getting track");
|
||||||
let mut song = song::Song::default();
|
let mut song = song::Song::default();
|
||||||
song.directory = get_tests_directory();
|
song.directory = utils::get_tests_directory();
|
||||||
song.filename = String::from("track01.flac");
|
song.filename = String::from("track01.flac");
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
does_directory_exists(&song.directory),
|
utils::does_directory_exists(&song.directory),
|
||||||
"Directory does not exist"
|
"Directory does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Directory: {}", song.directory);
|
println!("Directory: {}", song.directory);
|
||||||
|
|
||||||
match song.song_path() {
|
match song.song_path() {
|
||||||
Ok(filepath) => match extract_data_from_file(&filepath) {
|
Ok(filepath) => match utils::extract_data_from_file(&filepath) {
|
||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
assert_eq!(buffer.is_empty(), false);
|
assert_eq!(buffer.is_empty(), false);
|
||||||
|
|
||||||
match song.to_data() {
|
match song::io::to_data(&song) {
|
||||||
Ok(song_data) => {
|
Ok(song_data) => {
|
||||||
println!("Both files match");
|
println!("Both files match");
|
||||||
assert_eq!(buffer, song_data);
|
assert_eq!(buffer, song_data);
|
||||||
@@ -81,11 +84,11 @@ mod song_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_song_path_check() {
|
fn test_song_path_check() {
|
||||||
let mut song = song::Song::default();
|
let mut song = song::Song::default();
|
||||||
song.directory = get_tests_directory();
|
song.directory = utils::get_tests_directory();
|
||||||
song.filename = String::from("track01.flac");
|
song.filename = String::from("track01.flac");
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
does_directory_exists(&song.directory),
|
utils::does_directory_exists(&song.directory),
|
||||||
"Directory does not exist"
|
"Directory does not exist"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -93,53 +96,77 @@ mod song_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_song_generate_filename() {
|
fn test_song_generate_filename() {
|
||||||
let mut song = song::Song::default();
|
let mut song = song::Song::default();
|
||||||
song.directory = get_tests_directory();
|
song.directory = utils::get_tests_directory();
|
||||||
song.filename = String::from("track01.flac");
|
song.filename = String::from("track01.flac");
|
||||||
|
|
||||||
match song.song_path() {
|
let mut song_cpy = song.clone();
|
||||||
Ok(songpath) => match extract_data_from_file(&songpath) {
|
let temp_dir = tempdir().expect("Failed to create temp dir");
|
||||||
Ok(buffer) => {
|
song_cpy.directory = match temp_dir.path().to_str() {
|
||||||
let mut song_cpy = song.clone();
|
Some(s) => String::from(s),
|
||||||
let temp_dir = tempdir().expect("Failed to create temp dir");
|
None => String::new(),
|
||||||
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);
|
||||||
song_cpy.filename =
|
song_cpy.filename = song::generate_filename(types::MusicTypes::FlacExtension, true);
|
||||||
song.generate_filename(types::MusicTypes::FlacExtension, true);
|
println!("Directory: {:?}", song_cpy.directory);
|
||||||
println!("Directory: {:?}", song_cpy.directory);
|
println!("File to be created: {:?}", song_cpy.filename);
|
||||||
println!("File to be created: {:?}", song_cpy.filename);
|
|
||||||
|
|
||||||
let path = match song_cpy.song_path() {
|
match song::io::copy_song(&song, &mut song_cpy) {
|
||||||
Ok(s_path) => s_path,
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {:?}", err);
|
assert!(false, "Error copying song: Error: {err:?}")
|
||||||
String::new()
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
match File::create(path) {
|
#[test]
|
||||||
Ok(mut file_cpy) => match file_cpy.write_all(&buffer) {
|
fn test_save_song_to_filesystem_and_remove() {
|
||||||
Ok(success) => {
|
let mut song = song::Song::default();
|
||||||
println!("Success: {:?}", success);
|
song.directory = utils::get_tests_directory();
|
||||||
}
|
song.filename = String::from("track02.flac");
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error saving file: {:?}", err);
|
let mut copied_song = song::Song {
|
||||||
}
|
directory: utils::get_tests_directory(),
|
||||||
},
|
filename: String::from("track02-coppied.flac"),
|
||||||
Err(err) => {
|
..Default::default()
|
||||||
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 extracting song data: {:?}", err);
|
assert!(false, "Error: {err:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod album_tests {
|
||||||
|
use crate::utils;
|
||||||
|
use icarus_models::album;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_album() {
|
||||||
|
let test_dir = utils::get_tests_directory();
|
||||||
|
if utils::does_directory_exists(&test_dir) {
|
||||||
|
let album_file: String = test_dir + &String::from("album.json");
|
||||||
|
println!("Album file: {:?}", album_file);
|
||||||
|
|
||||||
|
match album::collection::parse_album(&album_file) {
|
||||||
|
Ok(album) => {
|
||||||
|
println!("Album title: {}", album.title);
|
||||||
|
assert_eq!(album.title.is_empty(), false);
|
||||||
|
assert_eq!(album.artist.is_empty(), false);
|
||||||
|
assert_eq!(album.tracks.is_empty(), false);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error parsing album json file: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user