Compare commits
98 Commits
32-impleme
...
17-use-web
Author | SHA1 | Date | |
---|---|---|---|
5d1e8cb01b | |||
bf89838297 | |||
b7e5327903
|
|||
8fea5fcec7
|
|||
266bba05aa | |||
86f9b6fbb3
|
|||
da45a503ac | |||
074f866e5f
|
|||
cb0936003c | |||
d66849c6cb
|
|||
b54ecb5b27 | |||
0ee61f288f
|
|||
8c516e3070 | |||
22f3749ee4
|
|||
7cb556e5ef | |||
bab819822d
|
|||
0c54f0aeb8
|
|||
afbcc65457
|
|||
e5a6e8f44e
|
|||
d45f102be7
|
|||
74b34b1e54
|
|||
2ea3979a89 | |||
21bb2d127f
|
|||
76631126de
|
|||
f8bbe319bd
|
|||
ffad799f72
|
|||
c72d4aee18
|
|||
8a474077da | |||
6202b287f0
|
|||
6b8c8d41e4
|
|||
4513335784 | |||
fa26ee40ed
|
|||
c27ad19499
|
|||
6ae55d5cfc
|
|||
7bcb5f8c04 | |||
9a462d5ee9
|
|||
5cc504b4d6 | |||
eb4dcd4776
|
|||
355c791ea7
|
|||
b0edd2174e
|
|||
3978526231
|
|||
0adf294cfc
|
|||
e7e7a8175e
|
|||
952fb93e1e
|
|||
1633d8c1a5
|
|||
b4054aa2b7
|
|||
3934a25900
|
|||
26c34e0012 | |||
522658c0dc | |||
3c9ae521b1
|
|||
4958d3a881 | |||
965bf5a457
|
|||
8ffe09381c
|
|||
12384b5a75
|
|||
bf9067aa43
|
|||
7b43906632
|
|||
4685861af3
|
|||
df78afbe60
|
|||
caefc46fcc | |||
94d62ea2d5
|
|||
893c411c7f
|
|||
618b7d65ce
|
|||
78d8e1243d
|
|||
955fc84412 | |||
cc4aee4ab4
|
|||
5775d3148b | |||
714fbc596a | |||
ff43b3f7e8
|
|||
e411ab9eee
|
|||
775c7eff3a
|
|||
2ed67e5545
|
|||
08f1b95c18
|
|||
7a750b60aa
|
|||
2b9d849578
|
|||
28ff98ab32
|
|||
a0da89204c
|
|||
c07237ad8a
|
|||
727029b757
|
|||
8a959d530d
|
|||
7abfbaf600
|
|||
161ea5f9c2
|
|||
353a8e3a9c
|
|||
5d7ac2bb80
|
|||
695f404ba8
|
|||
79ba191415
|
|||
3338cc2662
|
|||
60ad643669 | |||
490772654d
|
|||
b2fd8dc8e5
|
|||
91812f4695
|
|||
9b1ea51896 | |||
6bf08b7507
|
|||
04e0a66122
|
|||
b6066e2d3e
|
|||
241389e5f7
|
|||
557c189a17
|
|||
4f6f3f90c1
|
|||
7062c75013
|
@ -8,3 +8,4 @@
|
|||||||
!/style
|
!/style
|
||||||
!/Cargo.lock
|
!/Cargo.lock
|
||||||
!/Cargo.toml
|
!/Cargo.toml
|
||||||
|
!/ascii_art.txt
|
||||||
|
119
.gitea/workflows/push.yaml
Normal file
119
.gitea/workflows/push.yaml
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
name: Push Workflows
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Install cargo-leptos
|
||||||
|
run: cargo install cargo-leptos
|
||||||
|
- name: Build project
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-D warnings"
|
||||||
|
run: cargo-leptos build
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to Gitea container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.registry }}
|
||||||
|
username: ${{ env.actions_user }}
|
||||||
|
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
||||||
|
- name: Get Image Name
|
||||||
|
id: get-image-name
|
||||||
|
run: |
|
||||||
|
echo "IMAGE_NAME=$(echo ${{ env.registry }}/${{ gitea.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: "${{ steps.get-image-name.outputs.IMAGE_NAME }}:${{ gitea.sha }}"
|
||||||
|
cache-from: type=registry,ref=${{ steps.get-image-name.outputs.IMAGE_NAME }}:${{ gitea.sha }}
|
||||||
|
cache-to: type=inline
|
||||||
|
- name: Build and push Docker image with "latest" tag
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
if: gitea.ref == 'refs/heads/main'
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: "${{ steps.get-image-name.outputs.IMAGE_NAME }}:latest"
|
||||||
|
cache-from: type=registry,ref=${{ steps.get-image-name.outputs.IMAGE_NAME }}:latest
|
||||||
|
cache-to: type=inline
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Test project
|
||||||
|
run: cargo test --all-targets --all-features
|
||||||
|
|
||||||
|
leptos-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Install cargo-leptos
|
||||||
|
run: cargo install cargo-leptos
|
||||||
|
- name: Run Leptos tests
|
||||||
|
run: cargo-leptos test
|
||||||
|
|
||||||
|
docs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Generate docs
|
||||||
|
run: cargo doc --no-deps
|
||||||
|
- name: Upload docs
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: docs
|
||||||
|
path: target/doc
|
101
.gitlab-ci.yml
101
.gitlab-ci.yml
@ -1,101 +0,0 @@
|
|||||||
# Build the project
|
|
||||||
build:
|
|
||||||
needs: []
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
variables:
|
|
||||||
RUSTFLAGS: "-D warnings"
|
|
||||||
script:
|
|
||||||
- cargo-leptos build
|
|
||||||
|
|
||||||
.docker:
|
|
||||||
image: docker:latest
|
|
||||||
services:
|
|
||||||
- docker:dind
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
before_script:
|
|
||||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
||||||
|
|
||||||
# Build the docker image and push it to the registry
|
|
||||||
docker-build:
|
|
||||||
needs: ["build"]
|
|
||||||
extends: .docker
|
|
||||||
script:
|
|
||||||
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
|
|
||||||
# If running on the default branch, tag as latest
|
|
||||||
- if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then docker tag
|
|
||||||
$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
|
||||||
$CI_REGISTRY_IMAGE:latest; fi
|
|
||||||
- docker push $CI_REGISTRY_IMAGE --all-tags
|
|
||||||
|
|
||||||
# Run leptos tests
|
|
||||||
leptos-tests:
|
|
||||||
needs: ["build"]
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
script:
|
|
||||||
- cargo-leptos test
|
|
||||||
|
|
||||||
# Run all tests
|
|
||||||
tests:
|
|
||||||
needs: ["build"]
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
script:
|
|
||||||
- cargo test --all-targets --all-features
|
|
||||||
|
|
||||||
# Generate docs
|
|
||||||
cargo-doc:
|
|
||||||
needs: []
|
|
||||||
image: rust:slim
|
|
||||||
script:
|
|
||||||
- cargo doc --no-deps
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/doc
|
|
||||||
|
|
||||||
# Start the review environment
|
|
||||||
start-review:
|
|
||||||
extends: .docker
|
|
||||||
rules:
|
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
||||||
when: manual
|
|
||||||
script:
|
|
||||||
- apk add curl openssl
|
|
||||||
- cd cicd
|
|
||||||
- echo "$CLOUDFLARE_TUNNEL_AUTH_JSON" > tunnel-auth.json
|
|
||||||
- ./add-dns.sh $CLOUDFLARE_ZONE_ID review-$CI_COMMIT_SHORT_SHA libretunes-auto-review $CLOUDFLARE_API_TOKEN $CLOUDFLARE_TUNNEL_ID
|
|
||||||
- ./create-tunnel-config.sh http://libretunes:3000 review-$CI_COMMIT_SHORT_SHA.libretunes.xyz $CLOUDFLARE_TUNNEL_ID
|
|
||||||
- export COMPOSE_PROJECT_NAME=review-$CI_COMMIT_SHORT_SHA
|
|
||||||
- export POSTGRES_PASSWORD=$(openssl rand -hex 16)
|
|
||||||
- export LIBRETUNES_VERSION=$CI_COMMIT_SHORT_SHA
|
|
||||||
- docker compose --file docker-compose-cicd.yml pull
|
|
||||||
- docker compose --file docker-compose-cicd.yml create
|
|
||||||
- export CONFIG_VOL_NAME=review-${CI_COMMIT_SHORT_SHA}_cloudflared-config
|
|
||||||
- export TMP_CONTAINER_NAME=$(docker run --rm -d -v $CONFIG_VOL_NAME:/data busybox sh -c "sleep infinity")
|
|
||||||
- docker cp tunnel-auth.json $TMP_CONTAINER_NAME:/data/auth.json
|
|
||||||
- docker cp cloudflared-tunnel-config.yml $TMP_CONTAINER_NAME:/data/config.yml
|
|
||||||
- docker stop $TMP_CONTAINER_NAME
|
|
||||||
- docker compose --file docker-compose-cicd.yml up -d
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_SHORT_SHA
|
|
||||||
url: https://review-$CI_COMMIT_SHORT_SHA.libretunes.xyz
|
|
||||||
on_stop: stop-review
|
|
||||||
auto_stop_in: 1 week
|
|
||||||
|
|
||||||
# Stop the review environment
|
|
||||||
stop-review:
|
|
||||||
needs: ["start-review"]
|
|
||||||
extends: .docker
|
|
||||||
rules:
|
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
||||||
when: manual
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- apk add jq curl
|
|
||||||
- ./cicd/remove-dns.sh $CLOUDFLARE_ZONE_ID review-$CI_COMMIT_SHORT_SHA.libretunes.xyz libretunes-auto-review $CLOUDFLARE_API_TOKEN
|
|
||||||
- export COMPOSE_PROJECT_NAME=review-$CI_COMMIT_SHORT_SHA
|
|
||||||
- export LIBRETUNES_VERSION=$CI_COMMIT_SHORT_SHA
|
|
||||||
- docker compose --file cicd/docker-compose-cicd.yml down
|
|
||||||
- docker compose --file cicd/docker-compose-cicd.yml rm -f -v
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_SHORT_SHA
|
|
||||||
action: stop
|
|
213
Cargo.lock
generated
213
Cargo.lock
generated
@ -44,6 +44,21 @@ version = "0.2.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android-tzdata"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_system_properties"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.81"
|
version = "1.0.81"
|
||||||
@ -56,6 +71,12 @@ version = "1.7.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457"
|
checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-recursion"
|
name = "async-recursion"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -138,15 +159,11 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
|
||||||
"serde_path_to_error",
|
|
||||||
"serde_urlencoded",
|
|
||||||
"sync_wrapper 1.0.0",
|
"sync_wrapper 1.0.0",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"tracing",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -167,7 +184,6 @@ dependencies = [
|
|||||||
"sync_wrapper 0.1.2",
|
"sync_wrapper 0.1.2",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"tracing",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -244,6 +260,12 @@ version = "3.15.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa"
|
checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck"
|
||||||
|
version = "1.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@ -316,6 +338,18 @@ 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 = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
|
||||||
|
dependencies = [
|
||||||
|
"android-tzdata",
|
||||||
|
"iana-time-zone",
|
||||||
|
"num-traits",
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ciborium"
|
name = "ciborium"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@ -422,6 +456,12 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.12"
|
version = "0.2.12"
|
||||||
@ -613,6 +653,18 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flexi_logger"
|
||||||
|
version = "0.28.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f248c29a6d4bc5d065c9e9068d858761a0dcd796759f7801cc14db35db23abd8"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"glob",
|
||||||
|
"log",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "float-cmp"
|
name = "float-cmp"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@ -796,6 +848,12 @@ version = "0.28.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gloo-net"
|
name = "gloo-net"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@ -965,6 +1023,29 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone"
|
||||||
|
version = "0.1.60"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"iana-time-zone-haiku",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone-haiku"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icondata"
|
name = "icondata"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@ -1501,7 +1582,7 @@ dependencies = [
|
|||||||
"diesel",
|
"diesel",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"futures",
|
"flexi_logger",
|
||||||
"http",
|
"http",
|
||||||
"icondata",
|
"icondata",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -1510,17 +1591,21 @@ dependencies = [
|
|||||||
"leptos_icons",
|
"leptos_icons",
|
||||||
"leptos_meta",
|
"leptos_meta",
|
||||||
"leptos_router",
|
"leptos_router",
|
||||||
|
"log",
|
||||||
|
"multer",
|
||||||
"openssl",
|
"openssl",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"serde",
|
"serde",
|
||||||
|
"server_fn",
|
||||||
|
"symphonia",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tower-sessions",
|
|
||||||
"tower-sessions-redis-store",
|
"tower-sessions-redis-store",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2245,16 +2330,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_path_to_error"
|
|
||||||
version = "0.1.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6"
|
|
||||||
dependencies = [
|
|
||||||
"itoa",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_qs"
|
name = "serde_qs"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
@ -2284,23 +2359,11 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_urlencoded"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
|
||||||
dependencies = [
|
|
||||||
"form_urlencoded",
|
|
||||||
"itoa",
|
|
||||||
"ryu",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "server_fn"
|
name = "server_fn"
|
||||||
version = "0.6.10"
|
version = "0.6.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "15a46a2ffdecb81430ecfb995989218a18b6e94c1ead50cb806b5927c986a8ce"
|
checksum = "536a5b959673643ee01e59ae41bf01425482c8070dee95d7061ee2d45296b59c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"bytes",
|
"bytes",
|
||||||
@ -2314,6 +2377,7 @@ dependencies = [
|
|||||||
"hyper",
|
"hyper",
|
||||||
"inventory",
|
"inventory",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
"multer",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"send_wrapper",
|
"send_wrapper",
|
||||||
"serde",
|
"serde",
|
||||||
@ -2419,6 +2483,55 @@ version = "2.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"symphonia-bundle-mp3",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-bundle-mp3"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c01c2aae70f0f1fb096b6f0ff112a930b1fb3626178fba3ae68b09dce71706d4"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-core"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "798306779e3dc7d5231bd5691f5a813496dc79d3f56bf82e25789f2094e022c3"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"bytemuck",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-metadata"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc622b9841a10089c5b18e99eb904f4341615d5aa55bbf4eedde1be721a4023c"
|
||||||
|
dependencies = [
|
||||||
|
"encoding_rs",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
@ -2487,9 +2600,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.34"
|
version = "0.3.36"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
|
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
"itoa",
|
"itoa",
|
||||||
@ -2508,9 +2621,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time-macros"
|
name = "time-macros"
|
||||||
version = "0.2.17"
|
version = "0.2.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
|
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"time-core",
|
"time-core",
|
||||||
@ -2948,19 +3061,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.92"
|
version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
|
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
"wasm-bindgen-macro",
|
"wasm-bindgen-macro",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-backend"
|
name = "wasm-bindgen-backend"
|
||||||
version = "0.2.92"
|
version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
|
checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"log",
|
"log",
|
||||||
@ -2985,9 +3099,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.92"
|
version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
|
checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@ -2995,9 +3109,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.92"
|
version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -3008,9 +3122,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.92"
|
version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-streams"
|
name = "wasm-streams"
|
||||||
@ -3066,6 +3180,15 @@ 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 = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
43
Cargo.toml
43
Cargo.toml
@ -8,41 +8,50 @@ build = "src/build.rs"
|
|||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = { version = "0.1", optional = true }
|
||||||
cfg-if = "1"
|
cfg-if = "1"
|
||||||
http = "1.0"
|
http = { version = "1.0", default-features = false }
|
||||||
leptos = { version = "0.6", features = ["nightly"] }
|
leptos = { version = "0.6", default-features = false, features = ["nightly"] }
|
||||||
leptos_meta = { version = "0.6", features = ["nightly"] }
|
leptos_meta = { version = "0.6", features = ["nightly"] }
|
||||||
leptos_axum = { version = "0.6", optional = true }
|
leptos_axum = { version = "0.6", optional = true }
|
||||||
leptos_router = { version = "0.6", features = ["nightly"] }
|
leptos_router = { version = "0.6", features = ["nightly"] }
|
||||||
wasm-bindgen = "=0.2.92"
|
wasm-bindgen = { version = "=0.2.93", default-features = false, optional = true }
|
||||||
leptos_icons = { version = "0.3.0" }
|
leptos_icons = { version = "0.3.0" }
|
||||||
icondata = { version = "0.3.0" }
|
icondata = { version = "0.3.0" }
|
||||||
dotenv = { version = "0.15.0", optional = true }
|
dotenv = { version = "0.15.0", optional = true }
|
||||||
diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], optional = true }
|
diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], default-features = false, optional = true }
|
||||||
lazy_static = { version = "1.4.0", optional = true }
|
lazy_static = { version = "1.4.0", optional = true }
|
||||||
serde = { versions = "1.0.195", features = ["derive"] }
|
serde = { version = "1.0.195", features = ["derive"], default-features = false }
|
||||||
openssl = { version = "0.10.63", optional = true }
|
openssl = { version = "0.10.63", optional = true }
|
||||||
time = { version = "0.3.34", features = ["serde"] }
|
time = { version = "0.3.34", features = ["serde"], default-features = false }
|
||||||
diesel_migrations = { version = "2.1.0", optional = true }
|
diesel_migrations = { version = "2.1.0", optional = true }
|
||||||
pbkdf2 = { version = "0.12.2", features = ["simple"], optional = true }
|
pbkdf2 = { version = "0.12.2", features = ["simple"], optional = true }
|
||||||
futures = { version = "0.3.30", default-features = false, optional = true }
|
|
||||||
tokio = { version = "1", optional = true, features = ["rt-multi-thread"] }
|
tokio = { version = "1", optional = true, features = ["rt-multi-thread"] }
|
||||||
axum = { version = "0.7.5", optional = true }
|
axum = { version = "0.7.5", features = ["tokio", "http1"], default-features = false, optional = true }
|
||||||
tower = { veresion = "0.4.13", optional = true }
|
tower = { version = "0.4.13", optional = true }
|
||||||
tower-http = { version = "0.5", optional = true, features = ["fs"] }
|
tower-http = { version = "0.5", optional = true, features = ["fs"] }
|
||||||
thiserror = "1.0.57"
|
thiserror = "1.0.57"
|
||||||
tower-sessions = { version = "0.11", default-features = false }
|
|
||||||
tower-sessions-redis-store = { version = "0.11", optional = true }
|
tower-sessions-redis-store = { version = "0.11", optional = true }
|
||||||
async-trait = "0.1.79"
|
async-trait = { version = "0.1.79", optional = true }
|
||||||
axum-login = { version = "0.14.0", optional = true }
|
axum-login = { version = "0.14.0", optional = true }
|
||||||
|
server_fn = { version = "0.6.11", features = ["multipart"] }
|
||||||
|
symphonia = { version = "0.5.4", default-features = false, features = ["mp3"], optional = true }
|
||||||
|
multer = { version = "3.0.0", optional = true }
|
||||||
|
log = { version = "0.4.21", optional = true }
|
||||||
|
flexi_logger = { version = "0.28.0", optional = true, default-features = false }
|
||||||
|
web-sys = "0.3.69"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" }
|
gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
|
hydrate = [
|
||||||
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
|
"leptos/hydrate",
|
||||||
|
"leptos_meta/hydrate",
|
||||||
|
"leptos_router/hydrate",
|
||||||
|
"console_error_panic_hook",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
ssr = [
|
ssr = [
|
||||||
"dep:leptos_axum",
|
"dep:leptos_axum",
|
||||||
"leptos/ssr",
|
"leptos/ssr",
|
||||||
@ -54,13 +63,17 @@ ssr = [
|
|||||||
"openssl",
|
"openssl",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"futures",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"axum",
|
"axum",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tower-sessions-redis-store",
|
"tower-sessions-redis-store",
|
||||||
|
"async-trait",
|
||||||
"axum-login",
|
"axum-login",
|
||||||
|
"symphonia",
|
||||||
|
"multer",
|
||||||
|
"log",
|
||||||
|
"flexi_logger",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Defines a size-optimized profile for the WASM bundle in release mode
|
# Defines a size-optimized profile for the WASM bundle in release mode
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
FROM registry.mregirouard.com/libretunes/ops/docker-leptos/musl:latest as builder
|
FROM clux/muslrust:nightly AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
|
|
||||||
# Install a few dependencies
|
# Install a few dependencies
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apt-get update; \
|
apt-get update; \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
|
pkg-config \
|
||||||
|
clang \
|
||||||
npm; \
|
npm; \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN cargo install cargo-leptos
|
||||||
|
|
||||||
RUN npm install tailwindcss@3.1.8 -g
|
RUN npm install tailwindcss@3.1.8 -g
|
||||||
|
|
||||||
# Copy project dependency manifests
|
# Copy project dependency manifests
|
||||||
@ -32,6 +38,7 @@ COPY style /app/style
|
|||||||
# Minify CSS
|
# Minify CSS
|
||||||
RUN npx tailwindcss -i /app/style/main.scss -o /app/style/main.scss --minify
|
RUN npx tailwindcss -i /app/style/main.scss -o /app/style/main.scss --minify
|
||||||
|
|
||||||
|
COPY ascii_art.txt /app/ascii_art.txt
|
||||||
COPY assets /app/assets
|
COPY assets /app/assets
|
||||||
COPY src /app/src
|
COPY src /app/src
|
||||||
COPY migrations /app/migrations
|
COPY migrations /app/migrations
|
||||||
|
10
ascii_art.txt
Normal file
10
ascii_art.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.-=. =+==-.
|
||||||
|
.=++++. =+++++=.
|
||||||
|
_ _ _ _______ =++++++= :*++++++=
|
||||||
|
| | (_) | |__ __| -++++**+. -+**++++-
|
||||||
|
| | _| |__ _ __ ___| |_ _ _ __ ___ ___ *+++**+ +**+++*
|
||||||
|
| | | | '_ \| '__/ _ \ | | | | '_ \ / _ \/ __| *+++**+ +**+++*
|
||||||
|
| |____| | |_) | | | __/ | |_| | | | | __/\__ \ -++++**+-: +**++++-
|
||||||
|
|______|_|_.__/|_| \___|_|\__,_|_| |_|\___||___/ =++++++**+ -+++++=
|
||||||
|
.=+++++++=.+++=.
|
||||||
|
.-==++++---.
|
1
assets/images/placeholders/MusicPlaceholder.svg
Normal file
1
assets/images/placeholders/MusicPlaceholder.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg version="1.1" viewBox="0.0 0.0 960.0 960.0" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><clipPath id="p.0"><path d="m0 0l960.0 0l0 960.0l-960.0 0l0 -960.0z" clip-rule="nonzero"/></clipPath><g clip-path="url(#p.0)"><path fill="#4032a8" d="m0 0l960.0 0l0 960.0l-960.0 0z" fill-rule="evenodd"/><path fill="#ffffff" d="m290.11365 265.52475l35.496063 0l0 471.3386l-35.496063 0z" fill-rule="evenodd"/><path fill="#ffffff" d="m115.68951 737.6639l0 0c0 -36.946594 46.99247 -66.897644 104.960625 -66.897644l0 0c57.968155 0 104.96065 29.95105 104.96065 66.897644l0 0c0 36.946533 -46.992493 66.897644 -104.96065 66.897644l0 0c-57.968155 0 -104.960625 -29.95111 -104.960625 -66.897644z" fill-rule="evenodd"/><path fill="#ffffff" d="m723.79346 175.86597l35.496033 0l0 471.33856l-35.496033 0z" fill-rule="evenodd"/><path fill="#ffffff" d="m549.3693 648.00507l0 0c0 -36.946533 46.99243 -66.897644 104.96063 -66.897644l0 0c57.96814 0 104.96057 29.95111 104.96057 66.897644l0 0c0 36.946533 -46.99243 66.897644 -104.96057 66.897644l0 0c-57.9682 0 -104.96063 -29.95111 -104.96063 -66.897644z" fill-rule="evenodd"/><path fill="#ffffff" d="m759.2711 155.4385l-0.01727295 94.79588l-427.05206 100.14052l-42.09601 -84.920654z" fill-rule="evenodd"/><path fill="#ffffff" d="m421.49164 234.64502l21.039368 89.85828l-131.40158 30.803131l-21.039368 -89.85828z" fill-rule="evenodd"/></g></svg>
|
After Width: | Height: | Size: 1.4 KiB |
@ -1,2 +0,0 @@
|
|||||||
-- This file should undo anything in `up.sql`
|
|
||||||
DROP TABLE playlists;
|
|
@ -1,13 +0,0 @@
|
|||||||
-- Your SQL goes here
|
|
||||||
CREATE TABLE playlists (
|
|
||||||
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
|
|
||||||
name VARCHAR NOT NULL,
|
|
||||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE playlist_songs (
|
|
||||||
playlist_id INTEGER REFERENCES playlists(id) ON DELETE CASCADE NOT NULL,
|
|
||||||
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL,
|
|
||||||
position INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY (playlist_id, song_id)
|
|
||||||
);
|
|
@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE song_likes;
|
||||||
|
DROP TABLE song_dislikes;
|
@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE song_likes (
|
||||||
|
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
PRIMARY KEY (song_id, user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE song_dislikes (
|
||||||
|
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
PRIMARY KEY (song_id, user_id)
|
||||||
|
);
|
1
migrations/2024-05-16-220659_add_album_images/down.sql
Normal file
1
migrations/2024-05-16-220659_add_album_images/down.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE albums DROP COLUMN image_path;
|
1
migrations/2024-05-16-220659_add_album_images/up.sql
Normal file
1
migrations/2024-05-16-220659_add_album_images/up.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE albums ADD COLUMN image_path VARCHAR;
|
1
migrations/2024-05-18-231505_add_user_admin/down.sql
Normal file
1
migrations/2024-05-18-231505_add_user_admin/down.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE users DROP COLUMN admin;
|
1
migrations/2024-05-18-231505_add_user_admin/up.sql
Normal file
1
migrations/2024-05-18-231505_add_user_admin/up.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN admin BOOLEAN DEFAULT FALSE NOT NULL;
|
@ -1,2 +1 @@
|
|||||||
pub mod playlists;
|
|
||||||
pub mod songs;
|
pub mod songs;
|
@ -1,157 +0,0 @@
|
|||||||
use leptos::*;
|
|
||||||
use crate::models::Playlist;
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
if #[cfg(feature = "ssr")] {
|
|
||||||
use crate::database::get_db_conn;
|
|
||||||
use diesel::prelude::*;
|
|
||||||
use leptos_axum::extract;
|
|
||||||
use axum_login::AuthSession;
|
|
||||||
use crate::auth_backend::AuthBackend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Create a new, empty playlist in the database
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `new_playlist` - The new playlist
|
|
||||||
/// * `conn` - A mutable reference to a database connection
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<(), Box<dyn Error>>` - A empty result if successful, or an error
|
|
||||||
///
|
|
||||||
#[server(endpoint = "playlists/create-playlist")]
|
|
||||||
pub async fn create_playlist(playlist_name: String)->Result<(), ServerFnError> {
|
|
||||||
use crate::schema::playlists::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let auth_session = extract::<AuthSession<AuthBackend>>().await
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
|
|
||||||
|
|
||||||
//Ensure the playlist has no id
|
|
||||||
let new_playlist = Playlist {
|
|
||||||
id: None,
|
|
||||||
name: playlist_name,
|
|
||||||
user_id: auth_session.user.unwrap().id.expect("User has no id"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let db_con = &mut get_db_conn();
|
|
||||||
diesel::insert_into(playlists)
|
|
||||||
.values(&new_playlist)
|
|
||||||
.execute(db_con)
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating playlist: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all playlists for the current user
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<Vec<Playlist>, ServerFnError>` - A vector of playlists if successful, or an error
|
|
||||||
///
|
|
||||||
#[server(endpoint = "playlists/get-playlists")]
|
|
||||||
pub async fn get_playlists() -> Result<Vec<Playlist>, ServerFnError> {
|
|
||||||
use crate::schema::playlists::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let auth_session = extract::<AuthSession<AuthBackend>>().await
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
|
|
||||||
|
|
||||||
let other_user_id = auth_session.user.unwrap().id.expect("User has no id");
|
|
||||||
|
|
||||||
let db_con = &mut get_db_conn();
|
|
||||||
let results = playlists
|
|
||||||
.filter(user_id.eq(other_user_id))
|
|
||||||
.load::<Playlist>(db_con)
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting playlists: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
|
||||||
/// Add a song to a playlist
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `playlist_id` - The id of the playlist
|
|
||||||
/// * `song_id` - The id of the song
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<(), ServerFnError>` - An empty result if successful, or an error
|
|
||||||
///
|
|
||||||
#[server(endpoint = "playlists/add-song")]
|
|
||||||
pub async fn add_song(new_playlist_id: Option<i32>, new_song_id: Option<i32>) -> Result<(), ServerFnError> {
|
|
||||||
use crate::schema::playlist_songs::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let other_playlist_id = new_playlist_id.ok_or(ServerFnError::<NoCustomError>::ServerError("Playlist id must be present (Some) to add song".to_string()))?;
|
|
||||||
|
|
||||||
let other_song_id = new_song_id.ok_or(ServerFnError::<NoCustomError>::ServerError("Song id must be present (Some) to add song".to_string()))?;
|
|
||||||
|
|
||||||
let db_con = &mut get_db_conn();
|
|
||||||
diesel::insert_into(playlist_songs)
|
|
||||||
.values((playlist_id.eq(other_playlist_id), song_id.eq(other_song_id)))
|
|
||||||
.execute(db_con)
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding song to playlist: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
/// Get songs from a playlist
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `playlist_id` - The id of the playlist
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<Vec<Song>, ServerFnError>` - A vector of songs if successful, or an error
|
|
||||||
///
|
|
||||||
#[server(endpoint = "playlists/get-songs")]
|
|
||||||
pub async fn get_songs(new_playlist_id: Option<i32>) -> Result<Vec<crate::models::Song>, ServerFnError> {
|
|
||||||
use crate::schema::playlist_songs::dsl::*;
|
|
||||||
use crate::schema::songs::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let other_playlist_id = new_playlist_id.ok_or(ServerFnError::<NoCustomError>::ServerError("Playlist id must be present (Some) to get songs".to_string()))?;
|
|
||||||
|
|
||||||
let db_con = &mut get_db_conn();
|
|
||||||
let results = playlist_songs
|
|
||||||
.inner_join(songs)
|
|
||||||
.filter(playlist_id.eq(other_playlist_id))
|
|
||||||
.select(songs::all_columns())
|
|
||||||
.order_by(position)
|
|
||||||
.load(db_con)
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting songs from playlist: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
|
||||||
/// Remove a song from a playlist
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `playlist_id` - The id of the playlist
|
|
||||||
/// * `song_id` - The id of the song
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<(), ServerFnError>` - An empty result if successful, or an error
|
|
||||||
///
|
|
||||||
#[server(endpoint = "playlists/remove-song")]
|
|
||||||
pub async fn remove_song(new_playlist_id: Option<i32>, new_song_id: Option<i32>) -> Result<(), ServerFnError> {
|
|
||||||
use crate::schema::playlist_songs::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let other_playlist_id = new_playlist_id.ok_or(ServerFnError::<NoCustomError>::ServerError("Playlist id must be present (Some) to remove song".to_string()))?;
|
|
||||||
|
|
||||||
let other_song_id = new_song_id.ok_or(ServerFnError::<NoCustomError>::ServerError("Song id must be present (Some) to remove song".to_string()))?;
|
|
||||||
|
|
||||||
let db_con = &mut get_db_conn();
|
|
||||||
diesel::delete(playlist_songs.filter(playlist_id.eq(other_playlist_id).and(song_id.eq(other_song_id))))
|
|
||||||
.execute(db_con)
|
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error removing song from playlist: {}", e)))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@ -1,37 +1,55 @@
|
|||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::models::Artist;
|
|
||||||
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "ssr")] {
|
if #[cfg(feature = "ssr")] {
|
||||||
use crate::database::get_db_conn;
|
use leptos::server_fn::error::NoCustomError;
|
||||||
use diesel::prelude::*;
|
use crate::database::get_db_conn;
|
||||||
}
|
use crate::auth::get_user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a Vector of Artists associated with a Song
|
/// Like or unlike a song
|
||||||
///
|
#[server(endpoint = "songs/set_like")]
|
||||||
/// # Arguments
|
pub async fn set_like_song(song_id: i32, like: bool) -> Result<(), ServerFnError> {
|
||||||
/// `song_id_arg` - The id of the Song to get the Artists for
|
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
///
|
ServerError(format!("Error getting user: {}", e)))?;
|
||||||
/// # Returns
|
|
||||||
/// A Result containing a Vector of Artists if the operation was successful, or an error if the operation failed
|
|
||||||
#[server(endpoint = "songs/get-artists")]
|
|
||||||
pub async fn get_artists(song_id_arg: Option<i32>) -> Result<Vec<Artist>, ServerFnError> {
|
|
||||||
use crate::schema::artists::dsl::*;
|
|
||||||
use crate::schema::song_artists::dsl::*;
|
|
||||||
use leptos::server_fn::error::NoCustomError;
|
|
||||||
|
|
||||||
let other_song_id = song_id_arg.ok_or(ServerFnError::<NoCustomError>::ServerError("Song id must be present (Some) to get artists".to_string()))?;
|
let db_con = &mut get_db_conn();
|
||||||
|
|
||||||
let my_artists = artists
|
user.set_like_song(song_id, like, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
.inner_join(song_artists)
|
ServerError(format!("Error liking song: {}", e)))
|
||||||
.filter(song_id.eq(other_song_id))
|
|
||||||
.select(artists::all_columns())
|
|
||||||
.load(&mut get_db_conn())?;
|
|
||||||
|
|
||||||
Ok(my_artists)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dislike or remove dislike from a song
|
||||||
|
#[server(endpoint = "songs/set_dislike")]
|
||||||
|
pub async fn set_dislike_song(song_id: i32, dislike: bool) -> Result<(), ServerFnError> {
|
||||||
|
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error getting user: {}", e)))?;
|
||||||
|
|
||||||
|
let db_con = &mut get_db_conn();
|
||||||
|
|
||||||
|
user.set_dislike_song(song_id, dislike, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error disliking song: {}", e)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the like and dislike status of a song
|
||||||
|
#[server(endpoint = "songs/get_like_dislike")]
|
||||||
|
pub async fn get_like_dislike_song(song_id: i32) -> Result<(bool, bool), ServerFnError> {
|
||||||
|
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error getting user: {}", e)))?;
|
||||||
|
|
||||||
|
let db_con = &mut get_db_conn();
|
||||||
|
|
||||||
|
// TODO this could probably be done more efficiently with a tokio::try_join, but
|
||||||
|
// doing so is much more complicated than it would initially seem
|
||||||
|
|
||||||
|
let like = user.get_like_song(song_id, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error getting song liked: {}", e)))?;
|
||||||
|
let dislike = user.get_dislike_song(song_id, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error getting song disliked: {}", e)))?;
|
||||||
|
|
||||||
|
Ok((like, dislike))
|
||||||
|
}
|
||||||
|
67
src/app.rs
67
src/app.rs
@ -1,19 +1,24 @@
|
|||||||
use crate::error_template::{AppError, ErrorTemplate};
|
|
||||||
use crate::pages::login::*;
|
|
||||||
use crate::pages::signup::*;
|
|
||||||
use crate::playbar::PlayBar;
|
use crate::playbar::PlayBar;
|
||||||
use crate::playstatus::PlayStatus;
|
use crate::playstatus::PlayStatus;
|
||||||
use crate::queue::Queue;
|
use crate::queue::Queue;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use leptos_router::*;
|
use leptos_router::*;
|
||||||
use leptos::leptos_dom::*;
|
use crate::pages::login::*;
|
||||||
|
use crate::pages::signup::*;
|
||||||
|
use crate::pages::audiotest::*;
|
||||||
|
use crate::error_template::{AppError, ErrorTemplate};
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||||
provide_meta_context();
|
provide_meta_context();
|
||||||
|
|
||||||
|
let play_status = PlayStatus::default();
|
||||||
|
let play_status = create_rw_signal(play_status);
|
||||||
|
let upload_open = create_rw_signal(false);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
// injects a stylesheet into the document <head>
|
// injects a stylesheet into the document <head>
|
||||||
// id=leptos means cargo-leptos will hot-reload this stylesheet
|
// id=leptos means cargo-leptos will hot-reload this stylesheet
|
||||||
@ -33,58 +38,36 @@ pub fn App() -> impl IntoView {
|
|||||||
}>
|
}>
|
||||||
<main>
|
<main>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="" view=HomePage/>
|
<Route path="" view=move || view! { <HomePage play_status=play_status upload_open=upload_open/> }>
|
||||||
|
<Route path="" view=Dashboard />
|
||||||
|
<Route path="dashboard" view=Dashboard />
|
||||||
|
<Route path="search" view=Search />
|
||||||
|
</Route>
|
||||||
<Route path="/login" view=Login />
|
<Route path="/login" view=Login />
|
||||||
<Route path="/signup" view=Signup />
|
<Route path="/signup" view=Signup />
|
||||||
|
<Route path="/audiotest" view=AudioTest />
|
||||||
</Routes>
|
</Routes>
|
||||||
</main>
|
</main>
|
||||||
</Router>
|
</Router>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::components::dashboard::*;
|
|
||||||
use crate::components::personal::*;
|
|
||||||
use crate::components::search::*;
|
|
||||||
use crate::components::sidebar::*;
|
use crate::components::sidebar::*;
|
||||||
|
use crate::components::dashboard::*;
|
||||||
|
use crate::components::search::*;
|
||||||
|
use crate::components::personal::*;
|
||||||
|
use crate::components::upload::*;
|
||||||
|
|
||||||
/// Renders the home page of your application.
|
/// Renders the home page of your application.
|
||||||
#[component]
|
#[component]
|
||||||
fn HomePage() -> impl IntoView {
|
fn HomePage(play_status: RwSignal<PlayStatus>, upload_open: RwSignal<bool>) -> impl IntoView {
|
||||||
use crate::auth::check_auth;
|
|
||||||
|
|
||||||
let play_status = PlayStatus::default();
|
|
||||||
let play_status = create_rw_signal(play_status);
|
|
||||||
|
|
||||||
let (logged_in, set_logged_in) = create_signal(false);
|
|
||||||
|
|
||||||
let (dashboard_open, set_dashboard_open) = create_signal(true);
|
|
||||||
|
|
||||||
create_effect(move |_| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let auth_result = check_auth().await;
|
|
||||||
if let Err(err) = auth_result {
|
|
||||||
log!("Error checking auth: {:?}", err);
|
|
||||||
} else if let Ok(true) = auth_result {
|
|
||||||
log!("User is logged in");
|
|
||||||
set_logged_in.update(|value| *value = true);
|
|
||||||
} else if let Ok(false) = auth_result {
|
|
||||||
log!("User is not logged in");
|
|
||||||
set_logged_in.update(|value| *value = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div class="home-container">
|
<div class="home-container">
|
||||||
<Sidebar setter=set_dashboard_open active=dashboard_open logged_in=logged_in/>
|
<Upload open=upload_open/>
|
||||||
<Show
|
<Sidebar upload_open=upload_open/>
|
||||||
when=move || {dashboard_open() == true}
|
// This <Outlet /> will render the child route components
|
||||||
fallback=move || view! { <Search /> }
|
<Outlet />
|
||||||
>
|
<Personal />
|
||||||
<Dashboard />
|
|
||||||
</Show>
|
|
||||||
<Personal logged_in=logged_in/>
|
|
||||||
<PlayBar status=play_status/>
|
<PlayBar status=play_status/>
|
||||||
<Queue status=play_status/>
|
<Queue status=play_status/>
|
||||||
</div>
|
</div>
|
||||||
|
0
src/audioplayer.rs
Normal file
0
src/audioplayer.rs
Normal file
60
src/auth.rs
60
src/auth.rs
@ -21,9 +21,10 @@ use crate::users::UserCredentials;
|
|||||||
pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
|
pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
|
||||||
use crate::users::create_user;
|
use crate::users::create_user;
|
||||||
|
|
||||||
// Ensure the user has no id
|
// Ensure the user has no id, and is not a self-proclaimed admin
|
||||||
let new_user = User {
|
let new_user = User {
|
||||||
id: None,
|
id: None,
|
||||||
|
admin: false,
|
||||||
..new_user
|
..new_user
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,3 +121,60 @@ pub async fn require_auth() -> Result<(), ServerFnError> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current logged-in user
|
||||||
|
/// Returns a Result with the user if they are logged in
|
||||||
|
/// Returns an error if the user is not logged in, or if there is an error getting the user
|
||||||
|
/// Intended to be used in a route to get the current user:
|
||||||
|
/// ```rust
|
||||||
|
/// use leptos::*;
|
||||||
|
/// use libretunes::auth::get_user;
|
||||||
|
/// #[server(endpoint = "user_route")]
|
||||||
|
/// pub async fn user_route() -> Result<(), ServerFnError> {
|
||||||
|
/// let user = get_user().await?;
|
||||||
|
/// println!("Logged in as: {}", user.username);
|
||||||
|
/// // Do something with the user
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn get_user() -> Result<User, ServerFnError> {
|
||||||
|
let auth_session = extract::<AuthSession<AuthBackend>>().await
|
||||||
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
|
||||||
|
|
||||||
|
auth_session.user.ok_or(ServerFnError::<NoCustomError>::ServerError("User not logged in".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a user is an admin
|
||||||
|
/// Returns a Result with a boolean indicating if the user is logged in and an admin
|
||||||
|
#[server(endpoint = "check_admin")]
|
||||||
|
pub async fn check_admin() -> Result<bool, ServerFnError> {
|
||||||
|
let auth_session = extract::<AuthSession<AuthBackend>>().await
|
||||||
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
|
||||||
|
|
||||||
|
Ok(auth_session.user.as_ref().map(|u| u.admin).unwrap_or(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Require that a user is logged in and an admin
|
||||||
|
/// Returns a Result with the error message if the user is not logged in or is not an admin
|
||||||
|
/// Intended to be used at the start of a protected route, to ensure the user is logged in and an admin:
|
||||||
|
/// ```rust
|
||||||
|
/// use leptos::*;
|
||||||
|
/// use libretunes::auth::require_admin;
|
||||||
|
/// #[server(endpoint = "protected_admin_route")]
|
||||||
|
/// pub async fn protected_admin_route() -> Result<(), ServerFnError> {
|
||||||
|
/// require_admin().await?;
|
||||||
|
/// // Continue with protected route
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn require_admin() -> Result<(), ServerFnError> {
|
||||||
|
check_admin().await.and_then(|is_admin| {
|
||||||
|
if is_admin {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ServerFnError::<NoCustomError>::ServerError(format!("Unauthorized")))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
use async_trait::async_trait;
|
|
||||||
use axum_login::{AuthnBackend, AuthUser, UserId};
|
use axum_login::{AuthnBackend, AuthUser, UserId};
|
||||||
use crate::users::UserCredentials;
|
use crate::users::UserCredentials;
|
||||||
use leptos::server_fn::error::ServerFnErrorErr;
|
use leptos::server_fn::error::ServerFnErrorErr;
|
||||||
|
|
||||||
use crate::models::User;
|
use crate::models::User;
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "ssr")] {
|
||||||
|
use async_trait::async_trait;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AuthUser for User {
|
impl AuthUser for User {
|
||||||
type Id = i32;
|
type Id = i32;
|
||||||
|
|
||||||
|
@ -2,6 +2,4 @@ pub mod sidebar;
|
|||||||
pub mod dashboard;
|
pub mod dashboard;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod personal;
|
pub mod personal;
|
||||||
pub mod playlist;
|
pub mod upload;
|
||||||
pub mod create_playlist;
|
|
||||||
pub mod playlists;
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
use leptos::*;
|
|
||||||
use leptos_icons::*;
|
|
||||||
use leptos::leptos_dom::*;
|
|
||||||
use crate::api::playlists::create_playlist;
|
|
||||||
use crate::api::playlists::get_playlists;
|
|
||||||
use crate::models::Playlist;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn CreatePlayList(closer: WriteSignal<bool>, set_playlists: WriteSignal<Vec<Playlist>>) -> impl IntoView {
|
|
||||||
|
|
||||||
let (playlist_name, set_playlist_name) = create_signal("".to_string());
|
|
||||||
|
|
||||||
let on_submit = move |ev: leptos::ev::SubmitEvent| {
|
|
||||||
ev.prevent_default();
|
|
||||||
let new_playlist_name = playlist_name.get();
|
|
||||||
spawn_local(async move {
|
|
||||||
let create_result = create_playlist(new_playlist_name).await;
|
|
||||||
if let Err(err) = create_result {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error creating playlist: {:?}", err);
|
|
||||||
} else {
|
|
||||||
log!("Playlist created successfully!");
|
|
||||||
closer.update(|value| *value = false);
|
|
||||||
}
|
|
||||||
let playlists = get_playlists().await;
|
|
||||||
if let Err(err) = playlists {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error getting playlists: {:?}", err);
|
|
||||||
} else {
|
|
||||||
set_playlists.update(|value| *value = playlists.unwrap());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<div class="create-playlist-popup-container">
|
|
||||||
<div class="close-button" on:click=move |_| closer.update(|value| *value = false)>
|
|
||||||
<Icon icon=icondata::IoCloseSharp />
|
|
||||||
</div>
|
|
||||||
<h1 class="header">Create Playlist</h1>
|
|
||||||
<form class="create-playlist-form" action="POST" on:submit=on_submit>
|
|
||||||
<input class="name-input" type="text" placeholder="Playlist Name"
|
|
||||||
on:input=move |ev| {
|
|
||||||
set_playlist_name(event_target_value(&ev));
|
|
||||||
log!("playlist name changed to: {}", playlist_name.get());
|
|
||||||
}
|
|
||||||
prop:value=playlist_name
|
|
||||||
/>
|
|
||||||
<button class="create-button" type="submit">Create</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,17 +3,16 @@ use leptos::*;
|
|||||||
use leptos_icons::*;
|
use leptos_icons::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Personal(logged_in: ReadSignal<bool>) -> impl IntoView {
|
pub fn Personal() -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
<div class=" personal-container">
|
<div class=" personal-container">
|
||||||
<Profile logged_in=logged_in/>
|
<Profile />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Profile(logged_in: ReadSignal<bool>) -> impl IntoView {
|
pub fn Profile() -> impl IntoView {
|
||||||
|
|
||||||
let (dropdown_open, set_dropdown_open) = create_signal(false);
|
let (dropdown_open, set_dropdown_open) = create_signal(false);
|
||||||
|
|
||||||
let open_dropdown = move |_| {
|
let open_dropdown = move |_| {
|
||||||
@ -26,13 +25,7 @@ pub fn Profile(logged_in: ReadSignal<bool>) -> impl IntoView {
|
|||||||
<Icon icon=icondata::CgProfile />
|
<Icon icon=icondata::CgProfile />
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-container" style={move || if dropdown_open() {"display: flex"} else {"display: none"}}>
|
<div class="dropdown-container" style={move || if dropdown_open() {"display: flex"} else {"display: none"}}>
|
||||||
<Show
|
<DropDownNotLoggedIn />
|
||||||
when=move || {logged_in() == true}
|
|
||||||
fallback=move || view!{<DropDownNotLoggedIn />}
|
|
||||||
>
|
|
||||||
<DropDownLoggedIn/>
|
|
||||||
</Show>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@ -47,26 +40,3 @@ pub fn DropDownNotLoggedIn() -> impl IntoView {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[component]
|
|
||||||
pub fn DropDownLoggedIn() -> impl IntoView {
|
|
||||||
use crate::auth::logout;
|
|
||||||
|
|
||||||
let logout = move |_ev: leptos::ev::MouseEvent| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let _logout_result = logout().await;
|
|
||||||
if let Err(err) = _logout_result {
|
|
||||||
log!("Error logging out: {:?}", err);
|
|
||||||
} else {
|
|
||||||
log!("Logged out Successfully!");
|
|
||||||
leptos_router::use_navigate()("/login", Default::default());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
view! {
|
|
||||||
<div class="dropdown-logged-in">
|
|
||||||
<h1>Logged in!</h1>
|
|
||||||
<button on:click=logout class="auth-button">Log Out</button>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,162 +0,0 @@
|
|||||||
use leptos::*;
|
|
||||||
use leptos_icons::*;
|
|
||||||
use leptos::leptos_dom::*;
|
|
||||||
use crate::models::Playlist;
|
|
||||||
use crate::models::Song;
|
|
||||||
use crate::api::playlists::get_songs;
|
|
||||||
use crate::api::songs::get_artists;
|
|
||||||
use crate::api::playlists::remove_song;
|
|
||||||
|
|
||||||
fn total_duration(songs: ReadSignal<Vec<Song>>) -> i32 {
|
|
||||||
let mut total_duration = 0;
|
|
||||||
for song in songs.get() {
|
|
||||||
total_duration += song.duration;
|
|
||||||
}
|
|
||||||
total_duration
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_seconds(seconds: i32) -> String {
|
|
||||||
let minutes = seconds / 60;
|
|
||||||
let seconds = seconds % 60;
|
|
||||||
let seconds_string = if seconds < 10 {
|
|
||||||
format!("0{}", seconds)
|
|
||||||
} else {
|
|
||||||
format!("{}", seconds)
|
|
||||||
};
|
|
||||||
format!("{}:{}", minutes, seconds_string)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_to_text_time(seconds: i32) -> String {
|
|
||||||
let hours = seconds / 3600;
|
|
||||||
let minutes = (seconds % 3600) / 60;
|
|
||||||
format!("{} hour{}, {} minute{}", hours, if hours > 1 { "s" } else { "" }, minutes, if minutes > 1 { "s" } else { "" })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Playlist(playlist: Playlist) -> impl IntoView {
|
|
||||||
let (show_playlist, set_show_playlist) = create_signal(false);
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<div class="playlist" on:click=move|_| set_show_playlist.update(|value| *value=true) >
|
|
||||||
<h1 class="name">{playlist.name.clone()}</h1>
|
|
||||||
|
|
||||||
<Show
|
|
||||||
when=move || show_playlist()
|
|
||||||
fallback=move || view! {<div></div>}
|
|
||||||
>
|
|
||||||
<div class="screen-darkener"></div>
|
|
||||||
</Show>
|
|
||||||
|
|
||||||
<Show
|
|
||||||
when=move || show_playlist()
|
|
||||||
fallback=move || view! {<div></div>}
|
|
||||||
>
|
|
||||||
<PlayListPopUp playlist=playlist.clone() set_show_playlist=set_show_playlist />
|
|
||||||
</Show>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[component]
|
|
||||||
pub fn PlayListPopUp(playlist: Playlist, set_show_playlist: WriteSignal<bool>) -> impl IntoView {
|
|
||||||
let (songs, set_songs) = create_signal(vec![]);
|
|
||||||
|
|
||||||
create_effect(move |_| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let playlist_songs = get_songs(playlist.id.clone()).await;
|
|
||||||
if let Err(err) = playlist_songs {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error getting songs: {:?}", err);
|
|
||||||
} else {
|
|
||||||
log!("Songs: {:?}", playlist_songs);
|
|
||||||
log!("number of songs: {:?}", playlist_songs.clone().expect("REASON").len());
|
|
||||||
set_songs.update(|value| *value = playlist_songs.unwrap());
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<div class="playlist-container">
|
|
||||||
<div class="close-button" on:click=move |_| set_show_playlist.update(|value| *value = false)>
|
|
||||||
<Icon icon=icondata::IoCloseSharp />
|
|
||||||
</div>
|
|
||||||
<div class="info">
|
|
||||||
<h1>{playlist.name.clone()}</h1>
|
|
||||||
<p>{move || songs.get().len()} songs {move || convert_to_text_time(total_duration(songs))}</p>
|
|
||||||
</div>
|
|
||||||
<div class="options">
|
|
||||||
<button><Icon class="button-icons" icon=icondata::BsPlayFill />Play</button>
|
|
||||||
<button><Icon class="button-icons" icon=icondata::IoShuffle />Shuffle</button>
|
|
||||||
</div>
|
|
||||||
<ul class="songs">
|
|
||||||
{
|
|
||||||
move || songs.get().iter().enumerate().map(|(_index,song)| view! {
|
|
||||||
<PlaylistSong song=song.clone() playlist_id=playlist.id.clone() set_songs=set_songs />
|
|
||||||
}).collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[component]
|
|
||||||
pub fn PlaylistSong(song: Song, playlist_id: Option<i32>, set_songs: WriteSignal<Vec<Song>>) -> impl IntoView {
|
|
||||||
let (artists, set_artists) = create_signal("".to_string());
|
|
||||||
let (is_hovered, set_is_hovered) = create_signal(false);
|
|
||||||
|
|
||||||
let delete_song = move |_| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let delete_result = remove_song(playlist_id,song.id.clone()).await;
|
|
||||||
if let Err(err) = delete_result {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error deleting song: {:?}", err);
|
|
||||||
} else {
|
|
||||||
log!("Song deleted successfully!");
|
|
||||||
set_songs.update(|value| *value = value.iter().filter(|s| s.id != song.id).cloned().collect());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
create_effect(move |_| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let song_artists = get_artists(song.id.clone()).await;
|
|
||||||
if let Err(err) = song_artists {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error getting artist: {:?}", err);
|
|
||||||
} else {
|
|
||||||
log!("Artist: {:?}", song_artists);
|
|
||||||
let mut artist_string = "".to_string();
|
|
||||||
let song_artists = song_artists.unwrap();
|
|
||||||
for i in 0..song_artists.len() {
|
|
||||||
if i == song_artists.len() - 1 {
|
|
||||||
artist_string.push_str(&song_artists[i].name);
|
|
||||||
} else {
|
|
||||||
artist_string.push_str(&song_artists[i].name);
|
|
||||||
artist_string.push_str(" & ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set_artists.update(|value| *value = artist_string);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<div class="song" on:mouseenter=move |_| set_is_hovered.update(|value| *value=true) on:mouseleave=move |_| set_is_hovered.update(|value| *value=false)>
|
|
||||||
<img src={song.image_path.clone()} alt={song.title.clone()} />
|
|
||||||
<div class="song-info">
|
|
||||||
<h3>{song.title.clone()}</h3>
|
|
||||||
<p>{move || artists.get()}</p>
|
|
||||||
</div>
|
|
||||||
<div class="right">
|
|
||||||
<Show
|
|
||||||
when=move || is_hovered()
|
|
||||||
fallback=move || view! {<p class="duration">{convert_seconds(song.duration)}</p>}
|
|
||||||
>
|
|
||||||
<div class="delete-song" on:click=delete_song>
|
|
||||||
<Icon icon=icondata::FaTrashCanRegular />
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
use leptos::*;
|
|
||||||
use leptos::leptos_dom::*;
|
|
||||||
use leptos_icons::*;
|
|
||||||
use crate::components::create_playlist::CreatePlayList;
|
|
||||||
use crate::components::playlist::Playlist;
|
|
||||||
use crate::api::playlists::get_playlists;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Playlists() -> impl IntoView {
|
|
||||||
let (create_playlist_open, set_create_playlist_open) = create_signal(false);
|
|
||||||
let (playlists, set_playlists) = create_signal(vec![]);
|
|
||||||
|
|
||||||
create_effect(move |_| {
|
|
||||||
spawn_local(async move {
|
|
||||||
let playlists2 = get_playlists().await;
|
|
||||||
if let Err(err) = playlists2 {
|
|
||||||
// Handle the error here, e.g., log it or display to the user
|
|
||||||
log!("Error getting playlists: {:?}", err);
|
|
||||||
} else {
|
|
||||||
set_playlists.update(|value| *value = playlists2.unwrap());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<div class="sidebar-playlists-container">
|
|
||||||
<div class="heading">
|
|
||||||
<h1 class="header">Playlists</h1>
|
|
||||||
<button on:click=move|_| set_create_playlist_open.update(|value|*value = true) class="add-playlist">
|
|
||||||
<div class="add-sign">
|
|
||||||
<Icon icon=icondata::IoAddSharp />
|
|
||||||
</div>
|
|
||||||
New Playlist
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<Show
|
|
||||||
when=move || create_playlist_open()
|
|
||||||
fallback=move || view! {<div></div>}
|
|
||||||
>
|
|
||||||
<CreatePlayList closer=set_create_playlist_open set_playlists=set_playlists/>
|
|
||||||
</Show>
|
|
||||||
|
|
||||||
<ul class="playlists">
|
|
||||||
{
|
|
||||||
move || playlists.get().iter().enumerate().map(|(_index,playlist)| view! {
|
|
||||||
<Playlist playlist=playlist.clone() />
|
|
||||||
}).collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,42 +1,54 @@
|
|||||||
use leptos::leptos_dom::*;
|
use leptos::leptos_dom::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_icons::*;
|
use leptos_icons::*;
|
||||||
use crate::components::playlists::Playlists;
|
use crate::components::upload::*;
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Sidebar(setter: WriteSignal<bool>, active: ReadSignal<bool>, logged_in:ReadSignal<bool>) -> impl IntoView {
|
pub fn Sidebar(upload_open: RwSignal<bool>) -> impl IntoView {
|
||||||
let open_dashboard = move |_| {
|
use leptos_router::use_location;
|
||||||
setter.update(|value| *value = true);
|
let location = use_location();
|
||||||
log!("open dashboard");
|
|
||||||
};
|
let on_dashboard = Signal::derive(
|
||||||
let open_search = move |_| {
|
move || location.pathname.get().starts_with("/dashboard") || location.pathname.get() == "/",
|
||||||
setter.update(|value| *value = false);
|
);
|
||||||
log!("open search");
|
|
||||||
};
|
let on_search = Signal::derive(
|
||||||
|
move || location.pathname.get().starts_with("/search"),
|
||||||
|
);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div class="sidebar-container">
|
<div class="sidebar-container">
|
||||||
<div class="sidebar-top-container">
|
<div class="sidebar-top-container">
|
||||||
<h2 class="header">LibreTunes</h2>
|
<h2 class="header">LibreTunes</h2>
|
||||||
<div class="buttons" on:click=open_dashboard style={move || if active() {"color: #e1e3e1"} else {""}} >
|
<UploadBtn dialog_open=upload_open />
|
||||||
|
<a class="buttons" href="/dashboard" style={move || if on_dashboard() {"color: #e1e3e1"} else {""}} >
|
||||||
<Icon icon=icondata::OcHomeFillLg />
|
<Icon icon=icondata::OcHomeFillLg />
|
||||||
<h1>Dashboard</h1>
|
<h1>Dashboard</h1>
|
||||||
</div>
|
</a>
|
||||||
<div class="buttons" on:click=open_search style={move || if !active() {"color: #e1e3e1"} else {""}}>
|
<a class="buttons" href="/search" style={move || if on_search() {"color: #e1e3e1"} else {""}}>
|
||||||
<Icon icon=icondata::BiSearchRegular />
|
<Icon icon=icondata::BiSearchRegular />
|
||||||
<h1>Search</h1>
|
<h1>Search</h1>
|
||||||
</div>
|
</a>
|
||||||
</div>
|
|
||||||
<div class="sidebar-bottom-container">
|
|
||||||
<Show
|
|
||||||
when=move || {logged_in() == true}
|
|
||||||
fallback=move|| view!{<h1>LOG IN PLEASE</h1>}
|
|
||||||
>
|
|
||||||
<Playlists />
|
|
||||||
</Show>
|
|
||||||
</div>
|
</div>
|
||||||
|
<Bottom />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Bottom() -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<div class="sidebar-bottom-container">
|
||||||
|
<div class="heading">
|
||||||
|
<h1 class="header">Playlists</h1>
|
||||||
|
<button class="add-playlist">
|
||||||
|
<div class="add-sign">
|
||||||
|
<Icon icon=icondata::IoAddSharp />
|
||||||
|
</div>
|
||||||
|
New Playlist
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
245
src/components/upload.rs
Normal file
245
src/components/upload.rs
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
use std::rc::Rc;
|
||||||
|
use leptos::leptos_dom::*;
|
||||||
|
use leptos::*;
|
||||||
|
use leptos_icons::*;
|
||||||
|
use leptos_router::Form;
|
||||||
|
use web_sys::Response;
|
||||||
|
use crate::search::search_artists;
|
||||||
|
use crate::search::search_albums;
|
||||||
|
use crate::models::Artist;
|
||||||
|
use crate::models::Album;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn UploadBtn(dialog_open: RwSignal<bool>) -> impl IntoView {
|
||||||
|
let open_dialog = move |_| {
|
||||||
|
dialog_open.set(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<button class="upload-btn" on:click=open_dialog>
|
||||||
|
<div class="add-sign">
|
||||||
|
<Icon icon=icondata::IoAddSharp />
|
||||||
|
</div>
|
||||||
|
Upload
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Upload(open: RwSignal<bool>) -> impl IntoView {
|
||||||
|
// Create signals for the artist input and the filtered artists
|
||||||
|
let (artists, set_artists) = create_signal("".to_string());
|
||||||
|
let (filtered_artists, set_filtered_artists) = create_signal(vec![]);
|
||||||
|
|
||||||
|
let (albums, set_albums) = create_signal("".to_string());
|
||||||
|
let (filtered_albums, set_filtered_albums) = create_signal(vec![]);
|
||||||
|
|
||||||
|
let (error_msg, set_error_msg) = create_signal::<Option<String>>(None);
|
||||||
|
|
||||||
|
let close_dialog = move |ev: leptos::ev::MouseEvent| {
|
||||||
|
ev.prevent_default();
|
||||||
|
open.set(false);
|
||||||
|
};
|
||||||
|
// Create a filter function to handle filtering artists
|
||||||
|
// Allow users to search for artists by name, converts the artist name to artist id to be handed off to backend
|
||||||
|
let handle_filter_artists = move |ev: leptos::ev::Event| {
|
||||||
|
ev.prevent_default();
|
||||||
|
|
||||||
|
let artist_input: String = event_target_value(&ev);
|
||||||
|
|
||||||
|
//Get the artist that we are currently searching for
|
||||||
|
let mut all_artists: Vec<&str> = artist_input.split(",").collect();
|
||||||
|
let search = all_artists.pop().unwrap().to_string();
|
||||||
|
|
||||||
|
//Update the artist signal with the input
|
||||||
|
set_artists.update(|value: &mut String| *value = artist_input);
|
||||||
|
|
||||||
|
spawn_local(async move {
|
||||||
|
let filter_results = search_artists(search, 3).await;
|
||||||
|
if let Err(err) = filter_results {
|
||||||
|
log!("Error filtering artists: {:?}", err);
|
||||||
|
} else if let Ok(artists) = filter_results {
|
||||||
|
log!("Filtered artists: {:?}", artists);
|
||||||
|
|
||||||
|
set_filtered_artists.update(|value| *value = artists);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
// Create a filter function to handle filtering albums
|
||||||
|
// Allow users to search for albums by title, converts the album title to album id to be handed off to backend
|
||||||
|
let handle_filter_albums = move |ev: leptos::ev::Event| {
|
||||||
|
ev.prevent_default();
|
||||||
|
|
||||||
|
let album_input: String = event_target_value(&ev);
|
||||||
|
|
||||||
|
//Update the album signal with the input
|
||||||
|
set_albums.update(|value: &mut String| *value = album_input);
|
||||||
|
|
||||||
|
spawn_local(async move {
|
||||||
|
let filter_results = search_albums(albums.get_untracked(), 3).await;
|
||||||
|
if let Err(err) = filter_results {
|
||||||
|
log!("Error filtering albums: {:?}", err);
|
||||||
|
} else if let Ok(albums) = filter_results {
|
||||||
|
log!("Filtered albums: {:?}", albums);
|
||||||
|
set_filtered_albums.update(|value| *value = albums);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
let handle_response = Rc::new(move |response: &Response| {
|
||||||
|
if response.ok() {
|
||||||
|
set_error_msg.update(|value| *value = None);
|
||||||
|
set_filtered_artists.update(|value| *value = vec![]);
|
||||||
|
set_filtered_albums.update(|value| *value = vec![]);
|
||||||
|
set_artists.update(|value| *value = "".to_string());
|
||||||
|
set_albums.update(|value| *value = "".to_string());
|
||||||
|
open.set(false);
|
||||||
|
} else {
|
||||||
|
// TODO: Extract error message from response
|
||||||
|
set_error_msg.update(|value| *value = Some("Error uploading song".to_string()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<Show when=open fallback=move || view! {}>
|
||||||
|
<div class="upload-container" open=open>
|
||||||
|
<div class="close-button" on:click=close_dialog><Icon icon=icondata::IoClose /></div>
|
||||||
|
<div class="upload-header">
|
||||||
|
<h1>Upload Song</h1>
|
||||||
|
</div>
|
||||||
|
<Form action="/api/upload" method="POST" enctype=String::from("multipart/form-data")
|
||||||
|
class="upload-form" on_response=handle_response.clone()>
|
||||||
|
<div class="input-bx">
|
||||||
|
<input type="text" name="title" required class="text-input" required/>
|
||||||
|
<span>Title</span>
|
||||||
|
</div>
|
||||||
|
<div class="artists has-search">
|
||||||
|
<div class="input-bx">
|
||||||
|
<input type="text" name="artist_ids" class="text-input" prop:value=artists on:input=handle_filter_artists/>
|
||||||
|
<span>Artists</span>
|
||||||
|
</div>
|
||||||
|
<Show
|
||||||
|
when=move || {filtered_artists.get().len() > 0}
|
||||||
|
fallback=move || view! {}
|
||||||
|
>
|
||||||
|
<ul class="artist_results search-results">
|
||||||
|
{
|
||||||
|
move || filtered_artists.get().iter().enumerate().map(|(_index,filtered_artist)| view! {
|
||||||
|
<Artist artist=filtered_artist.clone() artists=artists set_artists=set_artists set_filtered=set_filtered_artists/>
|
||||||
|
}).collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
<div class="albums has-search">
|
||||||
|
<div class="input-bx">
|
||||||
|
<input type="text" name="album_id" class="text-input" prop:value=albums on:input=handle_filter_albums/>
|
||||||
|
<span>Album ID</span>
|
||||||
|
</div>
|
||||||
|
<Show
|
||||||
|
when=move || {filtered_albums.get().len() > 0}
|
||||||
|
fallback=move || view! {}
|
||||||
|
>
|
||||||
|
<ul class="album_results search-results">
|
||||||
|
{
|
||||||
|
move || filtered_albums.get().iter().enumerate().map(|(_index,filtered_album)| view! {
|
||||||
|
<Album album=filtered_album.clone() _albums=albums set_albums=set_albums set_filtered=set_filtered_albums/>
|
||||||
|
}).collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-bx">
|
||||||
|
<input type="number" name="track_number" class="text-input"/>
|
||||||
|
<span>Track Number</span>
|
||||||
|
</div>
|
||||||
|
<div class="release-date">
|
||||||
|
<div class="left">
|
||||||
|
<span>Release</span>
|
||||||
|
<span>Date</span>
|
||||||
|
</div>
|
||||||
|
<input class="info" type="date" name="release_date"/>
|
||||||
|
</div>
|
||||||
|
<div class="file">
|
||||||
|
<span>File</span>
|
||||||
|
<input class="info" type="file" accept=".mp3" name="file" required/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="upload-button">Upload</button>
|
||||||
|
</Form>
|
||||||
|
<Show
|
||||||
|
when=move || {error_msg.get().is_some()}
|
||||||
|
fallback=move || view! {}
|
||||||
|
>
|
||||||
|
<div class="error-msg">
|
||||||
|
<Icon icon=icondata::IoAlertCircleSharp />
|
||||||
|
{error_msg.get().as_ref().unwrap()}
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Artist(artist: Artist, artists: ReadSignal<String>, set_artists: WriteSignal<String>, set_filtered: WriteSignal<Vec<Artist>>) -> impl IntoView {
|
||||||
|
// Converts artist name to artist id and adds it to the artist input
|
||||||
|
let add_artist = move |_| {
|
||||||
|
//Create an empty string to hold previous artist ids
|
||||||
|
let mut s: String = String::from("");
|
||||||
|
//Get the current artist input
|
||||||
|
let all_artirts: String = artists.get();
|
||||||
|
//Split the input into a vector of artists separated by commas
|
||||||
|
let mut ids: Vec<&str> = all_artirts.split(",").collect();
|
||||||
|
//If there is only one artist in the input, get their id equivalent and add it to the string
|
||||||
|
if ids.len() == 1 {
|
||||||
|
let value_str = match artist.id.clone() {
|
||||||
|
Some(v) => v.to_string(),
|
||||||
|
None => String::from("None"),
|
||||||
|
};
|
||||||
|
s.push_str(&value_str);
|
||||||
|
s.push_str(",");
|
||||||
|
set_artists.update(|value| *value = s);
|
||||||
|
//If there are multiple artists in the input, pop the last artist by string off the vector,
|
||||||
|
//get their id equivalent, and add it to the string
|
||||||
|
} else {
|
||||||
|
ids.pop();
|
||||||
|
for id in ids {
|
||||||
|
s.push_str(id);
|
||||||
|
s.push_str(",");
|
||||||
|
}
|
||||||
|
let value_str = match artist.id.clone() {
|
||||||
|
Some(v) => v.to_string(),
|
||||||
|
None => String::from("None"),
|
||||||
|
};
|
||||||
|
s.push_str(&value_str);
|
||||||
|
s.push_str(",");
|
||||||
|
set_artists.update(|value| *value = s);
|
||||||
|
}
|
||||||
|
//Clear the search results
|
||||||
|
set_filtered.update(|value| *value = vec![]);
|
||||||
|
};
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<div class="artist result" on:click=add_artist>
|
||||||
|
{artist.name.clone()}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[component]
|
||||||
|
pub fn Album(album: Album, _albums: ReadSignal<String>, set_albums: WriteSignal<String>, set_filtered: WriteSignal<Vec<Album>>) -> impl IntoView {
|
||||||
|
//Converts album title to album id to upload a song
|
||||||
|
let add_album = move |_| {
|
||||||
|
let value_str = match album.id.clone() {
|
||||||
|
Some(v) => v.to_string(),
|
||||||
|
None => String::from("None"),
|
||||||
|
};
|
||||||
|
set_albums.update(|value| *value = value_str);
|
||||||
|
set_filtered.update(|value| *value = vec![]);
|
||||||
|
};
|
||||||
|
view! {
|
||||||
|
<div class="album result" on:click=add_album>
|
||||||
|
{album.title.clone()}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
@ -29,11 +29,11 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
|||||||
let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap();
|
let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap();
|
||||||
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
||||||
// This path is relative to the cargo root
|
// This path is relative to the cargo root
|
||||||
match ServeDir::new(root).oneshot(req).await {
|
match ServeDir::new(root).oneshot(req).await.ok() {
|
||||||
Ok(res) => Ok(res.into_response()),
|
Some(res) => Ok(res.into_response()),
|
||||||
Err(err) => Err((
|
None => Err((
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("Something went wrong: {err}"),
|
format!("Something went wrong"),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ pub mod auth;
|
|||||||
pub mod songdata;
|
pub mod songdata;
|
||||||
pub mod playstatus;
|
pub mod playstatus;
|
||||||
pub mod playbar;
|
pub mod playbar;
|
||||||
|
pub mod audioplayer;
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
@ -14,6 +15,9 @@ pub mod search;
|
|||||||
pub mod fileserv;
|
pub mod fileserv;
|
||||||
pub mod error_template;
|
pub mod error_template;
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
pub mod upload;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
|
38
src/main.rs
38
src/main.rs
@ -1,10 +1,10 @@
|
|||||||
// Needed for building in Docker container
|
// Needed for building in Docker container
|
||||||
// See https://github.com/clux/muslrust?tab=readme-ov-file#diesel-and-pq-builds
|
// See https://github.com/clux/muslrust?tab=readme-ov-file#diesel-and-pq-builds
|
||||||
// See https://github.com/sgrif/pq-sys/issues/25
|
// See https://github.com/sgrif/pq-sys/issues/25
|
||||||
#[cfg(target = "x86_64-unknown-linux-musl")]
|
#[cfg(target_env = "musl")]
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
|
|
||||||
#[cfg(target = "x86_64-unknown-linux-musl")]
|
#[cfg(target_env = "musl")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
@ -19,17 +19,27 @@ async fn main() {
|
|||||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||||
use libretunes::app::*;
|
use libretunes::app::*;
|
||||||
use libretunes::fileserv::{file_and_error_handler, get_static_file};
|
use libretunes::fileserv::{file_and_error_handler, get_static_file};
|
||||||
use tower_sessions::SessionManagerLayer;
|
use axum_login::tower_sessions::SessionManagerLayer;
|
||||||
use tower_sessions_redis_store::{fred::prelude::*, RedisStore};
|
use tower_sessions_redis_store::{fred::prelude::*, RedisStore};
|
||||||
use axum_login::AuthManagerLayerBuilder;
|
use axum_login::AuthManagerLayerBuilder;
|
||||||
use libretunes::auth_backend::AuthBackend;
|
use libretunes::auth_backend::AuthBackend;
|
||||||
|
use log::*;
|
||||||
|
|
||||||
|
flexi_logger::Logger::try_with_env_or_str("debug").unwrap().format(flexi_logger::opt_format).start().unwrap();
|
||||||
|
|
||||||
|
info!("\n{}", include_str!("../ascii_art.txt"));
|
||||||
|
info!("Starting Leptos server...");
|
||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
|
debug!("Running database migrations...");
|
||||||
|
|
||||||
// Bring the database up to date
|
// Bring the database up to date
|
||||||
libretunes::database::migrate();
|
libretunes::database::migrate();
|
||||||
|
|
||||||
|
debug!("Connecting to Redis...");
|
||||||
|
|
||||||
let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set");
|
let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set");
|
||||||
let redis_config = RedisConfig::from_url(&redis_url).expect(&format!("Unable to parse Redis URL: {}", redis_url));
|
let redis_config = RedisConfig::from_url(&redis_url).expect(&format!("Unable to parse Redis URL: {}", redis_url));
|
||||||
let redis_pool = RedisPool::new(redis_config, None, None, None, 1).expect("Unable to create Redis pool");
|
let redis_pool = RedisPool::new(redis_config, None, None, None, 1).expect("Unable to create Redis pool");
|
||||||
@ -55,30 +65,16 @@ async fn main() {
|
|||||||
.fallback(file_and_error_handler)
|
.fallback(file_and_error_handler)
|
||||||
.with_state(leptos_options);
|
.with_state(leptos_options);
|
||||||
|
|
||||||
println!("listening on http://{}", &addr);
|
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind(&addr).await.expect(&format!("Could not bind to {}", &addr));
|
let listener = tokio::net::TcpListener::bind(&addr).await.expect(&format!("Could not bind to {}", &addr));
|
||||||
|
|
||||||
|
info!("Listening on http://{}", &addr);
|
||||||
|
|
||||||
axum::serve(listener, app.into_make_service()).await.expect("Server failed");
|
axum::serve(listener, app.into_make_service()).await.expect("Server failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "ssr", feature = "csr")))]
|
#[cfg(not(feature = "ssr"))]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// no client-side main function
|
// no client-side main function
|
||||||
// unless we want this to work with e.g., Trunk for pure client-side testing
|
// unless we want this to work with e.g., Trunk for pure client-side testing
|
||||||
// see lib.rs for hydration function instead
|
// see lib.rs for hydration function instead
|
||||||
// see optional feature `csr` instead
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "ssr"), feature = "csr"))]
|
|
||||||
pub fn main() {
|
|
||||||
// a client-side main function is required for using `trunk serve`
|
|
||||||
// prefer using `cargo leptos serve` instead
|
|
||||||
// to run: `trunk serve --open --features csr`
|
|
||||||
use leptos::*;
|
|
||||||
use libretunes::app::*;
|
|
||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
|
||||||
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
|
|
||||||
leptos::mount_to_body(App);
|
|
||||||
}
|
}
|
||||||
|
261
src/models.rs
261
src/models.rs
@ -41,13 +41,144 @@ pub struct User {
|
|||||||
/// The time the user was created
|
/// The time the user was created
|
||||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = SystemTime))]
|
#[cfg_attr(feature = "ssr", diesel(deserialize_as = SystemTime))]
|
||||||
pub created_at: Option<SystemTime>,
|
pub created_at: Option<SystemTime>,
|
||||||
|
/// Whether the user is an admin
|
||||||
|
pub admin: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl User {
|
||||||
|
/// Like or unlike a song for this user
|
||||||
|
/// If likeing a song, remove dislike if it exists
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn set_like_song(self: &Self, song_id: i32, like: bool, conn: &mut PgPooledConn) ->
|
||||||
|
Result<(), Box<dyn Error>> {
|
||||||
|
use log::*;
|
||||||
|
debug!("Setting like for song {} to {}", song_id, like);
|
||||||
|
|
||||||
|
use crate::schema::song_likes;
|
||||||
|
use crate::schema::song_dislikes;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to like/un-like a song")?;
|
||||||
|
|
||||||
|
if like {
|
||||||
|
diesel::insert_into(song_likes::table)
|
||||||
|
.values((song_likes::song_id.eq(song_id), song_likes::user_id.eq(my_id)))
|
||||||
|
.execute(conn)?;
|
||||||
|
|
||||||
|
// Remove dislike if it exists
|
||||||
|
diesel::delete(song_dislikes::table.filter(song_dislikes::song_id.eq(song_id)
|
||||||
|
.and(song_dislikes::user_id.eq(my_id))))
|
||||||
|
.execute(conn)?;
|
||||||
|
} else {
|
||||||
|
diesel::delete(song_likes::table.filter(song_likes::song_id.eq(song_id).and(song_likes::user_id.eq(my_id))))
|
||||||
|
.execute(conn)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the like status of a song for this user
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn get_like_song(self: &Self, song_id: i32, conn: &mut PgPooledConn) -> Result<bool, Box<dyn Error>> {
|
||||||
|
use crate::schema::song_likes;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to get like status of a song")?;
|
||||||
|
|
||||||
|
let like = song_likes::table
|
||||||
|
.filter(song_likes::song_id.eq(song_id).and(song_likes::user_id.eq(my_id)))
|
||||||
|
.first::<(i32, i32)>(conn)
|
||||||
|
.optional()?
|
||||||
|
.is_some();
|
||||||
|
|
||||||
|
Ok(like)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get songs liked by this user
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn get_liked_songs(self: &Self, conn: &mut PgPooledConn) -> Result<Vec<Song>, Box<dyn Error>> {
|
||||||
|
use crate::schema::songs::dsl::*;
|
||||||
|
use crate::schema::song_likes::dsl::*;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to get liked songs")?;
|
||||||
|
|
||||||
|
let my_songs = songs
|
||||||
|
.inner_join(song_likes)
|
||||||
|
.filter(user_id.eq(my_id))
|
||||||
|
.select(songs::all_columns())
|
||||||
|
.load(conn)?;
|
||||||
|
|
||||||
|
Ok(my_songs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dislike or remove dislike from a song for this user
|
||||||
|
/// If disliking a song, remove like if it exists
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn set_dislike_song(self: &Self, song_id: i32, dislike: bool, conn: &mut PgPooledConn) ->
|
||||||
|
Result<(), Box<dyn Error>> {
|
||||||
|
use log::*;
|
||||||
|
debug!("Setting dislike for song {} to {}", song_id, dislike);
|
||||||
|
|
||||||
|
use crate::schema::song_likes;
|
||||||
|
use crate::schema::song_dislikes;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to dislike/un-dislike a song")?;
|
||||||
|
|
||||||
|
if dislike {
|
||||||
|
diesel::insert_into(song_dislikes::table)
|
||||||
|
.values((song_dislikes::song_id.eq(song_id), song_dislikes::user_id.eq(my_id)))
|
||||||
|
.execute(conn)?;
|
||||||
|
|
||||||
|
// Remove like if it exists
|
||||||
|
diesel::delete(song_likes::table.filter(song_likes::song_id.eq(song_id)
|
||||||
|
.and(song_likes::user_id.eq(my_id))))
|
||||||
|
.execute(conn)?;
|
||||||
|
} else {
|
||||||
|
diesel::delete(song_dislikes::table.filter(song_dislikes::song_id.eq(song_id)
|
||||||
|
.and(song_dislikes::user_id.eq(my_id))))
|
||||||
|
.execute(conn)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the dislike status of a song for this user
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn get_dislike_song(self: &Self, song_id: i32, conn: &mut PgPooledConn) -> Result<bool, Box<dyn Error>> {
|
||||||
|
use crate::schema::song_dislikes;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to get dislike status of a song")?;
|
||||||
|
|
||||||
|
let dislike = song_dislikes::table
|
||||||
|
.filter(song_dislikes::song_id.eq(song_id).and(song_dislikes::user_id.eq(my_id)))
|
||||||
|
.first::<(i32, i32)>(conn)
|
||||||
|
.optional()?
|
||||||
|
.is_some();
|
||||||
|
|
||||||
|
Ok(dislike)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get songs disliked by this user
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub async fn get_disliked_songs(self: &Self, conn: &mut PgPooledConn) -> Result<Vec<Song>, Box<dyn Error>> {
|
||||||
|
use crate::schema::songs::dsl::*;
|
||||||
|
use crate::schema::song_likes::dsl::*;
|
||||||
|
|
||||||
|
let my_id = self.id.ok_or("User id must be present (Some) to get disliked songs")?;
|
||||||
|
|
||||||
|
let my_songs = songs
|
||||||
|
.inner_join(song_likes)
|
||||||
|
.filter(user_id.eq(my_id))
|
||||||
|
.select(songs::all_columns())
|
||||||
|
.load(conn)?;
|
||||||
|
|
||||||
|
Ok(my_songs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Model for an artist
|
/// Model for an artist
|
||||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable, Identifiable))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::artists))]
|
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::artists))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct Artist {
|
pub struct Artist {
|
||||||
/// A unique id for the artist
|
/// A unique id for the artist
|
||||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||||
@ -162,13 +293,33 @@ impl Artist {
|
|||||||
|
|
||||||
Ok(my_songs)
|
Ok(my_songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display a list of artists as a string.
|
||||||
|
///
|
||||||
|
/// For one artist, displays [artist1]. For two artists, displays [artist1] & [artist2].
|
||||||
|
/// For three or more artists, displays [artist1], [artist2], & [artist3].
|
||||||
|
pub fn display_list(artists: &Vec<Artist>) -> String {
|
||||||
|
let mut artist_list = String::new();
|
||||||
|
|
||||||
|
for (i, artist) in artists.iter().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
artist_list.push_str(&artist.name);
|
||||||
|
} else if i == artists.len() - 1 {
|
||||||
|
artist_list.push_str(&format!(" & {}", artist.name));
|
||||||
|
} else {
|
||||||
|
artist_list.push_str(&format!(", {}", artist.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
artist_list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Model for an album
|
/// Model for an album
|
||||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable, Identifiable))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::albums))]
|
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::albums))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct Album {
|
pub struct Album {
|
||||||
/// A unique id for the album
|
/// A unique id for the album
|
||||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||||
@ -177,6 +328,8 @@ pub struct Album {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
/// The album's release date
|
/// The album's release date
|
||||||
pub release_date: Option<Date>,
|
pub release_date: Option<Date>,
|
||||||
|
/// The path to the album's image file
|
||||||
|
pub image_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Album {
|
impl Album {
|
||||||
@ -239,7 +392,7 @@ impl Album {
|
|||||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::songs))]
|
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::songs))]
|
||||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
/// A unique id for the song
|
/// A unique id for the song
|
||||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||||
@ -289,78 +442,8 @@ impl Song {
|
|||||||
|
|
||||||
Ok(my_artists)
|
Ok(my_artists)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/// Model for an playlist
|
|
||||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
|
||||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::playlists))]
|
|
||||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct Playlist {
|
|
||||||
/// A unique id for the playlist
|
|
||||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
|
||||||
pub id: Option<i32>,
|
|
||||||
/// The playlist's name
|
|
||||||
pub name: String,
|
|
||||||
/// The user who created the playlist
|
|
||||||
pub user_id: i32,
|
|
||||||
}
|
|
||||||
impl Playlist {
|
|
||||||
|
|
||||||
/// Create a new, empty playlist in the database
|
/// Get the album for this song from the database
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `new_playlist` - The new playlist
|
|
||||||
/// * `conn` - A mutable reference to a database connection
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<(), Box<dyn Error>>` - A result indicating success with the new playlist, or an error
|
|
||||||
///
|
|
||||||
#[cfg(feature = "ssr")]
|
|
||||||
pub fn create_playlist(new_playlist: Playlist, conn: &mut PgPooledConn) -> Result<(), Box<dyn Error>> {
|
|
||||||
use crate::schema::playlists::dsl::*;
|
|
||||||
|
|
||||||
let new_playlist = Playlist {
|
|
||||||
..new_playlist
|
|
||||||
};
|
|
||||||
|
|
||||||
diesel::insert_into(playlists)
|
|
||||||
.values(&new_playlist)
|
|
||||||
.execute(conn)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a song to this playlist in the database
|
|
||||||
///
|
|
||||||
/// The 'id' field of this playlist must be present (Some) to add a song
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `new_song_id` - The id of the song to add to this playlist
|
|
||||||
/// * `conn` - A mutable reference to a database connection
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<(), Box<dyn Error>>` - A result indicating success with an empty value, or an error
|
|
||||||
///
|
|
||||||
#[cfg(feature = "ssr")]
|
|
||||||
pub fn add_song(self: &Self, new_song_id: i32, conn: &mut PgPooledConn) -> Result<(), Box<dyn Error>> {
|
|
||||||
use crate::schema::playlist_songs::dsl::*;
|
|
||||||
|
|
||||||
let my_id = self.id.ok_or("Playlist id must be present (Some) to add a song")?;
|
|
||||||
|
|
||||||
diesel::insert_into(playlist_songs)
|
|
||||||
.values((playlist_id.eq(my_id), song_id.eq(new_song_id)))
|
|
||||||
.execute(conn)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get songs by this playlist from the database
|
|
||||||
///
|
|
||||||
/// The 'id' field of this playlist must be present (Some) to get songs
|
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
@ -368,23 +451,21 @@ impl Playlist {
|
|||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * `Result<Vec<Song>, Box<dyn Error>>` - A result indicating success with a vector of songs, or an error
|
/// * `Result<Option<Album>, Box<dyn Error>>` - A result indicating success with an album, or None if
|
||||||
|
/// the song does not have an album, or an error
|
||||||
///
|
///
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub fn get_songs(self: &Self, conn: &mut PgPooledConn) -> Result<Vec<Song>, Box<dyn Error>> {
|
pub fn get_album(self: &Self, conn: &mut PgPooledConn) -> Result<Option<Album>, Box<dyn Error>> {
|
||||||
use crate::schema::songs::dsl::*;
|
use crate::schema::albums::dsl::*;
|
||||||
use crate::schema::playlist_songs::dsl::*;
|
|
||||||
|
|
||||||
let my_id = self.id.ok_or("Playlist id must be present (Some) to get songs")?;
|
if let Some(album_id) = self.album_id {
|
||||||
|
let my_album = albums
|
||||||
|
.filter(id.eq(album_id))
|
||||||
|
.first::<Album>(conn)?;
|
||||||
|
|
||||||
let my_songs = songs
|
Ok(Some(my_album))
|
||||||
.inner_join(playlist_songs)
|
} else {
|
||||||
.filter(playlist_id.eq(my_id))
|
Ok(None)
|
||||||
.select(songs::all_columns())
|
}
|
||||||
.load(conn)?;
|
|
||||||
|
|
||||||
Ok(my_songs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,2 +1,3 @@
|
|||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod signup;
|
pub mod signup;
|
||||||
|
pub mod audiotest;
|
9
src/pages/audiotest.rs
Normal file
9
src/pages/audiotest.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use leptos::leptos_dom::*;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn AudioTest() -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<p>Hello World</p>
|
||||||
|
}
|
||||||
|
}
|
@ -73,7 +73,9 @@ pub fn Login() -> impl IntoView {
|
|||||||
<i></i>
|
<i></i>
|
||||||
<Show
|
<Show
|
||||||
when=move || {show_password() == false}
|
when=move || {show_password() == false}
|
||||||
fallback=move || view!{ <button on:click=toggle_password class="login-password-visibility"><Icon icon=icondata::AiEyeInvisibleFilled /></button> /> }
|
fallback=move || view!{ <button on:click=toggle_password class="login-password-visibility">
|
||||||
|
<Icon icon=icondata::AiEyeInvisibleFilled />
|
||||||
|
</button> /> }
|
||||||
>
|
>
|
||||||
<button on:click=toggle_password class="login-password-visibility">
|
<button on:click=toggle_password class="login-password-visibility">
|
||||||
<Icon icon=icondata::AiEyeFilled />
|
<Icon icon=icondata::AiEyeFilled />
|
||||||
|
@ -25,6 +25,7 @@ pub fn Signup() -> impl IntoView {
|
|||||||
email: email.get(),
|
email: email.get(),
|
||||||
password: Some(password.get()),
|
password: Some(password.get()),
|
||||||
created_at: None,
|
created_at: None,
|
||||||
|
admin: false,
|
||||||
};
|
};
|
||||||
log!("new user: {:?}", new_user);
|
log!("new user: {:?}", new_user);
|
||||||
|
|
||||||
|
134
src/playbar.rs
134
src/playbar.rs
@ -1,4 +1,7 @@
|
|||||||
|
use crate::models::Artist;
|
||||||
use crate::playstatus::PlayStatus;
|
use crate::playstatus::PlayStatus;
|
||||||
|
use crate::songdata::SongData;
|
||||||
|
use crate::api::songs;
|
||||||
use leptos::ev::MouseEvent;
|
use leptos::ev::MouseEvent;
|
||||||
use leptos::html::{Audio, Div};
|
use leptos::html::{Audio, Div};
|
||||||
use leptos::leptos_dom::*;
|
use leptos::leptos_dom::*;
|
||||||
@ -243,37 +246,149 @@ fn PlayDuration(elapsed_secs: MaybeSignal<i64>, total_secs: MaybeSignal<i64>) ->
|
|||||||
fn MediaInfo(status: RwSignal<PlayStatus>) -> impl IntoView {
|
fn MediaInfo(status: RwSignal<PlayStatus>) -> impl IntoView {
|
||||||
let name = Signal::derive(move || {
|
let name = Signal::derive(move || {
|
||||||
status.with(|status| {
|
status.with(|status| {
|
||||||
status.queue.front().map_or("No media playing".into(), |song| song.name.clone())
|
status.queue.front().map_or("No media playing".into(), |song| song.title.clone())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let artist = Signal::derive(move || {
|
let artist = Signal::derive(move || {
|
||||||
status.with(|status| {
|
status.with(|status| {
|
||||||
status.queue.front().map_or("".into(), |song| song.artist.clone())
|
status.queue.front().map_or("".into(), |song| format!("{}", Artist::display_list(&song.artists)))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let album = Signal::derive(move || {
|
let album = Signal::derive(move || {
|
||||||
status.with(|status| {
|
status.with(|status| {
|
||||||
status.queue.front().map_or("".into(), |song| song.album.clone())
|
status.queue.front().map_or("".into(), |song|
|
||||||
|
song.album.as_ref().map_or("".into(), |album| album.title.clone()))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let image = Signal::derive(move || {
|
let image = Signal::derive(move || {
|
||||||
status.with(|status| {
|
status.with(|status| {
|
||||||
// TODO Use some default / unknown image?
|
status.queue.front().map_or("/images/placeholders/MusicPlaceholder.svg".into(),
|
||||||
status.queue.front().map_or("".into(), |song| song.image_path.clone())
|
|song| song.image_path.clone())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div class="media-info">
|
|
||||||
<img class="media-info-img" align="left" src={image}/>
|
<img class="media-info-img" align="left" src={image}/>
|
||||||
<div class="media-info-text">
|
<div class="media-info-text">
|
||||||
{name}
|
{name}
|
||||||
<br/>
|
<br/>
|
||||||
{artist} - {album}
|
{artist} - {album}
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The like and dislike buttons
|
||||||
|
#[component]
|
||||||
|
fn LikeDislike(status: RwSignal<PlayStatus>) -> impl IntoView {
|
||||||
|
let like_icon = Signal::derive(move || {
|
||||||
|
status.with(|status| {
|
||||||
|
match status.queue.front() {
|
||||||
|
Some(SongData { like_dislike: Some((true, _)), .. }) => icondata::TbThumbUpFilled,
|
||||||
|
_ => icondata::TbThumbUp,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let dislike_icon = Signal::derive(move || {
|
||||||
|
status.with(|status| {
|
||||||
|
match status.queue.front() {
|
||||||
|
Some(SongData { like_dislike: Some((_, true)), .. }) => icondata::TbThumbDownFilled,
|
||||||
|
_ => icondata::TbThumbDown,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let toggle_like = move |_| {
|
||||||
|
status.update(|status| {
|
||||||
|
match status.queue.front_mut() {
|
||||||
|
Some(SongData { id, like_dislike: Some((liked, disliked)), .. }) => {
|
||||||
|
*liked = !*liked;
|
||||||
|
|
||||||
|
if *liked {
|
||||||
|
*disliked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = *id;
|
||||||
|
let liked = *liked;
|
||||||
|
spawn_local(async move {
|
||||||
|
if let Err(e) = songs::set_like_song(id, liked).await {
|
||||||
|
error!("Error liking song: {:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
Some(SongData { id, like_dislike, .. }) => {
|
||||||
|
// This arm should only be reached if like_dislike is None
|
||||||
|
// In this case, the buttons will show up not filled, indicating that the song is not
|
||||||
|
// liked or disliked. Therefore, clicking the like button should like the song.
|
||||||
|
|
||||||
|
*like_dislike = Some((true, false));
|
||||||
|
|
||||||
|
let id = *id;
|
||||||
|
spawn_local(async move {
|
||||||
|
if let Err(e) = songs::set_like_song(id, true).await {
|
||||||
|
error!("Error liking song: {:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
log!("Unable to like song: No song in queue");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let toggle_dislike = move |_| {
|
||||||
|
status.update(|status| {
|
||||||
|
match status.queue.front_mut() {
|
||||||
|
Some(SongData { id, like_dislike: Some((liked, disliked)), .. }) => {
|
||||||
|
*disliked = !*disliked;
|
||||||
|
|
||||||
|
if *disliked {
|
||||||
|
*liked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = *id;
|
||||||
|
let disliked = *disliked;
|
||||||
|
spawn_local(async move {
|
||||||
|
if let Err(e) = songs::set_dislike_song(id, disliked).await {
|
||||||
|
error!("Error disliking song: {:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
Some(SongData { id, like_dislike, .. }) => {
|
||||||
|
// This arm should only be reached if like_dislike is None
|
||||||
|
// In this case, the buttons will show up not filled, indicating that the song is not
|
||||||
|
// liked or disliked. Therefore, clicking the dislike button should dislike the song.
|
||||||
|
|
||||||
|
*like_dislike = Some((false, true));
|
||||||
|
|
||||||
|
let id = *id;
|
||||||
|
spawn_local(async move {
|
||||||
|
if let Err(e) = songs::set_dislike_song(id, true).await {
|
||||||
|
error!("Error disliking song: {:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
log!("Unable to dislike song: No song in queue");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<div class="like-dislike">
|
||||||
|
<button on:click=toggle_dislike>
|
||||||
|
<Icon class="controlbtn hmirror" width=SKIP_BTN_SIZE height=SKIP_BTN_SIZE icon=dislike_icon />
|
||||||
|
</button>
|
||||||
|
<button on:click=toggle_like>
|
||||||
|
<Icon class="controlbtn" width=SKIP_BTN_SIZE height=SKIP_BTN_SIZE icon=like_icon />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +515,7 @@ pub fn PlayBar(status: RwSignal<PlayStatus>) -> impl IntoView {
|
|||||||
status.with_untracked(|status| {
|
status.with_untracked(|status| {
|
||||||
// Start playing the first song in the queue, if available
|
// Start playing the first song in the queue, if available
|
||||||
if let Some(song) = status.queue.front() {
|
if let Some(song) = status.queue.front() {
|
||||||
log!("Starting playing with song: {}", song.name);
|
log!("Starting playing with song: {}", song.title);
|
||||||
|
|
||||||
// Don't use the set_play_src / set_playing helper function
|
// Don't use the set_play_src / set_playing helper function
|
||||||
// here because we already have access to the audio element
|
// here because we already have access to the audio element
|
||||||
@ -453,7 +568,7 @@ pub fn PlayBar(status: RwSignal<PlayStatus>) -> impl IntoView {
|
|||||||
let prev_song = status.queue.pop_front();
|
let prev_song = status.queue.pop_front();
|
||||||
|
|
||||||
if let Some(prev_song) = prev_song {
|
if let Some(prev_song) = prev_song {
|
||||||
log!("Adding song to history: {}", prev_song.name);
|
log!("Adding song to history: {}", prev_song.title);
|
||||||
status.history.push_back(prev_song);
|
status.history.push_back(prev_song);
|
||||||
} else {
|
} else {
|
||||||
log!("Queue empty, no previous song to add to history");
|
log!("Queue empty, no previous song to add to history");
|
||||||
@ -486,7 +601,10 @@ pub fn PlayBar(status: RwSignal<PlayStatus>) -> impl IntoView {
|
|||||||
on:timeupdate=on_time_update on:ended=on_end type="audio/mpeg" />
|
on:timeupdate=on_time_update on:ended=on_end type="audio/mpeg" />
|
||||||
<div class="playbar">
|
<div class="playbar">
|
||||||
<ProgressBar percentage=percentage.into() status=status />
|
<ProgressBar percentage=percentage.into() status=status />
|
||||||
|
<div class="playbar-left-group">
|
||||||
<MediaInfo status=status />
|
<MediaInfo status=status />
|
||||||
|
<LikeDislike status=status />
|
||||||
|
</div>
|
||||||
<PlayControls status=status />
|
<PlayControls status=status />
|
||||||
<PlayDuration elapsed_secs=elapsed_secs.into() total_secs=total_secs.into() />
|
<PlayDuration elapsed_secs=elapsed_secs.into() total_secs=total_secs.into() />
|
||||||
<QueueToggle status=status />
|
<QueueToggle status=status />
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::models::Artist;
|
||||||
use crate::playstatus::PlayStatus;
|
use crate::playstatus::PlayStatus;
|
||||||
use crate::song::Song;
|
use crate::song::Song;
|
||||||
use leptos::ev::MouseEvent;
|
use leptos::ev::MouseEvent;
|
||||||
@ -98,7 +99,7 @@ pub fn Queue(status: RwSignal<PlayStatus>) -> impl IntoView {
|
|||||||
on:dragenter=move |e: DragEvent| on_drag_enter(e, index)
|
on:dragenter=move |e: DragEvent| on_drag_enter(e, index)
|
||||||
on:dragover=on_drag_over
|
on:dragover=on_drag_over
|
||||||
>
|
>
|
||||||
<Song song_image_path=song.image_path.clone() song_title=song.name.clone() song_artist=song.artist.clone() />
|
<Song song_image_path=song.image_path.clone() song_title=song.title.clone() song_artist=Artist::display_list(&song.artists) />
|
||||||
<Show
|
<Show
|
||||||
when=move || index != 0
|
when=move || index != 0
|
||||||
fallback=|| view!{
|
fallback=|| view!{
|
||||||
|
@ -12,6 +12,7 @@ diesel::table! {
|
|||||||
id -> Int4,
|
id -> Int4,
|
||||||
title -> Varchar,
|
title -> Varchar,
|
||||||
release_date -> Nullable<Date>,
|
release_date -> Nullable<Date>,
|
||||||
|
image_path -> Nullable<Varchar>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,25 +24,23 @@ diesel::table! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
playlist_songs (playlist_id, song_id) {
|
song_artists (song_id, artist_id) {
|
||||||
playlist_id -> Int4,
|
|
||||||
song_id -> Int4,
|
song_id -> Int4,
|
||||||
position -> Int4,
|
artist_id -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
playlists (id) {
|
song_dislikes (song_id, user_id) {
|
||||||
id -> Int4,
|
song_id -> Int4,
|
||||||
name -> Varchar,
|
|
||||||
user_id -> Int4,
|
user_id -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
song_artists (song_id, artist_id) {
|
song_likes (song_id, user_id) {
|
||||||
song_id -> Int4,
|
song_id -> Int4,
|
||||||
artist_id -> Int4,
|
user_id -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,25 +64,27 @@ diesel::table! {
|
|||||||
email -> Varchar,
|
email -> Varchar,
|
||||||
password -> Varchar,
|
password -> Varchar,
|
||||||
created_at -> Timestamp,
|
created_at -> Timestamp,
|
||||||
|
admin -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::joinable!(album_artists -> albums (album_id));
|
diesel::joinable!(album_artists -> albums (album_id));
|
||||||
diesel::joinable!(album_artists -> artists (artist_id));
|
diesel::joinable!(album_artists -> artists (artist_id));
|
||||||
diesel::joinable!(playlist_songs -> playlists (playlist_id));
|
|
||||||
diesel::joinable!(playlist_songs -> songs (song_id));
|
|
||||||
diesel::joinable!(playlists -> users (user_id));
|
|
||||||
diesel::joinable!(song_artists -> artists (artist_id));
|
diesel::joinable!(song_artists -> artists (artist_id));
|
||||||
diesel::joinable!(song_artists -> songs (song_id));
|
diesel::joinable!(song_artists -> songs (song_id));
|
||||||
|
diesel::joinable!(song_dislikes -> songs (song_id));
|
||||||
|
diesel::joinable!(song_dislikes -> users (user_id));
|
||||||
|
diesel::joinable!(song_likes -> songs (song_id));
|
||||||
|
diesel::joinable!(song_likes -> users (user_id));
|
||||||
diesel::joinable!(songs -> albums (album_id));
|
diesel::joinable!(songs -> albums (album_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
album_artists,
|
album_artists,
|
||||||
albums,
|
albums,
|
||||||
artists,
|
artists,
|
||||||
playlist_songs,
|
|
||||||
playlists,
|
|
||||||
song_artists,
|
song_artists,
|
||||||
|
song_dislikes,
|
||||||
|
song_likes,
|
||||||
songs,
|
songs,
|
||||||
users,
|
users,
|
||||||
);
|
);
|
||||||
|
@ -102,7 +102,7 @@ pub async fn search(query: String, limit: i64) -> Result<(Vec<Album>, Vec<Artist
|
|||||||
let artists = search_artists(query.clone(), limit);
|
let artists = search_artists(query.clone(), limit);
|
||||||
let songs = search_songs(query.clone(), limit);
|
let songs = search_songs(query.clone(), limit);
|
||||||
|
|
||||||
use futures::join;
|
use tokio::join;
|
||||||
|
|
||||||
let (albums, artists, songs) = join!(albums, artists, songs);
|
let (albums, artists, songs) = join!(albums, artists, songs);
|
||||||
Ok((albums?, artists?, songs?))
|
Ok((albums?, artists?, songs?))
|
||||||
|
@ -1,16 +1,62 @@
|
|||||||
|
use crate::models::{Album, Artist, Song};
|
||||||
|
|
||||||
|
use time::Date;
|
||||||
|
|
||||||
/// Holds information about a song
|
/// Holds information about a song
|
||||||
#[derive(Debug, Clone)]
|
///
|
||||||
|
/// Intended to be used in the front-end, as it includes artist and album objects, rather than just their ids.
|
||||||
pub struct SongData {
|
pub struct SongData {
|
||||||
|
/// Song id
|
||||||
|
pub id: i32,
|
||||||
/// Song name
|
/// Song name
|
||||||
pub name: String,
|
pub title: String,
|
||||||
/// Song artist
|
/// Song artists
|
||||||
pub artist: String,
|
pub artists: Vec<Artist>,
|
||||||
/// Song album
|
/// Song album
|
||||||
pub album: String,
|
pub album: Option<Album>,
|
||||||
|
/// The track number of the song on the album
|
||||||
|
pub track: Option<i32>,
|
||||||
|
/// The duration of the song in seconds
|
||||||
|
pub duration: i32,
|
||||||
|
/// The song's release date
|
||||||
|
pub release_date: Option<Date>,
|
||||||
/// Path to song file, relative to the root of the web server.
|
/// Path to song file, relative to the root of the web server.
|
||||||
/// For example, `"/assets/audio/Song.mp3"`
|
/// For example, `"/assets/audio/Song.mp3"`
|
||||||
pub song_path: String,
|
pub song_path: String,
|
||||||
/// Path to song image, relative to the root of the web server.
|
/// Path to song image, relative to the root of the web server.
|
||||||
/// For example, `"/assets/images/Song.jpg"`
|
/// For example, `"/assets/images/Song.jpg"`
|
||||||
pub image_path: String,
|
pub image_path: String,
|
||||||
|
/// Whether the song is liked by the user
|
||||||
|
pub like_dislike: Option<(bool, bool)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl TryInto<Song> for SongData {
|
||||||
|
type Error = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
|
/// Convert a SongData object into a Song object
|
||||||
|
///
|
||||||
|
/// The SongData/Song conversions are also not truly reversible,
|
||||||
|
/// due to the way the image_path data is handled.
|
||||||
|
fn try_into(self) -> Result<Song, Self::Error> {
|
||||||
|
Ok(Song {
|
||||||
|
id: Some(self.id),
|
||||||
|
title: self.title,
|
||||||
|
album_id: self.album.map(|album|
|
||||||
|
album.id.ok_or("Album id must be present (Some) to convert to Song")).transpose()?,
|
||||||
|
track: self.track,
|
||||||
|
duration: self.duration,
|
||||||
|
release_date: self.release_date,
|
||||||
|
// TODO https://gitlab.mregirouard.com/libretunes/libretunes/-/issues/35
|
||||||
|
storage_path: self.song_path,
|
||||||
|
|
||||||
|
// Note that if the source of the image_path was the album, the image_path
|
||||||
|
// will be set to the album's image_path instead of None
|
||||||
|
image_path: if self.image_path == "/assets/images/placeholder.jpg" {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(self.image_path)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
294
src/upload.rs
Normal file
294
src/upload.rs
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
use leptos::*;
|
||||||
|
use server_fn::codec::{MultipartData, MultipartFormData};
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "ssr")] {
|
||||||
|
use multer::Field;
|
||||||
|
use crate::database::get_db_conn;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use log::*;
|
||||||
|
use server_fn::error::NoCustomError;
|
||||||
|
use time::Date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract the text from a multipart field
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
async fn extract_field(field: Field<'static>) -> Result<String, ServerFnError> {
|
||||||
|
let field = match field.text().await {
|
||||||
|
Ok(field) => field,
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading field: {}", e)))?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate the artist ids in a multipart field
|
||||||
|
/// Expects a field with a comma-separated list of artist ids, and ensures each is a valid artist id in the database
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
async fn validate_artist_ids(artist_ids: Field<'static>) -> Result<Vec<i32>, ServerFnError> {
|
||||||
|
use crate::models::Artist;
|
||||||
|
use diesel::result::Error::NotFound;
|
||||||
|
|
||||||
|
// Extract the artist id from the field
|
||||||
|
match artist_ids.text().await {
|
||||||
|
Ok(artist_ids) => {
|
||||||
|
let artist_ids = artist_ids.trim_end_matches(',').split(',');
|
||||||
|
|
||||||
|
artist_ids.filter(|artist_id| !artist_id.is_empty()).map(|artist_id| {
|
||||||
|
// Parse the artist id as an integer
|
||||||
|
if let Ok(artist_id) = artist_id.parse::<i32>() {
|
||||||
|
// Check if the artist exists
|
||||||
|
let db_con = &mut get_db_conn();
|
||||||
|
let artist = crate::schema::artists::dsl::artists.find(artist_id).first::<Artist>(db_con);
|
||||||
|
|
||||||
|
match artist {
|
||||||
|
Ok(_) => Ok(artist_id),
|
||||||
|
Err(NotFound) => Err(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError("Artist does not exist".to_string())),
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error finding artist id: {}", e))),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ServerFnError::<NoCustomError>::ServerError("Error parsing artist id".to_string()))
|
||||||
|
}
|
||||||
|
}).collect()
|
||||||
|
},
|
||||||
|
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading artist id: {}", e))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate the album id in a multipart field
|
||||||
|
/// Expects a field with an album id, and ensures it is a valid album id in the database
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
async fn validate_album_id(album_id: Field<'static>) -> Result<Option<i32>, ServerFnError> {
|
||||||
|
use crate::models::Album;
|
||||||
|
use diesel::result::Error::NotFound;
|
||||||
|
|
||||||
|
// Extract the album id from the field
|
||||||
|
match album_id.text().await {
|
||||||
|
Ok(album_id) => {
|
||||||
|
if album_id.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the album id as an integer
|
||||||
|
if let Ok(album_id) = album_id.parse::<i32>() {
|
||||||
|
// Check if the album exists
|
||||||
|
let db_con = &mut get_db_conn();
|
||||||
|
let album = crate::schema::albums::dsl::albums.find(album_id).first::<Album>(db_con);
|
||||||
|
|
||||||
|
match album {
|
||||||
|
Ok(_) => Ok(Some(album_id)),
|
||||||
|
Err(NotFound) => Err(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError("Album does not exist".to_string())),
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error finding album id: {}", e))),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ServerFnError::<NoCustomError>::ServerError("Error parsing album id".to_string()))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading album id: {}", e))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate the track number in a multipart field
|
||||||
|
/// Expects a field with a track number, and ensures it is a valid track number (non-negative integer)
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
async fn validate_track_number(track_number: Field<'static>) -> Result<Option<i32>, ServerFnError> {
|
||||||
|
match track_number.text().await {
|
||||||
|
Ok(track_number) => {
|
||||||
|
if track_number.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(track_number) = track_number.parse::<i32>() {
|
||||||
|
if track_number < 0 {
|
||||||
|
return Err(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError("Track number must be positive or 0".to_string()));
|
||||||
|
} else {
|
||||||
|
Ok(Some(track_number))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(ServerFnError::<NoCustomError>::ServerError("Error parsing track number".to_string()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading track number: {}", e)))?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate the release date in a multipart field
|
||||||
|
/// Expects a field with a release date, and ensures it is a valid date in the format [year]-[month]-[day]
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
async fn validate_release_date(release_date: Field<'static>) -> Result<Option<Date>, ServerFnError> {
|
||||||
|
match release_date.text().await {
|
||||||
|
Ok(release_date) => {
|
||||||
|
if release_date.trim().is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let date_format = time::macros::format_description!("[year]-[month]-[day]");
|
||||||
|
let release_date = Date::parse(&release_date.trim(), date_format);
|
||||||
|
|
||||||
|
match release_date {
|
||||||
|
Ok(release_date) => Ok(Some(release_date)),
|
||||||
|
Err(_) => Err(ServerFnError::<NoCustomError>::ServerError("Invalid release date".to_string())),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading release date: {}", e))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle the file upload form
|
||||||
|
#[server(input = MultipartFormData, endpoint = "/upload")]
|
||||||
|
pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
|
||||||
|
// Safe to unwrap - "On the server side, this always returns Some(_). On the client side, always returns None."
|
||||||
|
let mut data = data.into_inner().unwrap();
|
||||||
|
|
||||||
|
let mut title = None;
|
||||||
|
let mut artist_ids = None;
|
||||||
|
let mut album_id = None;
|
||||||
|
let mut track = None;
|
||||||
|
let mut release_date = None;
|
||||||
|
let mut file_name = None;
|
||||||
|
let mut duration = None;
|
||||||
|
|
||||||
|
// Fetch the fields from the form data
|
||||||
|
while let Ok(Some(mut field)) = data.next_field().await {
|
||||||
|
let name = field.name().unwrap_or_default().to_string();
|
||||||
|
|
||||||
|
match name.as_str() {
|
||||||
|
"title" => { title = Some(extract_field(field).await?); },
|
||||||
|
"artist_ids" => { artist_ids = Some(validate_artist_ids(field).await?); },
|
||||||
|
"album_id" => { album_id = Some(validate_album_id(field).await?); },
|
||||||
|
"track_number" => { track = Some(validate_track_number(field).await?); },
|
||||||
|
"release_date" => { release_date = Some(validate_release_date(field).await?); },
|
||||||
|
"file" => {
|
||||||
|
use symphonia::core::codecs::CODEC_TYPE_MP3;
|
||||||
|
use crate::util::audio::extract_metadata;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::{Seek, Write};
|
||||||
|
|
||||||
|
// Some logging is done here where there is high potential for bugs / failures,
|
||||||
|
// or behavior that we may wish to change in the future
|
||||||
|
|
||||||
|
// Create file name
|
||||||
|
let title = title.clone().ok_or(ServerFnError::<NoCustomError>::
|
||||||
|
ServerError("Title field required and must precede file field".to_string()))?;
|
||||||
|
|
||||||
|
let clean_title = title.replace(" ", "_").replace("/", "_");
|
||||||
|
let date_format = time::macros::format_description!("[year]-[month]-[day]_[hour]:[minute]:[second]");
|
||||||
|
let date_str = time::OffsetDateTime::now_utc().format(date_format).unwrap_or_default();
|
||||||
|
let upload_path = format!("assets/audio/upload-{}_{}.mp3", date_str, clean_title);
|
||||||
|
file_name = Some(format!("upload-{}_{}.mp3", date_str, clean_title));
|
||||||
|
|
||||||
|
debug!("Saving uploaded file {}", upload_path);
|
||||||
|
|
||||||
|
// Save file to disk
|
||||||
|
// Use these open options to create the file, write to it, then read from it
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(upload_path.clone())?;
|
||||||
|
|
||||||
|
while let Some(chunk) = field.chunk().await? {
|
||||||
|
file.write(&chunk)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.flush()?;
|
||||||
|
|
||||||
|
// Rewind the file so the duration can be measured
|
||||||
|
file.rewind()?;
|
||||||
|
|
||||||
|
// Get the codec and duration of the file
|
||||||
|
let (file_codec, file_duration) = extract_metadata(file)
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Error measuring duration of audio file {}: {}", upload_path, e);
|
||||||
|
warn!("{}", msg);
|
||||||
|
ServerFnError::<NoCustomError>::ServerError(msg)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if file_codec != CODEC_TYPE_MP3 {
|
||||||
|
let msg = format!("Invalid uploaded audio file codec: {}", file_codec);
|
||||||
|
warn!("{}", msg);
|
||||||
|
return Err(ServerFnError::<NoCustomError>::ServerError(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
duration = Some(file_duration);
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
warn!("Unknown file upload field: {}", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap mandatory fields
|
||||||
|
let title = title.ok_or(ServerFnError::<NoCustomError>::ServerError("Missing title".to_string()))?;
|
||||||
|
let artist_ids = artist_ids.unwrap_or(vec![]);
|
||||||
|
let file_name = file_name.ok_or(ServerFnError::<NoCustomError>::ServerError("Missing file".to_string()))?;
|
||||||
|
let duration = duration.ok_or(ServerFnError::<NoCustomError>::ServerError("Missing duration".to_string()))?;
|
||||||
|
let duration = i32::try_from(duration).map_err(|e| ServerFnError::<NoCustomError>::
|
||||||
|
ServerError(format!("Error converting duration to i32: {}", e)))?;
|
||||||
|
|
||||||
|
let album_id = album_id.unwrap_or(None);
|
||||||
|
let track = track.unwrap_or(None);
|
||||||
|
let release_date = release_date.unwrap_or(None);
|
||||||
|
|
||||||
|
if album_id.is_some() != track.is_some() {
|
||||||
|
return Err(ServerFnError::<NoCustomError>
|
||||||
|
::ServerError("Album id and track number must both be present or both be absent".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the song
|
||||||
|
use crate::models::Song;
|
||||||
|
let song = Song {
|
||||||
|
id: None,
|
||||||
|
title,
|
||||||
|
album_id,
|
||||||
|
track,
|
||||||
|
duration,
|
||||||
|
release_date,
|
||||||
|
storage_path: file_name,
|
||||||
|
image_path: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save the song to the database
|
||||||
|
let db_con = &mut get_db_conn();
|
||||||
|
let song = song.insert_into(crate::schema::songs::table)
|
||||||
|
.get_result::<Song>(db_con)
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Error saving song to database: {}", e);
|
||||||
|
warn!("{}", msg);
|
||||||
|
ServerFnError::<NoCustomError>::ServerError(msg)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// Save the song's artists to the database
|
||||||
|
let song_id = song.id.ok_or_else(|| {
|
||||||
|
let msg = "Error saving song to database: song id not found after insertion".to_string();
|
||||||
|
warn!("{}", msg);
|
||||||
|
ServerFnError::<NoCustomError>::ServerError(msg)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
use crate::schema::song_artists;
|
||||||
|
use diesel::ExpressionMethods;
|
||||||
|
|
||||||
|
let artist_ids = artist_ids.into_iter().map(|artist_id| {
|
||||||
|
(song_artists::song_id.eq(song_id), song_artists::artist_id.eq(artist_id))
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
diesel::insert_into(crate::schema::song_artists::table)
|
||||||
|
.values(&artist_ids)
|
||||||
|
.execute(db_con)
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Error saving song artists to database: {}", e);
|
||||||
|
warn!("{}", msg);
|
||||||
|
ServerFnError::<NoCustomError>::ServerError(msg)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
37
src/util/audio.rs
Normal file
37
src/util/audio.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use symphonia::core::codecs::CodecType;
|
||||||
|
use symphonia::core::formats::FormatOptions;
|
||||||
|
use symphonia::core::io::MediaSourceStream;
|
||||||
|
use symphonia::core::meta::MetadataOptions;
|
||||||
|
use symphonia::core::probe::Hint;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
/// Extract the codec and duration of an audio file
|
||||||
|
/// This is combined into one function because the file object will be consumed
|
||||||
|
pub fn extract_metadata(file: File) -> Result<(CodecType, u64), Box<dyn std::error::Error>> {
|
||||||
|
let source_stream = MediaSourceStream::new(Box::new(file), Default::default());
|
||||||
|
|
||||||
|
let hint = Hint::new();
|
||||||
|
let format_opts = FormatOptions::default();
|
||||||
|
let metadata_opts = MetadataOptions::default();
|
||||||
|
|
||||||
|
let probe = symphonia::default::get_probe().format(&hint, source_stream, &format_opts, &metadata_opts)?;
|
||||||
|
let reader = probe.format;
|
||||||
|
|
||||||
|
if reader.tracks().len() != 1 {
|
||||||
|
return Err(format!("Expected 1 track, found {}", reader.tracks().len()).into())
|
||||||
|
}
|
||||||
|
|
||||||
|
let track = &reader.tracks()[0];
|
||||||
|
|
||||||
|
let time_base = track.codec_params.time_base.ok_or("Missing time base")?;
|
||||||
|
let duration = track.codec_params.n_frames
|
||||||
|
.map(|frames| track.codec_params.start_ts + frames)
|
||||||
|
.ok_or("Missing number of frames")?;
|
||||||
|
|
||||||
|
let duration = duration
|
||||||
|
.checked_mul(time_base.numer as u64)
|
||||||
|
.and_then(|v| v.checked_div(time_base.denom as u64))
|
||||||
|
.ok_or("Overflow while computing duration")?;
|
||||||
|
|
||||||
|
Ok((track.codec_params.codec, duration))
|
||||||
|
}
|
7
src/util/mod.rs
Normal file
7
src/util/mod.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "ssr")] {
|
||||||
|
pub mod audio;
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@
|
|||||||
@import 'home.scss';
|
@import 'home.scss';
|
||||||
@import 'search.scss';
|
@import 'search.scss';
|
||||||
@import 'personal.scss';
|
@import 'personal.scss';
|
||||||
|
@import 'upload.scss';
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
|
@ -39,15 +39,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.media-info {
|
.playbar-left-group {
|
||||||
font-size: 16;
|
display: flex;
|
||||||
margin-left: 10px;
|
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
display: grid;
|
margin-left: 10px;
|
||||||
grid-template-columns: 50px 1fr;
|
|
||||||
|
|
||||||
.media-info-img {
|
.media-info-img {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
@ -57,6 +54,10 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.like-dislike {
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.playcontrols {
|
.playcontrols {
|
||||||
@ -64,23 +65,6 @@
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
button {
|
|
||||||
.controlbtn {
|
|
||||||
color: $text-controls-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
.controlbtn:hover {
|
|
||||||
color: $controls-hover-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
.controlbtn:active {
|
|
||||||
color: $controls-click-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
background-color: transparent;
|
|
||||||
border: transparent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.playduration {
|
.playduration {
|
||||||
@ -94,22 +78,30 @@
|
|||||||
bottom: 13px;
|
bottom: 13px;
|
||||||
top: 13px;
|
top: 13px;
|
||||||
right: 90px;
|
right: 90px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
.controlbtn {
|
.hmirror {
|
||||||
color: $text-controls-color;
|
-moz-transform: scale(-1, 1);
|
||||||
}
|
-webkit-transform: scale(-1, 1);
|
||||||
|
-o-transform: scale(-1, 1);
|
||||||
.controlbtn:hover {
|
-ms-transform: scale(-1, 1);
|
||||||
color: $controls-hover-color;
|
transform: scale(-1, 1);
|
||||||
}
|
|
||||||
|
|
||||||
.controlbtn:active {
|
|
||||||
color: $controls-click-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
background-color: transparent;
|
|
||||||
border: transparent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.controlbtn {
|
||||||
|
color: $text-controls-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlbtn:hover {
|
||||||
|
color: $controls-hover-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlbtn:active {
|
||||||
|
color: $controls-click-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
background-color: transparent;
|
||||||
|
border: transparent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,56 +4,74 @@
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
width: 22rem;
|
width: 22rem;
|
||||||
height: calc(100% - 75px);
|
height: calc(100% - 75px);
|
||||||
}
|
.sidebar-top-container {
|
||||||
|
border-radius: 1rem;
|
||||||
.sidebar-top-container {
|
background-color: #1c1c1c;
|
||||||
border-radius: 1rem;
|
height: 9rem;
|
||||||
background-color: #1c1c1c;
|
margin: 3px;
|
||||||
height: 9rem;
|
padding: 0.1rem 1rem 1rem 1rem;
|
||||||
margin: 3px;
|
position: relative;
|
||||||
padding: 0.1rem 1rem 1rem 1rem;
|
.header {
|
||||||
}
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
.sidebar-top-container .header {
|
.upload-btn {
|
||||||
font-size: 1.2rem;
|
position: absolute;
|
||||||
}
|
top: 10px;
|
||||||
.sidebar-top-container .buttons {
|
right: 7px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
font-size: 1.8rem;
|
align-items: center;
|
||||||
align-items: center;
|
justify-content: center;
|
||||||
transition: all 0.5s;
|
font-size: 0.9rem;
|
||||||
cursor: pointer;
|
border-radius: 50px;
|
||||||
color: grey;
|
border: none;
|
||||||
}
|
height: 2.2rem;
|
||||||
.sidebar-top-container .buttons:hover {
|
padding-right: 1rem;
|
||||||
color: white;
|
padding-left: 1rem;
|
||||||
}
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
.sidebar-top-container .buttons:last-child {
|
.add-sign {
|
||||||
margin-left: 0.02rem;
|
font-size: 1.5rem;
|
||||||
margin-top: 0.5rem;
|
margin-top: auto;
|
||||||
}
|
margin-right: 5px;
|
||||||
|
color: white;
|
||||||
.sidebar-top-container h1 {
|
}
|
||||||
font-size: 0.95rem;
|
}
|
||||||
margin-left: 0.9rem;
|
.upload-btn:hover {
|
||||||
font-weight: 400;
|
background-color: #9e9e9e;
|
||||||
font-style: $standard-font;
|
}
|
||||||
letter-spacing: 0.5px;
|
.buttons {
|
||||||
}
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
.sidebar-bottom-container {
|
font-size: 1.8rem;
|
||||||
border-radius: 1rem;
|
align-items: center;
|
||||||
background-color: #1c1c1c;
|
transition: all 0.5s;
|
||||||
margin: 3px;
|
cursor: pointer;
|
||||||
margin-top: 6px;
|
color: grey;
|
||||||
padding: 0.2rem 1rem 1rem 1rem;
|
text-decoration: none;
|
||||||
height: calc(100% - 9rem);
|
}
|
||||||
|
.buttons:hover {
|
||||||
.sidebar-playlists-container {
|
color: white;
|
||||||
width: 100%;
|
}
|
||||||
height: 100%;
|
.buttons:last-child {
|
||||||
|
margin-left: 0.02rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
margin-left: 0.9rem;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: $standard-font;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sidebar-bottom-container {
|
||||||
|
border-radius: 1rem;
|
||||||
|
background-color: #1c1c1c;
|
||||||
|
margin: 3px;
|
||||||
|
margin-top: 6px;
|
||||||
|
padding: 0.2rem 1rem 1rem 1rem;
|
||||||
|
height: calc(100% - 9rem);
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -92,252 +110,7 @@
|
|||||||
background-color: #9e9e9e;
|
background-color: #9e9e9e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.create-playlist-popup-container {
|
|
||||||
display: flex;
|
|
||||||
position: relative;
|
|
||||||
flex-direction: column;
|
|
||||||
// background-color: #1c1c1c;
|
|
||||||
height: 12rem;
|
|
||||||
width: 20rem;
|
|
||||||
border-radius: 2px;
|
|
||||||
padding: 1rem;
|
|
||||||
padding-top: 0.1rem;
|
|
||||||
border: 1px solid grey;
|
|
||||||
position: fixed;
|
|
||||||
top: 40%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
.close-button {
|
|
||||||
position: absolute;
|
|
||||||
top: 5px;
|
|
||||||
right: 5px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 50%;
|
|
||||||
font-size: 1.6rem;
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
.close-button:hover {
|
|
||||||
transform: scale(1.1);
|
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-button:active {
|
|
||||||
transform: scale(0.8);
|
|
||||||
}
|
|
||||||
.header {
|
|
||||||
font-size: 1.2rem;
|
|
||||||
font-weight: 200;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
}
|
|
||||||
.create-playlist-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
position: relative;
|
|
||||||
height: 100%;
|
|
||||||
.name-input {
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
border-bottom: 1px solid grey;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
color: white;
|
|
||||||
margin-top: 2rem;
|
|
||||||
}
|
|
||||||
.name-input:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
.create-button {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0px;
|
|
||||||
width: 5rem;
|
|
||||||
padding: 0.4rem;
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.playlists {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
margin-top: 5px;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
.playlist {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
margin-top: 5px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
border: 1px solid grey;
|
|
||||||
height: 3rem;
|
|
||||||
border-radius: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
|
|
||||||
.screen-darkener {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name {
|
|
||||||
font-size: 1rem;
|
|
||||||
margin-left: 1rem;
|
|
||||||
margin-top: 0.5rem;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.playlist-container {
|
|
||||||
background-color: #1c1c1c;
|
|
||||||
width: 40rem;
|
|
||||||
height: 40rem;
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
border: 1px solid white;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 1rem;
|
|
||||||
padding-top: 0;
|
|
||||||
z-index: 2;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
.close-button {
|
|
||||||
position: absolute;
|
|
||||||
top: 5px;
|
|
||||||
right: 5px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 50%;
|
|
||||||
font-size: 1.6rem;
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-button:hover {
|
|
||||||
transform: scale(1.1);
|
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-button:active {
|
|
||||||
transform: scale(0.8);
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 2rem;
|
|
||||||
font-weight: bolder;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
}
|
|
||||||
.info {
|
|
||||||
display:flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: end;
|
|
||||||
h1 {
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 2rem;
|
|
||||||
margin-left: .5rem;
|
|
||||||
margin-right:2rem;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
color: #aaa;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.options {
|
|
||||||
display: flex;
|
|
||||||
button {
|
|
||||||
background-color: white;
|
|
||||||
border: none;
|
|
||||||
color: black;
|
|
||||||
font-size: 1rem;
|
|
||||||
padding: .6rem;
|
|
||||||
border-radius: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
margin-right: 10px;
|
|
||||||
margin-top: 1rem;
|
|
||||||
margin-left: 5px;
|
|
||||||
.button-icons {
|
|
||||||
margin-right: 7px;
|
|
||||||
font-size: 1.3rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.songs {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
margin-top: 2rem;
|
|
||||||
.song {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 7px 10px 7px 10px;
|
|
||||||
border-bottom: 1px solid #ccc; /* Separator line color */
|
|
||||||
|
|
||||||
img {
|
|
||||||
max-width: 40px; /* Adjust maximum width for images */
|
|
||||||
margin-right: 10px; /* Add spacing between image and text */
|
|
||||||
border-radius: 5px; /* Add border radius to image */
|
|
||||||
}
|
|
||||||
.song-info {
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
margin: 0; /* Remove default margin for heading */
|
|
||||||
color: #fff; /* Adjust text color for song */
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 0; /* Remove default margin for paragraph */
|
|
||||||
color: #aaa; /* Adjust text color for artist */
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.right {
|
|
||||||
position: fixed;
|
|
||||||
right: 25px;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
.duration {
|
|
||||||
|
|
||||||
}
|
|
||||||
.delete-song {
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.delete-song:hover {
|
|
||||||
transform: scale(1.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.delete-song:active {
|
|
||||||
transform: scale(0.8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.song:first-child {
|
|
||||||
border-top: 1px solid #ccc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.playlist:hover {
|
|
||||||
background-color: #adadad36;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
188
style/upload.scss
Normal file
188
style/upload.scss
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
@import "theme.scss";
|
||||||
|
|
||||||
|
.upload-container {
|
||||||
|
position: fixed;
|
||||||
|
top: 45%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
width: 30rem;
|
||||||
|
height: 30rem;
|
||||||
|
border: 1px solid white;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 1rem;
|
||||||
|
padding-top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: #1c1c1c;
|
||||||
|
.close-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
right: 5px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 50%;
|
||||||
|
font-size: 1.6rem;
|
||||||
|
transition: all 0.3s;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button:hover {
|
||||||
|
transform: scale(1.1);
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
.close-button:active {
|
||||||
|
transform: scale(0.8);
|
||||||
|
}
|
||||||
|
.upload-header {
|
||||||
|
font-size: .7rem;
|
||||||
|
font-weight: 300;
|
||||||
|
padding-bottom: 0;
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
font-family: "Roboto", sans-serif;
|
||||||
|
}
|
||||||
|
.upload-form {
|
||||||
|
padding: .1rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
.input-bx{
|
||||||
|
margin-top: 1rem;
|
||||||
|
position: relative;
|
||||||
|
width: 300px;
|
||||||
|
input{
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px solid #7f8fa6;
|
||||||
|
border-radius: 5px;
|
||||||
|
outline: none;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: 0.6s;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
span{
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 1px;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #7f8fa6;
|
||||||
|
text-transform: uppercase;
|
||||||
|
pointer-events: none;
|
||||||
|
transition: 0.6s;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
input:valid ~ span,
|
||||||
|
input:focus ~ span{
|
||||||
|
color: #fff;
|
||||||
|
transform: translateX(10px) translateY(-7px);
|
||||||
|
font-size: 0.65rem;
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 0 10px;
|
||||||
|
background: #1c1c1c;
|
||||||
|
letter-spacing: 0.1rem;
|
||||||
|
}
|
||||||
|
input:valid,
|
||||||
|
input:focus{
|
||||||
|
color: #fff;
|
||||||
|
border: 2px solid #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.release-date {
|
||||||
|
margin-top: 1rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: #7f8fa6;
|
||||||
|
font-family: "Roboto", sans-serif;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
.left {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-left: 5px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
span {
|
||||||
|
font-size: .85rem;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.file {
|
||||||
|
margin-top: .5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
span {
|
||||||
|
font-size: .9rem;
|
||||||
|
color: #7f8fa6;
|
||||||
|
font-family: "Roboto", sans-serif;
|
||||||
|
margin-left: 5px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.upload-button {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #7f8fa6;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-family: "Roboto", sans-serif;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: 0.3s;
|
||||||
|
&:hover {
|
||||||
|
background-color: #fff;
|
||||||
|
color: #7f8fa6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.has-search {
|
||||||
|
position: relative;
|
||||||
|
width: 325px;
|
||||||
|
.search-results {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
border: 1px solid white;
|
||||||
|
width: 100%;
|
||||||
|
position: absolute;
|
||||||
|
top: 75%;
|
||||||
|
background-color: #1c1c1c;
|
||||||
|
z-index: 2;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 0;
|
||||||
|
.result {
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
padding: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: 0.3s;
|
||||||
|
&:hover {
|
||||||
|
background-color: #7f8fa6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.result:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-msg {
|
||||||
|
padding-top: 10px;
|
||||||
|
color: red;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user