Compare commits
10 Commits
v0.2.4-dev
...
ee8ef9033c
Author | SHA1 | Date | |
---|---|---|---|
ee8ef9033c
|
|||
2b38cafd0b
|
|||
b70a121a4e
|
|||
bd01dac544 | |||
f748d93b3f | |||
80762b81ae | |||
af4f1acb87 | |||
d5e24f9114 | |||
83eafd0005 | |||
e3895b6d1a |
18
.dockerignore.yaml
Normal file
18
.dockerignore.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
# Ignore build artifacts
|
||||
target/
|
||||
pkg/
|
||||
|
||||
# Ignore git directory
|
||||
.git/
|
||||
|
||||
.gitea/
|
||||
|
||||
# Ignore environment files (configure via docker-compose instead)
|
||||
.env*
|
||||
|
||||
# Ignore IDE/editor specific files
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Ignore OS specific files
|
||||
*.DS_Store
|
@@ -1,2 +1,4 @@
|
||||
ROOT_DIRECTORY=/home/songparser/mydata
|
||||
ICARUS_BASE_API_URL=http://localhost:3000
|
||||
ROOT_DIRECTORY=/usr/local/bin
|
||||
ICARUS_BASE_API_URL=http://api:3000
|
||||
ICARUS_AUTH_BASE_API_URL=http://auth_api:3000
|
||||
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||
|
@@ -1,2 +1,4 @@
|
||||
ROOT_DIRECTORY=/home/songparser/mydata
|
||||
ICARUS_BASE_API_URL=http://localhost:3000
|
||||
ICARUS_AUTH_BASE_API_URL=http://localhost:3001
|
||||
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||
|
@@ -3,7 +3,6 @@ name: Release Tagging
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- devel
|
||||
|
||||
jobs:
|
||||
@@ -50,6 +49,3 @@ jobs:
|
||||
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
||||
body: |
|
||||
Release of version ${{ steps.version.outputs.project_tag_release }}
|
||||
# draft: false
|
||||
# prerelease: ${{ startsWith(github.ref, 'v') == false }} # prerelease if not a valid release tag
|
||||
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
/target
|
||||
.env
|
||||
.env.local
|
||||
.env.docker
|
||||
|
121
Cargo.lock
generated
121
Cargo.lock
generated
@@ -17,6 +17,21 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
@@ -501,8 +516,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "icarus_envy"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.0-devel-d73fba9899-006#d73fba9899372b0655a90cb426645930135152da"
|
||||
version = "0.3.2"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
@@ -511,20 +526,22 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "icarus_meta"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0-devel-f4b71de969-680#f4b71de9692029a706b1ce82c39f6715c560158e"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0#f87c049ab3139995230485b33038a0425f2e7430"
|
||||
dependencies = [
|
||||
"lofty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icarus_models"
|
||||
version = "0.4.5"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166"
|
||||
version = "0.5.6"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.6#2d6b550ae6721b41ecc3039799f6a5e873869077"
|
||||
dependencies = [
|
||||
"josekit",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"time",
|
||||
"utoipa",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
@@ -643,6 +660,7 @@ checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -667,6 +685,23 @@ version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "josekit"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a808e078330e6af222eb0044b71d4b1ff981bfef43e7bc8133a88234e0c86a0c"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
"flate2",
|
||||
"openssl",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.77"
|
||||
@@ -1009,6 +1044,35 @@ dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.20"
|
||||
@@ -1195,6 +1259,7 @@ version = "1.0.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
@@ -1255,7 +1320,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "songparser"
|
||||
version = "0.2.4"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"icarus_envy",
|
||||
@@ -1347,6 +1412,26 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.41"
|
||||
@@ -1561,6 +1646,30 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "utoipa"
|
||||
version = "5.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"utoipa-gen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utoipa-gen"
|
||||
version = "5.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.17.0"
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "songparser"
|
||||
version = "0.2.4"
|
||||
version = "0.3.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.88"
|
||||
|
||||
@@ -13,6 +13,6 @@ serde_json = { version = "1.0.140" }
|
||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||
rand = { version = "0.9.1" }
|
||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0-devel-f4b71de969-680" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.5-devel-655d05dabb-111" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.0-devel-d73fba9899-006" }
|
||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" }
|
||||
|
63
Dockerfile
Normal file
63
Dockerfile
Normal file
@@ -0,0 +1,63 @@
|
||||
# Stage 1: Build the application
|
||||
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
||||
# Using slim variant for smaller base image
|
||||
FROM rust:1.88 as builder
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install build dependencies if needed (e.g., git for cloning)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
pkg-config libssl3 \
|
||||
ca-certificates \
|
||||
openssh-client git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# << --- ADD HOST KEY HERE --- >>
|
||||
# Replace 'yourgithost.com' with the actual hostname (e.g., github.com)
|
||||
RUN mkdir -p -m 0700 ~/.ssh && \
|
||||
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
||||
|
||||
# Copy Cargo manifests
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
|
||||
# Build *only* dependencies to leverage Docker cache
|
||||
# This dummy build caches dependencies as a separate layer
|
||||
RUN --mount=type=ssh mkdir src && \
|
||||
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
|
||||
cargo build --release --quiet && \
|
||||
rm -rf src target/release/deps/songparser* # Clean up dummy build artifacts (replace songparser)
|
||||
|
||||
# Copy the actual source code
|
||||
COPY src ./src
|
||||
# If you have other directories like `templates` or `static`, copy them too
|
||||
COPY .env ./.env
|
||||
|
||||
# << --- SSH MOUNT ADDED HERE --- >>
|
||||
# Build *only* dependencies to leverage Docker cache
|
||||
# This dummy build caches dependencies as a separate layer
|
||||
# Mount the SSH agent socket for this command
|
||||
RUN --mount=type=ssh \
|
||||
cargo build --release --quiet
|
||||
|
||||
# Stage 2: Create the final, smaller runtime image
|
||||
# Use a minimal base image like debian-slim or even distroless for security/size
|
||||
FROM ubuntu:24.04
|
||||
|
||||
# Install runtime dependencies if needed (e.g., SSL certificates)
|
||||
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /usr/local/bin
|
||||
|
||||
# Copy the compiled binary from the builder stage
|
||||
# Replace 'songparser' with the actual name of your binary (usually the crate name)
|
||||
COPY --from=builder /usr/src/app/target/release/songparser .
|
||||
|
||||
# Copy other necessary files like .env (if used for runtime config) or static assets
|
||||
# It's generally better to configure via environment variables in Docker though
|
||||
COPY --from=builder /usr/src/app/.env .
|
||||
|
||||
# Set the command to run your application
|
||||
# Ensure this matches the binary name copied above
|
||||
CMD ["./songparser"]
|
99
README.md
99
README.md
@@ -1,93 +1,20 @@
|
||||
# Songparser
|
||||
|
||||
A service that edits the metadata of a queued song and populates it with data.
|
||||
|
||||
|
||||
## Getting started
|
||||
This service can run as a regular service or a docker image. The easiest way to get quickly
|
||||
started is to run it with docker. Copy `.env.docker.sample` as `.env`. Ensure that
|
||||
`ROOT_DIRECTORY` is pointing to a directory that exists, not for the local filesystem, but
|
||||
for the filesystem on the docker image. The current directory that is listed will work, but
|
||||
it can be changed.
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
The `SERVICE_PASSPHRASE` env variable should not be changed, but it could be changed. The
|
||||
value for this variable should match the value in the `passphrase` table. This would be
|
||||
found in the `icarus_auth` project.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
Ensure that the URLs for the two APIs are correctly set for the respective env variables
|
||||
`ICARUS_BASE_API_URL` for Icarus API and `ICARUS_AUTH_BASE_API_URL` for `icarus_auth`.
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.com/kdeng00/songparser.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.com/kdeng00/songparser/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
If the values are properly set, next is to build the image. The docker image should be
|
||||
built from the main icarus web API.
|
||||
|
12
docker-compose.yaml
Normal file
12
docker-compose.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
version: '3.8' # Use a recent version
|
||||
|
||||
services:
|
||||
# Your Rust Application Service
|
||||
songparser:
|
||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
||||
context: .
|
||||
ssh: ["default"] # Uses host's SSH agent
|
||||
container_name: songparser # Optional: Give the container a specific name
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped # Optional: Restart policy
|
64
src/api.rs
64
src/api.rs
@@ -1,8 +1,20 @@
|
||||
pub async fn fetch_next_queue_item(base_url: &String) -> Result<reqwest::Response, reqwest::Error> {
|
||||
pub async fn fetch_next_queue_item(
|
||||
app: &crate::config::App,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||
let api_url = format!("{base_url}/{fetch_endpoint}");
|
||||
client.get(api_url).send().await
|
||||
let api_url = format!("{}/{fetch_endpoint}", app.uri);
|
||||
let (key, header) = auth_header(app).await;
|
||||
|
||||
client.get(api_url).header(key, header).send().await
|
||||
}
|
||||
|
||||
pub async fn auth_header(
|
||||
app: &crate::config::App,
|
||||
) -> (reqwest::header::HeaderName, reqwest::header::HeaderValue) {
|
||||
let bearer = format!("Bearer {}", app.token.token);
|
||||
let header_value = reqwest::header::HeaderValue::from_str(&bearer).unwrap();
|
||||
(reqwest::header::AUTHORIZATION, header_value)
|
||||
}
|
||||
|
||||
pub mod parsing {
|
||||
@@ -27,27 +39,30 @@ pub mod parsing {
|
||||
|
||||
pub mod fetch_song_queue_data {
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}/{id}");
|
||||
client.get(api_url).send().await
|
||||
let api_url = format!("{}/{endpoint}/{id}", app.uri);
|
||||
let (key, header) = super::auth_header(app).await;
|
||||
client.get(api_url).header(key, header).send().await
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_metadata_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/metadata/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
let api_url = format!("{}/{endpoint}", app.uri);
|
||||
let (key, header) = super::auth_header(app).await;
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.header(key, header)
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
@@ -90,27 +105,30 @@ pub mod get_metadata_queue {
|
||||
|
||||
pub mod get_coverart_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
let api_url = format!("{}/{endpoint}", app.uri);
|
||||
let (key, header) = super::auth_header(app).await;
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.header(key, header)
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue/data");
|
||||
let api_url = format!("{base_url}/{endpoint}/{coverart_queue_id}");
|
||||
client.get(api_url).send().await
|
||||
let api_url = format!("{}/{endpoint}/{coverart_queue_id}", app.uri);
|
||||
let (key, header) = super::auth_header(app).await;
|
||||
client.get(api_url).header(key, header).send().await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
@@ -129,3 +147,23 @@ pub mod get_coverart_queue {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod service_token {
|
||||
pub mod response {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod refresh_token {
|
||||
pub mod response {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
src/config.rs
Normal file
6
src/config.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
#[derive(Default, Debug)]
|
||||
pub struct App {
|
||||
pub uri: String,
|
||||
pub auth_uri: String,
|
||||
pub token: icarus_models::login_result::LoginResult,
|
||||
}
|
184
src/main.rs
184
src/main.rs
@@ -1,4 +1,5 @@
|
||||
pub mod api;
|
||||
pub mod config;
|
||||
pub mod responses;
|
||||
pub mod the_rest;
|
||||
pub mod update_queued_song;
|
||||
@@ -10,34 +11,62 @@ pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let app_base_url = icarus_envy::environment::get_icarus_base_api_url().await;
|
||||
let mut app = config::App {
|
||||
uri: icarus_envy::environment::get_icarus_base_api_url().await,
|
||||
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url().await,
|
||||
..Default::default()
|
||||
};
|
||||
println!("Base URL: {:?}", app.uri);
|
||||
println!("Auth URL: {:?}", app.auth_uri);
|
||||
|
||||
match auth::get_token(&app).await {
|
||||
Ok(login_result) => {
|
||||
app.token = login_result;
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
std::process::exit(-1);
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
println!("Base URL: {app_base_url}");
|
||||
println!("Token: {:?}", app.token);
|
||||
|
||||
match is_queue_empty(&app_base_url).await {
|
||||
if auth::did_token_expire(&app.token).await {
|
||||
println!("Token expired");
|
||||
app.token = match auth::get_refresh_token(&app).await {
|
||||
Ok(login_result) => login_result,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
println!("Token refreshed");
|
||||
println!("Refreshed token: {:?}", app.token);
|
||||
} else {
|
||||
println!("Token did not expire");
|
||||
}
|
||||
|
||||
match is_queue_empty(&app).await {
|
||||
Ok((empty, song_queue_item)) => {
|
||||
if !empty {
|
||||
println!("Queue is not empty");
|
||||
println!("SongQueueItem: {song_queue_item:?}");
|
||||
|
||||
let song_queue_id = song_queue_item.data[0].id;
|
||||
let user_id = song_queue_item.data[0].user_id;
|
||||
|
||||
// TODO: Do something with the result later
|
||||
match some_work(&app_base_url, &song_queue_id, &user_id).await {
|
||||
match some_work(&app, &song_queue_id, &user_id).await {
|
||||
Ok((
|
||||
_song,
|
||||
_coverart,
|
||||
(song_queue_id, song_queue_path),
|
||||
(coverart_queue_id, coverart_queue_path),
|
||||
)) => {
|
||||
// TODO: Wipe data from song and coverart queues
|
||||
match wipe_data_from_queues(
|
||||
&app_base_url,
|
||||
&song_queue_id,
|
||||
&coverart_queue_id,
|
||||
)
|
||||
.await
|
||||
match wipe_data_from_queues(&app, &song_queue_id, &coverart_queue_id)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
match cleanup(&song_queue_path, &coverart_queue_path).await {
|
||||
@@ -72,35 +101,100 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
mod auth {
|
||||
pub async fn get_token(
|
||||
app: &crate::config::App,
|
||||
) -> Result<icarus_models::login_result::LoginResult, std::io::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/service/login");
|
||||
let api_url = format!("{}/{endpoint}", app.auth_uri);
|
||||
|
||||
let payload = serde_json::json!({
|
||||
"passphrase": icarus_envy::environment::get_service_passphrase().await,
|
||||
});
|
||||
|
||||
match client.post(api_url).json(&payload).send().await {
|
||||
Ok(response) => match response
|
||||
.json::<crate::api::service_token::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(resp) => {
|
||||
if resp.data.is_empty() {
|
||||
Err(std::io::Error::other(String::from("No token returned")))
|
||||
} else {
|
||||
Ok(resp.data[0].clone())
|
||||
}
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Might want to put the functionality within icarus_models at some point
|
||||
pub async fn did_token_expire(login_result: &icarus_models::login_result::LoginResult) -> bool {
|
||||
let current_time = time::OffsetDateTime::now_utc();
|
||||
let expire_time =
|
||||
time::OffsetDateTime::from_unix_timestamp(login_result.expiration).unwrap();
|
||||
current_time > expire_time
|
||||
}
|
||||
|
||||
pub async fn get_refresh_token(
|
||||
app: &crate::config::App,
|
||||
) -> Result<icarus_models::login_result::LoginResult, std::io::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/token/refresh");
|
||||
let api_url = format!("{}/{endpoint}", app.auth_uri);
|
||||
|
||||
let payload = serde_json::json!({
|
||||
"access_token": app.token.token
|
||||
});
|
||||
|
||||
match client.post(api_url).json(&payload).send().await {
|
||||
Ok(response) => match response
|
||||
.json::<crate::api::refresh_token::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(resp) => {
|
||||
if resp.data.is_empty() {
|
||||
Err(std::io::Error::other(String::from("No token returned")))
|
||||
} else {
|
||||
Ok(resp.data[0].clone())
|
||||
}
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn wipe_data_from_queues(
|
||||
app_base_url: &String,
|
||||
app: &config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
|
||||
match the_rest::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
|
||||
Ok(response) => match response
|
||||
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
|
||||
app_base_url,
|
||||
coverart_queue_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(inner_response) => match inner_response
|
||||
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_inner_resp) => {
|
||||
println!("Wiped data from CoverArt queue");
|
||||
println!("Resp: {_inner_resp:?}");
|
||||
Ok(())
|
||||
}
|
||||
Ok(_resp) => {
|
||||
match the_rest::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
|
||||
Ok(inner_response) => match inner_response
|
||||
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_inner_resp) => {
|
||||
println!("Wiped data from CoverArt queue");
|
||||
println!("Resp: {_inner_resp:?}");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
@@ -125,9 +219,9 @@ async fn cleanup(
|
||||
}
|
||||
|
||||
async fn is_queue_empty(
|
||||
api_url: &String,
|
||||
app: &config::App,
|
||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||
match api::fetch_next_queue_item(api_url).await {
|
||||
match api::fetch_next_queue_item(app).await {
|
||||
Ok(response) => {
|
||||
match response
|
||||
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||
@@ -148,7 +242,7 @@ async fn is_queue_empty(
|
||||
}
|
||||
|
||||
async fn some_work(
|
||||
app_base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> Result<
|
||||
@@ -160,12 +254,12 @@ async fn some_work(
|
||||
),
|
||||
std::io::Error,
|
||||
> {
|
||||
match prep_song(app_base_url, song_queue_id).await {
|
||||
match prep_song(app, song_queue_id).await {
|
||||
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
|
||||
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||
Ok(_applied) => {
|
||||
match update_queued_song::update_queued_song(
|
||||
app_base_url,
|
||||
app,
|
||||
&song_queue_path,
|
||||
song_queue_id,
|
||||
)
|
||||
@@ -183,10 +277,7 @@ async fn some_work(
|
||||
let song_type = String::from("flac");
|
||||
|
||||
match the_rest::create_song::create(
|
||||
app_base_url,
|
||||
&metadata,
|
||||
user_id,
|
||||
&song_type,
|
||||
app, &metadata, user_id, &song_type,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -198,7 +289,7 @@ async fn some_work(
|
||||
println!("Response: {resp:?}");
|
||||
|
||||
let song = &resp.data[0];
|
||||
match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await {
|
||||
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await {
|
||||
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
||||
Ok(resp) => {
|
||||
println!("CoverArt sent and successfully parsed response");
|
||||
@@ -234,7 +325,7 @@ async fn some_work(
|
||||
}
|
||||
|
||||
async fn prep_song(
|
||||
api_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<
|
||||
(
|
||||
@@ -245,7 +336,7 @@ async fn prep_song(
|
||||
),
|
||||
reqwest::Error,
|
||||
> {
|
||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
||||
match api::fetch_song_queue_data::get_data(app, song_queue_id).await {
|
||||
Ok(response) => {
|
||||
// Process data here...
|
||||
match api::parsing::parse_response_into_bytes(response).await {
|
||||
@@ -255,7 +346,7 @@ async fn prep_song(
|
||||
|
||||
println!("Saved at: {song_queue_path:?}");
|
||||
|
||||
match api::get_metadata_queue::get(api_url, song_queue_id).await {
|
||||
match api::get_metadata_queue::get(app, song_queue_id).await {
|
||||
Ok(response) => {
|
||||
match response
|
||||
.json::<api::get_metadata_queue::response::Response>()
|
||||
@@ -270,15 +361,14 @@ async fn prep_song(
|
||||
println!("Created at: {created_at:?}");
|
||||
|
||||
println!("Getting coverart queue");
|
||||
match api::get_coverart_queue::get(api_url, song_queue_id).await
|
||||
{
|
||||
match api::get_coverart_queue::get(app, song_queue_id).await {
|
||||
Ok(response) => {
|
||||
match response.json::<api::get_coverart_queue::response::Response>().await {
|
||||
Ok(response) => {
|
||||
let coverart_queue_id = &response.data[0].id;
|
||||
println!("Coverart queue Id: {coverart_queue_id:?}");
|
||||
|
||||
match api::get_coverart_queue::get_data(api_url, coverart_queue_id).await {
|
||||
match api::get_coverart_queue::get_data(app, coverart_queue_id).await {
|
||||
Ok(response) => match api::parsing::parse_response_into_bytes(response).await {
|
||||
Ok(coverart_queue_bytes) => {
|
||||
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
pub mod create_song {
|
||||
pub async fn create(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
|
||||
user_id: &uuid::Uuid,
|
||||
song_type: &String,
|
||||
@@ -28,9 +28,10 @@ pub mod create_song {
|
||||
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
|
||||
let url = format!("{base_url}/api/v2/song");
|
||||
let url = format!("{}/api/v2/song", app.uri);
|
||||
let (key, header) = crate::api::auth_header(app).await;
|
||||
|
||||
let request = client.post(url).json(&payload);
|
||||
let request = client.post(url).json(&payload).header(key, header);
|
||||
request.send().await
|
||||
}
|
||||
|
||||
@@ -46,14 +47,15 @@ pub mod create_song {
|
||||
pub mod create_coverart {
|
||||
|
||||
pub async fn create(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/coverart");
|
||||
let url = format!("{}/api/v2/coverart", app.uri);
|
||||
let payload = get_payload(song_id, coverart_queue_id);
|
||||
let request = client.post(url).json(&payload);
|
||||
let (key, header) = crate::api::auth_header(app).await;
|
||||
let request = client.post(url).json(&payload).header(key, header);
|
||||
|
||||
request.send().await
|
||||
}
|
||||
@@ -77,15 +79,16 @@ pub mod create_coverart {
|
||||
pub mod wipe_data {
|
||||
pub mod song_queue {
|
||||
pub async fn wipe_data(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
|
||||
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
|
||||
let payload = serde_json::json!({
|
||||
"song_queue_id": song_queue_id
|
||||
});
|
||||
let request = client.patch(url).json(&payload);
|
||||
let (key, header) = crate::api::auth_header(app).await;
|
||||
let request = client.patch(url).json(&payload).header(key, header);
|
||||
|
||||
request.send().await
|
||||
}
|
||||
@@ -98,18 +101,18 @@ pub mod wipe_data {
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Wipe data from queued coverart
|
||||
pub mod coverart_queue {
|
||||
pub async fn wipe_data(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
|
||||
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
|
||||
let payload = serde_json::json!({
|
||||
"coverart_queue_id": coverart_queue_id
|
||||
});
|
||||
let request = client.patch(url).json(&payload);
|
||||
let (key, header) = crate::api::auth_header(app).await;
|
||||
let request = client.patch(url).json(&payload).header(key, header);
|
||||
|
||||
request.send().await
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
pub async fn update_queued_song(
|
||||
base_url: &String,
|
||||
app: &crate::config::App,
|
||||
song_path: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
@@ -14,10 +14,11 @@ pub async fn update_queued_song(
|
||||
.file_name("track01.flac"),
|
||||
);
|
||||
|
||||
let url = format!("{base_url}/api/v2/song/queue/{song_queue_id}");
|
||||
let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri);
|
||||
println!("Url: {url:?}");
|
||||
|
||||
let request = client.patch(url).multipart(form);
|
||||
let (key, header) = crate::api::auth_header(app).await;
|
||||
let request = client.patch(url).multipart(form).header(key, header);
|
||||
|
||||
let response = request.send().await?;
|
||||
|
||||
|
Reference in New Issue
Block a user