Compare commits
5
Commits
main
...
884753b996
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
884753b996
|
||
|
|
e211b09422
|
||
|
|
2d9ee031b6
|
||
|
|
38ceebc451
|
||
|
|
2afce82682
|
+3
-3
@@ -4,9 +4,9 @@ FRONTEND_URL=http://localhost:4200
|
|||||||
RUST_LOG=debug
|
RUST_LOG=debug
|
||||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||||
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
||||||
ROOT_DIRECTORY=/home/icarus/mydata
|
ROOT_DIRECTORY=/home/soaricarus/mydata
|
||||||
POSTGRES_MAIN_USER=icarus
|
POSTGRES_MAIN_USER=soaricarus
|
||||||
POSTGRES_MAIN_PASSWORD=password
|
POSTGRES_MAIN_PASSWORD=password
|
||||||
POSTGRES_MAIN_DB=icarus_db
|
POSTGRES_MAIN_DB=soaricarus_db
|
||||||
POSTGRES_MAIN_HOST=main_db
|
POSTGRES_MAIN_HOST=main_db
|
||||||
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
||||||
|
|||||||
+3
-3
@@ -4,9 +4,9 @@ FRONTEND_URL=http://localhost:4200
|
|||||||
RUST_LOG=debug
|
RUST_LOG=debug
|
||||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||||
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
||||||
ROOT_DIRECTORY=/home/icarus/mydata
|
ROOT_DIRECTORY=/home/soaricarus/mydata
|
||||||
POSTGRES_MAIN_USER=icarus
|
POSTGRES_MAIN_USER=soaricarus
|
||||||
POSTGRES_MAIN_PASSWORD=password
|
POSTGRES_MAIN_PASSWORD=password
|
||||||
POSTGRES_MAIN_DB=icarus_db
|
POSTGRES_MAIN_DB=soaricarus_db
|
||||||
POSTGRES_MAIN_HOST=main_db
|
POSTGRES_MAIN_HOST=main_db
|
||||||
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ jobs:
|
|||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
|
|
||||||
cargo check
|
cargo check
|
||||||
|
|
||||||
@@ -75,12 +75,12 @@ jobs:
|
|||||||
ROOT_DIRECTORY: "/tmp"
|
ROOT_DIRECTORY: "/tmp"
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
|
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
@@ -96,12 +96,12 @@ jobs:
|
|||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
@@ -116,12 +116,12 @@ jobs:
|
|||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo clippy -- -D warnings
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@@ -135,10 +135,10 @@ jobs:
|
|||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|||||||
Generated
+56
-56
@@ -1038,46 +1038,6 @@ dependencies = [
|
|||||||
"tower-service",
|
"tower-service",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icarus"
|
|
||||||
version = "0.5.2"
|
|
||||||
dependencies = [
|
|
||||||
"axum",
|
|
||||||
"axum-extra",
|
|
||||||
"common-multipart-rfc7578",
|
|
||||||
"futures",
|
|
||||||
"icarus_envy",
|
|
||||||
"icarus_meta",
|
|
||||||
"icarus_models",
|
|
||||||
"josekit",
|
|
||||||
"jsonwebtoken",
|
|
||||||
"mime_guess",
|
|
||||||
"openssl",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sqlx",
|
|
||||||
"tempfile",
|
|
||||||
"time",
|
|
||||||
"tokio",
|
|
||||||
"tokio-util",
|
|
||||||
"tower",
|
|
||||||
"tower-http",
|
|
||||||
"tracing-subscriber",
|
|
||||||
"url",
|
|
||||||
"utoipa",
|
|
||||||
"utoipa-swagger-ui",
|
|
||||||
"uuid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icarus_envy"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.8.0#349056db6e6254c2eb778fdcdd1d64de339f1309"
|
|
||||||
dependencies = [
|
|
||||||
"const_format",
|
|
||||||
"dotenvy",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@@ -1089,20 +1049,6 @@ dependencies = [
|
|||||||
"rand 0.10.2",
|
"rand 0.10.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icarus_models"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.11.3#859b0fb1b377370d8171e22e59893d86e41b258b"
|
|
||||||
dependencies = [
|
|
||||||
"josekit",
|
|
||||||
"rand 0.10.2",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"time",
|
|
||||||
"utoipa",
|
|
||||||
"uuid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icu_collections"
|
name = "icu_collections"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@@ -2160,6 +2106,15 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sienvy"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.0-main-d06c8fdf49-006#d06c8fdf49920cf4d8ba0487c20f5bdc851c36de"
|
||||||
|
dependencies = [
|
||||||
|
"const_format",
|
||||||
|
"dotenvy",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.8"
|
version = "1.4.8"
|
||||||
@@ -2186,6 +2141,20 @@ version = "0.3.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simodels"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.3-main-fe9d101bd0-111#fe9d101bd019f91fe8c99c29721ccb0e6e90c92c"
|
||||||
|
dependencies = [
|
||||||
|
"josekit",
|
||||||
|
"rand 0.10.2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"time",
|
||||||
|
"utoipa",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simple_asn1"
|
name = "simple_asn1"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
@@ -2213,6 +2182,37 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "soaricarus"
|
||||||
|
version = "0.5.2"
|
||||||
|
dependencies = [
|
||||||
|
"axum",
|
||||||
|
"axum-extra",
|
||||||
|
"common-multipart-rfc7578",
|
||||||
|
"futures",
|
||||||
|
"icarus_meta",
|
||||||
|
"josekit",
|
||||||
|
"jsonwebtoken",
|
||||||
|
"mime_guess",
|
||||||
|
"openssl",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sienvy",
|
||||||
|
"simodels",
|
||||||
|
"sqlx",
|
||||||
|
"tempfile",
|
||||||
|
"time",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
|
"tower",
|
||||||
|
"tower-http",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"url",
|
||||||
|
"utoipa",
|
||||||
|
"utoipa-swagger-ui",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
@@ -2857,9 +2857,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.23.4"
|
version = "1.24.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53"
|
checksum = "bf3923a6f5c4c6382e0b653c4117f48d631ea17f38ed86e2a828e6f7412f5239"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.4.3",
|
"getrandom 0.4.3",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "soaricarus"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
@@ -17,7 +17,7 @@ tower-http = { version = "0.7.0", features = ["cors", "timeout"] }
|
|||||||
tracing-subscriber = "0.3.23"
|
tracing-subscriber = "0.3.23"
|
||||||
futures = { version = "0.3.32" }
|
futures = { version = "0.3.32" }
|
||||||
mime_guess = { version = "2.0.5" }
|
mime_guess = { version = "2.0.5" }
|
||||||
uuid = { version = "1.23.4", features = ["v4", "serde"] }
|
uuid = { version = "1.23.5", features = ["v4", "serde"] }
|
||||||
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
||||||
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
|
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
|
||||||
@@ -25,8 +25,8 @@ josekit = { version = "0.10.3" }
|
|||||||
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.6.1" }
|
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.6.1" }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.11.3" }
|
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.8.0" }
|
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
common-multipart-rfc7578 = { version = "0.7.0" }
|
common-multipart-rfc7578 = { version = "0.7.0" }
|
||||||
|
|||||||
+3
-21
@@ -1,4 +1,3 @@
|
|||||||
# Stage 1: Build the application
|
|
||||||
FROM rust:1.95 as builder
|
FROM rust:1.95 as builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
@@ -17,34 +16,24 @@ RUN mkdir -p -m 0700 ~/.ssh && \
|
|||||||
echo " User git" >> ~/.ssh/config && \
|
echo " User git" >> ~/.ssh/config && \
|
||||||
chmod 600 ~/.ssh/config
|
chmod 600 ~/.ssh/config
|
||||||
|
|
||||||
# << --- ADD HOST KEY HERE --- >>
|
|
||||||
RUN ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
RUN ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
# Copy Cargo manifests
|
# Copy Cargo manifests
|
||||||
COPY Cargo.toml Cargo.lock ./
|
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 && \
|
RUN --mount=type=ssh mkdir src && \
|
||||||
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
|
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
|
||||||
cargo build --release --quiet && \
|
cargo build --release --quiet && \
|
||||||
rm -rf src target/release/deps/icarus* # Clean up dummy build artifacts (replace icarus)
|
rm -rf src target/release/deps/soaricarus_api*
|
||||||
|
|
||||||
# Copy the actual source code
|
# Copy the actual source code
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
# If you have other directories like `templates` or `static`, copy them too
|
|
||||||
COPY .env ./.env
|
COPY .env ./.env
|
||||||
COPY migrations ./migrations
|
COPY migrations ./migrations
|
||||||
|
|
||||||
# << --- 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 \
|
RUN --mount=type=ssh \
|
||||||
cargo build --release --quiet
|
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 debian:trixie-slim
|
FROM debian:trixie-slim
|
||||||
|
|
||||||
# Install runtime dependencies if needed (e.g., SSL certificates)
|
# Install runtime dependencies if needed (e.g., SSL certificates)
|
||||||
@@ -53,18 +42,11 @@ RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && r
|
|||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /usr/local/bin
|
WORKDIR /usr/local/bin
|
||||||
|
|
||||||
# Copy the compiled binary from the builder stage
|
COPY --from=builder /usr/src/app/target/release/soaricarus_api .
|
||||||
# Replace 'icarus' with the actual name of your binary (usually the crate name)
|
|
||||||
COPY --from=builder /usr/src/app/target/release/icarus .
|
|
||||||
|
|
||||||
# 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 .
|
COPY --from=builder /usr/src/app/.env .
|
||||||
COPY --from=builder /usr/src/app/migrations ./migrations
|
COPY --from=builder /usr/src/app/migrations ./migrations
|
||||||
|
|
||||||
# Expose the port your Axum app listens on (e.g., 3000 or 8000)
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Set the command to run your application
|
CMD ["./soaricarus_api"]
|
||||||
# Ensure this matches the binary name copied above
|
|
||||||
CMD ["./icarus"]
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
# Icarus
|
# soaricarus_api
|
||||||
Web API for the Icarus project.
|
Core web API for the soaricarus project.
|
||||||
|
|
||||||
|
|
||||||
### Requires
|
### Requires
|
||||||
`icarus_auth` v0.8.x
|
`soaricarus_auth` v0.8.x
|
||||||
`songparser` v0.6.x
|
`songparser` v0.6.x
|
||||||
|
|
||||||
### Compatible with
|
### Compatible with
|
||||||
`icarus-dm` v0.9.x
|
`soaricarus-dm` v0.9.x
|
||||||
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
Quickest way to get started is with docker. Make sure `icarus_auth` and `songparser` repositories
|
Quickest way to get started is with docker. Make sure `soaricarus_auth` and `songparser` repositories
|
||||||
are located in the root of the parent directory. Check the respective repositories to ensure they
|
are located in the root of the parent directory. Check the respective repositories to ensure they
|
||||||
are setup correctly before configuring `Icarus`.
|
are setup correctly before configuring `soaricarus_api`.
|
||||||
|
|
||||||
Copy the `.env.docker.sample` file to `.env`. Ensure that the `ROOT_DIRECTORY` variable is populated
|
Copy the `.env.docker.sample` file to `.env`. Ensure that the `ROOT_DIRECTORY` variable is populated
|
||||||
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
|
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
|
||||||
|
|||||||
+11
-11
@@ -21,7 +21,7 @@ services:
|
|||||||
# --- Web API auth ---
|
# --- Web API auth ---
|
||||||
auth_api:
|
auth_api:
|
||||||
build:
|
build:
|
||||||
context: ../icarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
context: ../soaricarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
||||||
ssh: ["default"]
|
ssh: ["default"]
|
||||||
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
||||||
container_name: auth_api
|
container_name: auth_api
|
||||||
@@ -29,12 +29,12 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "8001:8001"
|
- "8001:8001"
|
||||||
env_file:
|
env_file:
|
||||||
- ../icarus_auth/.env
|
- ../soaricarus_auth/.env
|
||||||
depends_on:
|
depends_on:
|
||||||
auth_db:
|
auth_db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- soaricarus-network
|
||||||
# Optional: Mount local code for development (live reload)
|
# Optional: Mount local code for development (live reload)
|
||||||
# volumes:
|
# volumes:
|
||||||
# - ./path/to/your/web-api-repo:/app
|
# - ./path/to/your/web-api-repo:/app
|
||||||
@@ -55,13 +55,13 @@ services:
|
|||||||
- auth_api
|
- auth_api
|
||||||
- auth_db
|
- auth_db
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- soaricarus-network
|
||||||
|
|
||||||
|
|
||||||
# PostgreSQL Database Service
|
# PostgreSQL Database Service
|
||||||
main_db:
|
main_db:
|
||||||
image: postgres:18.4-alpine
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_db
|
container_name: soaricarus_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
||||||
@@ -81,17 +81,17 @@ services:
|
|||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- soaricarus-network
|
||||||
|
|
||||||
# --- icarus web auth api db ---
|
# --- icarus web auth api db ---
|
||||||
auth_db:
|
auth_db:
|
||||||
image: postgres:18.4-alpine
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_auth_db
|
container_name: soaricarus_auth_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
POSTGRES_USER: ${POSTGRES_AUTH_USER:-soaricarus_op}
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password}
|
POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password}
|
||||||
POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db}
|
POSTGRES_DB: ${POSTGRES_AUTH_DB:-soaricarus_auth_db}
|
||||||
volumes:
|
volumes:
|
||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data_auth:/var/lib/postgresql
|
- postgres_data_auth:/var/lib/postgresql
|
||||||
@@ -106,7 +106,7 @@ services:
|
|||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- soaricarus-network
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
@@ -115,5 +115,5 @@ volumes:
|
|||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
icarus-network:
|
soaricarus-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|||||||
+2
-2
@@ -36,11 +36,11 @@ pub async fn auth<B>(
|
|||||||
(StatusCode::UNAUTHORIZED, Json(json_error))
|
(StatusCode::UNAUTHORIZED, Json(json_error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let secret_key = icarus_envy::environment::get_secret_main_key().value;
|
let secret_key = sienvy::environment::get_secret_main_key().value;
|
||||||
|
|
||||||
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
|
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
|
||||||
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
|
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
|
||||||
let _claims = decode::<icarus_models::token::UserClaims>(
|
let _claims = decode::<simodels::token::UserClaims>(
|
||||||
&token,
|
&token,
|
||||||
&DecodingKey::from_secret(secret_key.as_ref()),
|
&DecodingKey::from_secret(secret_key.as_ref()),
|
||||||
&validation,
|
&validation,
|
||||||
|
|||||||
+15
-18
@@ -20,7 +20,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::coverart::CoverArt>,
|
pub data: Vec<simodels::coverart::CoverArt>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::coverart::CoverArt>,
|
pub data: Vec<simodels::coverart::CoverArt>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,21 +68,21 @@ pub mod endpoint {
|
|||||||
let song_id = payload.song_id;
|
let song_id = payload.song_id;
|
||||||
match crate::repo::song::get_song(&pool, &song_id).await {
|
match crate::repo::song::get_song(&pool, &song_id).await {
|
||||||
Ok(song) => {
|
Ok(song) => {
|
||||||
let directory = icarus_envy::environment::get_root_directory().value;
|
let directory = sienvy::environment::get_root_directory().value;
|
||||||
let file_type =
|
let file_type =
|
||||||
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||||
let coverart_type = if file_type.file_type
|
let coverart_type = if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::JpegExtension
|
simodels::types::CoverArtType::JpegExtension
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::JpgExtension
|
simodels::types::CoverArtType::JpgExtension
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::PngExtension
|
simodels::types::CoverArtType::PngExtension
|
||||||
} else {
|
} else {
|
||||||
response.message = String::from("Invalid CoverArt type");
|
response.message = String::from("Invalid CoverArt type");
|
||||||
return (
|
return (
|
||||||
@@ -91,13 +91,11 @@ pub mod endpoint {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
let filename =
|
let filename =
|
||||||
icarus_models::coverart::generate_filename(coverart_type, true)
|
simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut coverart =
|
let mut coverart = simodels::coverart::init::init_coverart_dir_and_filename(
|
||||||
icarus_models::coverart::init::init_coverart_dir_and_filename(
|
&directory, &filename,
|
||||||
&directory, &filename,
|
);
|
||||||
);
|
|
||||||
coverart.title = song.album.clone();
|
coverart.title = song.album.clone();
|
||||||
coverart.file_type = file_type.file_type;
|
coverart.file_type = file_type.file_type;
|
||||||
coverart.data = data;
|
coverart.data = data;
|
||||||
@@ -200,7 +198,7 @@ pub mod endpoint {
|
|||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||||
match repo::coverart::get_coverart(&pool, &id).await {
|
match repo::coverart::get_coverart(&pool, &id).await {
|
||||||
Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) {
|
Ok(coverart) => match simodels::coverart::io::to_data(&coverart) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let (file_type, img_type) =
|
let (file_type, img_type) =
|
||||||
match icarus_meta::detection::coverart::file_type_from_data(&data) {
|
match icarus_meta::detection::coverart::file_type_from_data(&data) {
|
||||||
@@ -208,15 +206,15 @@ pub mod endpoint {
|
|||||||
if file_type.file_type
|
if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||||
{
|
{
|
||||||
(file_type, icarus_models::types::CoverArtType::JpegExtension)
|
(file_type, simodels::types::CoverArtType::JpegExtension)
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||||
{
|
{
|
||||||
(file_type, icarus_models::types::CoverArtType::JpgExtension)
|
(file_type, simodels::types::CoverArtType::JpgExtension)
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||||
{
|
{
|
||||||
(file_type, icarus_models::types::CoverArtType::PngExtension)
|
(file_type, simodels::types::CoverArtType::PngExtension)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
@@ -235,8 +233,7 @@ pub mod endpoint {
|
|||||||
let bytes = axum::body::Bytes::from(data);
|
let bytes = axum::body::Bytes::from(data);
|
||||||
let mut response = bytes.into_response();
|
let mut response = bytes.into_response();
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
let filename =
|
let filename = simodels::coverart::generate_filename(img_type, true).unwrap();
|
||||||
icarus_models::coverart::generate_filename(img_type, true).unwrap();
|
|
||||||
headers.insert(
|
headers.insert(
|
||||||
axum::http::header::CONTENT_TYPE,
|
axum::http::header::CONTENT_TYPE,
|
||||||
file_type.mime.parse().unwrap(),
|
file_type.mime.parse().unwrap(),
|
||||||
|
|||||||
@@ -331,23 +331,22 @@ pub mod endpoint {
|
|||||||
let coverart_type = if file_type.file_type
|
let coverart_type = if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::JpegExtension
|
simodels::types::CoverArtType::JpegExtension
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::JpgExtension
|
simodels::types::CoverArtType::JpgExtension
|
||||||
} else if file_type.file_type
|
} else if file_type.file_type
|
||||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||||
{
|
{
|
||||||
icarus_models::types::CoverArtType::PngExtension
|
simodels::types::CoverArtType::PngExtension
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::response::Response::default(),
|
axum::response::Response::default(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
let filename =
|
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||||
icarus_models::coverart::generate_filename(coverart_type, true).unwrap();
|
|
||||||
headers.insert(
|
headers.insert(
|
||||||
axum::http::header::CONTENT_DISPOSITION,
|
axum::http::header::CONTENT_DISPOSITION,
|
||||||
format!("attachment; filename=\"{filename}\"")
|
format!("attachment; filename=\"{filename}\"")
|
||||||
|
|||||||
+11
-13
@@ -36,8 +36,8 @@ pub mod request {
|
|||||||
|| !self.song_queue_id.is_nil()
|
|| !self.song_queue_id.is_nil()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_song(&self) -> icarus_models::song::Song {
|
pub fn to_song(&self) -> simodels::song::Song {
|
||||||
icarus_models::song::Song {
|
simodels::song::Song {
|
||||||
id: uuid::Uuid::nil(),
|
id: uuid::Uuid::nil(),
|
||||||
title: self.title.clone(),
|
title: self.title.clone(),
|
||||||
artist: self.artist.clone(),
|
artist: self.artist.clone(),
|
||||||
@@ -71,7 +71,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::song::Song>,
|
pub data: Vec<simodels::song::Song>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,15 +79,15 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::song::Song>,
|
pub data: Vec<simodels::song::Song>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod delete_song {
|
pub mod delete_song {
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct SongAndCoverArt {
|
pub struct SongAndCoverArt {
|
||||||
pub song: icarus_models::song::Song,
|
pub song: simodels::song::Song,
|
||||||
pub coverart: icarus_models::coverart::CoverArt,
|
pub coverart: simodels::coverart::CoverArt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
@@ -134,12 +134,10 @@ pub mod endpoint {
|
|||||||
|
|
||||||
if payload.is_valid() {
|
if payload.is_valid() {
|
||||||
let mut song = payload.to_song();
|
let mut song = payload.to_song();
|
||||||
song.filename = icarus_models::song::generate_filename(
|
song.filename =
|
||||||
icarus_models::types::MusicType::FlacExtension,
|
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
|
||||||
true,
|
.unwrap();
|
||||||
)
|
song.directory = sienvy::environment::get_root_directory().value;
|
||||||
.unwrap();
|
|
||||||
song.directory = icarus_envy::environment::get_root_directory().value;
|
|
||||||
|
|
||||||
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
@@ -340,7 +338,7 @@ pub mod endpoint {
|
|||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||||
match repo::song::get_song(&pool, &id).await {
|
match repo::song::get_song(&pool, &id).await {
|
||||||
Ok(song) => match icarus_models::song::io::to_data(&song) {
|
Ok(song) => match simodels::song::io::to_data(&song) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let bytes = axum::body::Bytes::from(data);
|
let bytes = axum::body::Bytes::from(data);
|
||||||
let mut response = bytes.into_response();
|
let mut response = bytes.into_response();
|
||||||
|
|||||||
+14
-19
@@ -28,20 +28,18 @@ mod cors {
|
|||||||
axum::http::Method::POST,
|
axum::http::Method::POST,
|
||||||
axum::http::Method::PUT,
|
axum::http::Method::PUT,
|
||||||
axum::http::Method::DELETE,
|
axum::http::Method::DELETE,
|
||||||
]) // Specify allowed methods:cite[2]
|
])
|
||||||
.allow_headers([
|
.allow_headers([
|
||||||
axum::http::header::CONTENT_TYPE,
|
axum::http::header::CONTENT_TYPE,
|
||||||
axum::http::header::AUTHORIZATION,
|
axum::http::header::AUTHORIZATION,
|
||||||
]) // Specify allowed headers:cite[2]
|
])
|
||||||
.allow_credentials(true) // If you need to send cookies or authentication headers:cite[2]
|
.allow_credentials(true)
|
||||||
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
||||||
|
|
||||||
// Dynamically set the allowed origin based on the environment
|
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
|
||||||
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
|
||||||
Ok("production") => {
|
Ok("production") => {
|
||||||
// In production, allow only your specific, trusted origins
|
let allowed_origins_env = sienvy::environment::get_allowed_origins();
|
||||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins();
|
match sienvy::utility::delimitize(&allowed_origins_env) {
|
||||||
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
|
||||||
Ok(alwd) => {
|
Ok(alwd) => {
|
||||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -55,17 +53,14 @@ mod cors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => cors.allow_origin(vec![
|
||||||
// Development (default): Allow localhost origins
|
"http://localhost:8000".parse().unwrap(),
|
||||||
cors.allow_origin(vec![
|
"http://127.0.0.1:8000".parse().unwrap(),
|
||||||
"http://localhost:8000".parse().unwrap(),
|
"http://localhost:8001".parse().unwrap(),
|
||||||
"http://127.0.0.1:8000".parse().unwrap(),
|
"http://127.0.0.1:8001".parse().unwrap(),
|
||||||
"http://localhost:8001".parse().unwrap(),
|
"http://localhost:4200".parse().unwrap(),
|
||||||
"http://127.0.0.1:8001".parse().unwrap(),
|
"http://127.0.0.1:4200".parse().unwrap(),
|
||||||
"http://localhost:4200".parse().unwrap(),
|
]),
|
||||||
"http://127.0.0.1:4200".parse().unwrap(),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ pub mod connection_settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().value;
|
let database_url = sienvy::environment::get_db_url().value;
|
||||||
println!("Database url: {database_url}");
|
println!("Database url: {database_url}");
|
||||||
|
|
||||||
PgPoolOptions::new()
|
PgPoolOptions::new()
|
||||||
|
|||||||
+15
-15
@@ -38,7 +38,7 @@ mod tests {
|
|||||||
pub const LIMIT: usize = 6;
|
pub const LIMIT: usize = 6;
|
||||||
|
|
||||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let tm_db_url = icarus_envy::environment::get_db_url().value;
|
let tm_db_url = sienvy::environment::get_db_url().value;
|
||||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||||
sqlx::PgPool::connect_with(tm_options).await
|
sqlx::PgPool::connect_with(tm_options).await
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let db_url = icarus_envy::environment::get_db_url().value;
|
let db_url = sienvy::environment::get_db_url().value;
|
||||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||||
sqlx::PgPool::connect_with(options).await
|
sqlx::PgPool::connect_with(options).await
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().value;
|
let database_url = sienvy::environment::get_db_url().value;
|
||||||
let parsed_url = url::Url::parse(&database_url)?;
|
let parsed_url = url::Url::parse(&database_url)?;
|
||||||
|
|
||||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||||
@@ -157,17 +157,17 @@ mod tests {
|
|||||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||||
|
|
||||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||||
let key: String = icarus_envy::environment::get_secret_main_key().value;
|
let key: String = sienvy::environment::get_secret_main_key().value;
|
||||||
let (message, issuer, audience) = token_fields();
|
let (message, issuer, audience) = token_fields();
|
||||||
|
|
||||||
let token_resource = icarus_models::token::TokenResource {
|
let token_resource = simodels::token::TokenResource {
|
||||||
message: message,
|
message: message,
|
||||||
issuer: issuer,
|
issuer: issuer,
|
||||||
audiences: vec![audience],
|
audiences: vec![audience],
|
||||||
id: TEST_USER_ID,
|
id: TEST_USER_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
match icarus_models::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
match simodels::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
||||||
Ok((access_token, _some_time)) => Ok(access_token),
|
Ok((access_token, _some_time)) => Ok(access_token),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
@@ -913,10 +913,10 @@ mod tests {
|
|||||||
let temp_file =
|
let temp_file =
|
||||||
tempfile::tempdir().expect("Could not create test directory");
|
tempfile::tempdir().expect("Could not create test directory");
|
||||||
let test_dir = String::from(temp_file.path().to_str().unwrap());
|
let test_dir = String::from(temp_file.path().to_str().unwrap());
|
||||||
let song = icarus_models::song::Song {
|
let song = simodels::song::Song {
|
||||||
directory: test_dir,
|
directory: test_dir,
|
||||||
filename: icarus_models::song::generate_filename(
|
filename: simodels::song::generate_filename(
|
||||||
icarus_models::types::MusicType::FlacExtension,
|
simodels::types::MusicType::FlacExtension,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
@@ -2219,20 +2219,20 @@ mod tests {
|
|||||||
coverart_directory: &String,
|
coverart_directory: &String,
|
||||||
coverart_filename: &String,
|
coverart_filename: &String,
|
||||||
) -> Result<(Vec<u8>, Vec<u8>), std::io::Error> {
|
) -> Result<(Vec<u8>, Vec<u8>), std::io::Error> {
|
||||||
let song = icarus_models::song::Song {
|
let song = simodels::song::Song {
|
||||||
directory: song_directory.clone(),
|
directory: song_directory.clone(),
|
||||||
filename: song_filename.clone(),
|
filename: song_filename.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let coverart = icarus_models::coverart::CoverArt {
|
let coverart = simodels::coverart::CoverArt {
|
||||||
directory: coverart_directory.clone(),
|
directory: coverart_directory.clone(),
|
||||||
filename: coverart_filename.clone(),
|
filename: coverart_filename.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
match icarus_models::song::io::to_data(&song) {
|
match simodels::song::io::to_data(&song) {
|
||||||
Ok(song_data) => match icarus_models::coverart::io::to_data(&coverart) {
|
Ok(song_data) => match simodels::coverart::io::to_data(&coverart) {
|
||||||
Ok(coverart_data) => Ok((song_data, coverart_data)),
|
Ok(coverart_data) => Ok((song_data, coverart_data)),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
@@ -2248,14 +2248,14 @@ mod tests {
|
|||||||
coverart_filename: &String,
|
coverart_filename: &String,
|
||||||
coverart_data: Vec<u8>,
|
coverart_data: Vec<u8>,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
let song = icarus_models::song::Song {
|
let song = simodels::song::Song {
|
||||||
directory: song_directory.clone(),
|
directory: song_directory.clone(),
|
||||||
filename: song_filename.clone(),
|
filename: song_filename.clone(),
|
||||||
data: song_data,
|
data: song_data,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let coverart = icarus_models::coverart::CoverArt {
|
let coverart = simodels::coverart::CoverArt {
|
||||||
directory: coverart_directory.clone(),
|
directory: coverart_directory.clone(),
|
||||||
filename: coverart_filename.clone(),
|
filename: coverart_filename.clone(),
|
||||||
data: coverart_data,
|
data: coverart_data,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use sqlx::Row;
|
|||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
coverart: &icarus_models::coverart::CoverArt,
|
coverart: &simodels::coverart::CoverArt,
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
@@ -36,7 +36,7 @@ pub async fn create(
|
|||||||
pub async fn get_coverart(
|
pub async fn get_coverart(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE id = $1;
|
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE id = $1;
|
||||||
@@ -50,7 +50,7 @@ pub async fn get_coverart(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -84,7 +84,7 @@ pub async fn get_coverart(
|
|||||||
pub async fn get_coverart_with_song_id(
|
pub async fn get_coverart_with_song_id(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE song_id = $1;
|
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE song_id = $1;
|
||||||
@@ -98,7 +98,7 @@ pub async fn get_coverart_with_song_id(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -132,7 +132,7 @@ pub async fn get_coverart_with_song_id(
|
|||||||
pub async fn delete_coverart(
|
pub async fn delete_coverart(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM "coverart"
|
DELETE FROM "coverart"
|
||||||
@@ -148,7 +148,7 @@ pub async fn delete_coverart(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
|||||||
+9
-11
@@ -2,7 +2,7 @@ use sqlx::Row;
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
song: &icarus_models::song::Song,
|
song: &simodels::song::Song,
|
||||||
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
|
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
@@ -52,7 +52,7 @@ pub async fn insert(
|
|||||||
pub async fn get_song(
|
pub async fn get_song(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::song::Song, sqlx::Error> {
|
) -> Result<simodels::song::Song, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT * FROM "song" WHERE id = $1
|
SELECT * FROM "song" WHERE id = $1
|
||||||
@@ -72,7 +72,7 @@ pub async fn get_song(
|
|||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(icarus_models::song::Song {
|
Ok(simodels::song::Song {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -145,9 +145,7 @@ pub async fn get_song(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_songs(
|
pub async fn get_all_songs(pool: &sqlx::PgPool) -> Result<Vec<simodels::song::Song>, sqlx::Error> {
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
) -> Result<Vec<icarus_models::song::Song>, sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT * FROM "song";
|
SELECT * FROM "song";
|
||||||
@@ -161,7 +159,7 @@ pub async fn get_all_songs(
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(rows) => {
|
Ok(rows) => {
|
||||||
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
|
let mut songs: Vec<simodels::song::Song> = Vec::new();
|
||||||
|
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let date_created_time: time::OffsetDateTime = row
|
let date_created_time: time::OffsetDateTime = row
|
||||||
@@ -169,7 +167,7 @@ pub async fn get_all_songs(
|
|||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let song = icarus_models::song::Song {
|
let song = simodels::song::Song {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -250,9 +248,9 @@ pub async fn get_all_songs(
|
|||||||
pub async fn delete_song(
|
pub async fn delete_song(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::song::Song, sqlx::Error> {
|
) -> Result<simodels::song::Song, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
// icarus_models::song::Song,
|
// simodels::song::Song,
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM "song"
|
DELETE FROM "song"
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
@@ -273,7 +271,7 @@ pub async fn delete_song(
|
|||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(icarus_models::song::Song {
|
Ok(simodels::song::Song {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
|||||||
Reference in New Issue
Block a user