diff --git a/Cargo.lock b/Cargo.lock index c032944..a311bba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,7 +137,6 @@ dependencies = [ "axum-extra", "chrono", "common", - "db", "futures", "hex", "jsonwebtoken", @@ -948,10 +947,17 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" name = "common" version = "0.1.0" dependencies = [ + "argon2", "aws-config", "aws-sdk-s3", "aws-types", + "chrono", + "nanoid", + "serde", + "sqlx", "tracing", + "tracing-subscriber", + "uuid", "walkdir", ] @@ -1097,20 +1103,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" -[[package]] -name = "db" -version = "0.1.0" -dependencies = [ - "argon2", - "chrono", - "nanoid", - "serde", - "sqlx", - "tracing", - "tracing-subscriber", - "uuid", -] - [[package]] name = "der" version = "0.6.1" @@ -1317,7 +1309,7 @@ version = "0.1.0" dependencies = [ "anyhow", "axum 0.7.9", - "db", + "common", "queue", "tokio", "tracing", @@ -2432,7 +2424,6 @@ dependencies = [ "async-trait", "chrono", "common", - "db", "futures", "serde", "sqlx", @@ -3862,7 +3853,6 @@ dependencies = [ "anyhow", "aws-sdk-s3", "common", - "db", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index 9a35c1b..53c7c21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,4 @@ [workspace] -members = [ - "packages/db", - "packages/vod", - "packages/queue", - "services/forge-queue", - "services/silo-api", "packages/common", -] +members = ["crates/*", "services/forge-queue", "services/silo-api"] resolver = "2" diff --git a/config/api.Dockerfile b/config/api.Dockerfile index 5da0de4..106af89 100644 --- a/config/api.Dockerfile +++ b/config/api.Dockerfile @@ -14,7 +14,7 @@ WORKDIR /app COPY Cargo.toml Cargo.lock ./ # Copy all workspace members -COPY packages/ ./packages/ +COPY crates/ ./crates/ COPY services/forge-queue ./services/forge-queue COPY services/silo-api ./services/silo-api diff --git a/config/queue.Dockerfile b/config/queue.Dockerfile index 02e917f..457cf10 100644 --- a/config/queue.Dockerfile +++ b/config/queue.Dockerfile @@ -14,7 +14,7 @@ WORKDIR /app COPY Cargo.toml Cargo.lock ./ # Copy all workspace members -COPY packages/ ./packages/ +COPY crates/ ./crates/ COPY services/forge-queue ./services/forge-queue COPY services/silo-api ./services/silo-api diff --git a/packages/db/Cargo.toml b/crates/common/Cargo.toml similarity index 74% rename from packages/db/Cargo.toml rename to crates/common/Cargo.toml index 0c5e716..daa4232 100644 --- a/packages/db/Cargo.toml +++ b/crates/common/Cargo.toml @@ -1,9 +1,13 @@ [package] -name = "db" +name = "common" version = "0.1.0" edition = "2021" [dependencies] +aws-sdk-s3 = "1.66.0" +aws-config = { version = "1.5.11", features = ["behavior-version-latest"] } +aws-types = "1.3.3" +walkdir = "2.5.0" argon2 = { version = "0.5", features = ["password-hash"] } chrono = { version = "0.4", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } diff --git a/packages/db/migrations/20241030222807_users.down.sql b/crates/common/migrations/20241030222807_users.down.sql similarity index 100% rename from packages/db/migrations/20241030222807_users.down.sql rename to crates/common/migrations/20241030222807_users.down.sql diff --git a/packages/db/migrations/20241030222807_users.up.sql b/crates/common/migrations/20241030222807_users.up.sql similarity index 100% rename from packages/db/migrations/20241030222807_users.up.sql rename to crates/common/migrations/20241030222807_users.up.sql diff --git a/packages/db/migrations/20241101164200_add_videos.down.sql b/crates/common/migrations/20241101164200_add_videos.down.sql similarity index 100% rename from packages/db/migrations/20241101164200_add_videos.down.sql rename to crates/common/migrations/20241101164200_add_videos.down.sql diff --git a/packages/db/migrations/20241101164200_add_videos.up.sql b/crates/common/migrations/20241101164200_add_videos.up.sql similarity index 100% rename from packages/db/migrations/20241101164200_add_videos.up.sql rename to crates/common/migrations/20241101164200_add_videos.up.sql diff --git a/packages/db/migrations/20241109045238_queue.down.sql b/crates/common/migrations/20241109045238_queue.down.sql similarity index 100% rename from packages/db/migrations/20241109045238_queue.down.sql rename to crates/common/migrations/20241109045238_queue.down.sql diff --git a/packages/db/migrations/20241109045238_queue.up.sql b/crates/common/migrations/20241109045238_queue.up.sql similarity index 100% rename from packages/db/migrations/20241109045238_queue.up.sql rename to crates/common/migrations/20241109045238_queue.up.sql diff --git a/packages/db/migrations/20241109231211_video_privacy.down.sql b/crates/common/migrations/20241109231211_video_privacy.down.sql similarity index 100% rename from packages/db/migrations/20241109231211_video_privacy.down.sql rename to crates/common/migrations/20241109231211_video_privacy.down.sql diff --git a/packages/db/migrations/20241109231211_video_privacy.up.sql b/crates/common/migrations/20241109231211_video_privacy.up.sql similarity index 100% rename from packages/db/migrations/20241109231211_video_privacy.up.sql rename to crates/common/migrations/20241109231211_video_privacy.up.sql diff --git a/packages/db/migrations/20241110070700_user_roles.down.sql b/crates/common/migrations/20241110070700_user_roles.down.sql similarity index 100% rename from packages/db/migrations/20241110070700_user_roles.down.sql rename to crates/common/migrations/20241110070700_user_roles.down.sql diff --git a/packages/db/migrations/20241110070700_user_roles.up.sql b/crates/common/migrations/20241110070700_user_roles.up.sql similarity index 100% rename from packages/db/migrations/20241110070700_user_roles.up.sql rename to crates/common/migrations/20241110070700_user_roles.up.sql diff --git a/packages/db/migrations/20241124231804_compresseion_cols.down.sql b/crates/common/migrations/20241124231804_compresseion_cols.down.sql similarity index 100% rename from packages/db/migrations/20241124231804_compresseion_cols.down.sql rename to crates/common/migrations/20241124231804_compresseion_cols.down.sql diff --git a/packages/db/migrations/20241124231804_compresseion_cols.up.sql b/crates/common/migrations/20241124231804_compresseion_cols.up.sql similarity index 100% rename from packages/db/migrations/20241124231804_compresseion_cols.up.sql rename to crates/common/migrations/20241124231804_compresseion_cols.up.sql diff --git a/packages/db/migrations/20241125013621_user_accounts.down.sql b/crates/common/migrations/20241125013621_user_accounts.down.sql similarity index 100% rename from packages/db/migrations/20241125013621_user_accounts.down.sql rename to crates/common/migrations/20241125013621_user_accounts.down.sql diff --git a/packages/db/migrations/20241125013621_user_accounts.up.sql b/crates/common/migrations/20241125013621_user_accounts.up.sql similarity index 100% rename from packages/db/migrations/20241125013621_user_accounts.up.sql rename to crates/common/migrations/20241125013621_user_accounts.up.sql diff --git a/packages/db/src/accounts.rs b/crates/common/src/db/accounts.rs similarity index 100% rename from packages/db/src/accounts.rs rename to crates/common/src/db/accounts.rs diff --git a/packages/db/src/lib.rs b/crates/common/src/db/mod.rs similarity index 100% rename from packages/db/src/lib.rs rename to crates/common/src/db/mod.rs diff --git a/packages/db/src/users.rs b/crates/common/src/db/users.rs similarity index 100% rename from packages/db/src/users.rs rename to crates/common/src/db/users.rs diff --git a/packages/db/src/videos.rs b/crates/common/src/db/videos.rs similarity index 100% rename from packages/db/src/videos.rs rename to crates/common/src/db/videos.rs diff --git a/packages/common/src/lib.rs b/crates/common/src/lib.rs similarity index 95% rename from packages/common/src/lib.rs rename to crates/common/src/lib.rs index e89286c..0fc3460 100644 --- a/packages/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,3 +1,4 @@ +pub mod db; pub mod s3; /// Get the directory for where to store videos diff --git a/packages/common/src/s3.rs b/crates/common/src/s3.rs similarity index 100% rename from packages/common/src/s3.rs rename to crates/common/src/s3.rs diff --git a/packages/queue/Cargo.toml b/crates/queue/Cargo.toml similarity index 87% rename from packages/queue/Cargo.toml rename to crates/queue/Cargo.toml index 3568f63..c1026f7 100644 --- a/packages/queue/Cargo.toml +++ b/crates/queue/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" anyhow = "1" async-trait = "0.1" chrono = "0.4" -db = { path = "../../packages/db" } +common = { path = "../common" } futures = "0.3" serde = { version = "1", features = ["derive"] } thiserror = "1" @@ -22,6 +22,5 @@ tokio = { version = "1", features = ["full"] } tracing = "0.1" ulid = { version = "1", features = ["uuid"] } uuid = { version = "1", features = ["serde", "v4"] } -vod = { path = "../../packages/vod" } +vod = { path = "../vod" } zip = "0.6" -common = { path = "../common" } diff --git a/packages/queue/src/error.rs b/crates/queue/src/error.rs similarity index 100% rename from packages/queue/src/error.rs rename to crates/queue/src/error.rs diff --git a/packages/queue/src/job.rs b/crates/queue/src/job.rs similarity index 100% rename from packages/queue/src/job.rs rename to crates/queue/src/job.rs diff --git a/packages/queue/src/lib.rs b/crates/queue/src/lib.rs similarity index 100% rename from packages/queue/src/lib.rs rename to crates/queue/src/lib.rs diff --git a/packages/queue/src/queue.rs b/crates/queue/src/queue.rs similarity index 100% rename from packages/queue/src/queue.rs rename to crates/queue/src/queue.rs diff --git a/packages/queue/src/runner.rs b/crates/queue/src/runner.rs similarity index 99% rename from packages/queue/src/runner.rs rename to crates/queue/src/runner.rs index c0b85e0..c0ed031 100644 --- a/packages/queue/src/runner.rs +++ b/crates/queue/src/runner.rs @@ -4,7 +4,7 @@ use crate::queue::{Job, Message, Queue}; use anyhow::anyhow; use common::get_storage_dir; use common::s3::sync_directory_to_bucket; -use db::Video; +use common::db::Video; use futures::{stream, StreamExt}; use sqlx::{Pool, Postgres}; use std::fs; diff --git a/packages/vod/Cargo.toml b/crates/vod/Cargo.toml similarity index 86% rename from packages/vod/Cargo.toml rename to crates/vod/Cargo.toml index 3344913..ea66ead 100644 --- a/packages/vod/Cargo.toml +++ b/crates/vod/Cargo.toml @@ -6,6 +6,5 @@ edition = "2021" [dependencies] anyhow = "1.0" tracing = "0.1" -db = { path = "../db" } aws-sdk-s3 = "1.71.0" common = { path = "../common" } diff --git a/packages/vod/src/lib.rs b/crates/vod/src/lib.rs similarity index 99% rename from packages/vod/src/lib.rs rename to crates/vod/src/lib.rs index d384f7c..dd5ddbe 100644 --- a/packages/vod/src/lib.rs +++ b/crates/vod/src/lib.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use anyhow::anyhow; use aws_sdk_s3::Client; -use db::{DBPool, Video}; +use common::db::{DBPool, Video}; use stream::{get_ffmpeg_location, HLSConverter}; pub mod stream; diff --git a/packages/vod/src/stream.rs b/crates/vod/src/stream.rs similarity index 100% rename from packages/vod/src/stream.rs rename to crates/vod/src/stream.rs diff --git a/justfile b/justfile index 08e55b4..17b326e 100644 --- a/justfile +++ b/justfile @@ -28,7 +28,7 @@ create-db: drop-db: sqlx database drop -mig_source := "packages/db/migrations" +mig_source := "crates/common/migrations" mig: migrate migrate: diff --git a/packages/common/Cargo.toml b/packages/common/Cargo.toml deleted file mode 100644 index c8eb133..0000000 --- a/packages/common/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "common" -version = "0.1.0" -edition = "2021" - -[dependencies] -aws-sdk-s3 = "1.66.0" -aws-config = { version = "1.5.11", features = ["behavior-version-latest"] } -aws-types = "1.3.3" -walkdir = "2.5.0" -tracing = "0.1" diff --git a/services/forge-queue/Cargo.toml b/services/forge-queue/Cargo.toml index 4a096c4..37a99d1 100644 --- a/services/forge-queue/Cargo.toml +++ b/services/forge-queue/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" [dependencies] anyhow = "1" axum = { version = "0.7.9", features = ["tracing"] } -db = { path = "../../packages/db" } -queue = { path = "../../packages/queue" } +common = { path = "../../crates/common" } +queue = { path = "../../crates/queue" } tokio = { version = "1", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/services/forge-queue/src/main.rs b/services/forge-queue/src/main.rs index b2eb49a..53bbe47 100644 --- a/services/forge-queue/src/main.rs +++ b/services/forge-queue/src/main.rs @@ -1,4 +1,4 @@ -use db::connect_to_database; +use common::db::connect_to_database; use queue::{runner, PostgresQueue, Queue}; use std::sync::Arc; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; diff --git a/services/silo-api/Cargo.toml b/services/silo-api/Cargo.toml index 42ece2a..6aaa709 100644 --- a/services/silo-api/Cargo.toml +++ b/services/silo-api/Cargo.toml @@ -7,14 +7,13 @@ edition = "2021" axum = { version = "0.7", features = ["multipart", "tracing", "ws", "macros"] } axum-extra = "0.3" chrono = { version = "0.4.31", features = ["serde"] } -db = { path = "../../packages/db" } futures = "0.3" hex = "0.4" sha2 = "0.10" jsonwebtoken = "8.1" lazy_static = "1.4" nanoid = "0.4.0" -queue = { path = "../../packages/queue" } +queue = { path = "../../crates/queue" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sqlx = { version = "0.8", features = [ @@ -35,4 +34,4 @@ reqwest = { version = "0.12.9", features = ["json"] } aws-sdk-s3 = "1.66.0" aws-config = { version = "1.5.11", features = ["behavior-version-latest"] } aws-types = "1.3.3" -common = { path = "../../packages/common" } +common = { path = "../../crates/common" } diff --git a/services/silo-api/src/app_state.rs b/services/silo-api/src/app_state.rs index 71dbb9d..5593de0 100644 --- a/services/silo-api/src/app_state.rs +++ b/services/silo-api/src/app_state.rs @@ -17,7 +17,7 @@ pub struct AppState { impl AppState { pub async fn new(config: Config) -> Result> { // Initialize a connection to the database - let db = db::connect_to_database() + let db = common::db::connect_to_database() .await .expect("Could not connect to database"); // Initialize the queue diff --git a/services/silo-api/src/main.rs b/services/silo-api/src/main.rs index 348a784..fb793df 100644 --- a/services/silo-api/src/main.rs +++ b/services/silo-api/src/main.rs @@ -6,16 +6,12 @@ mod routes; pub use app_state::AppState; use axum::{ - extract::State, middleware as axum_mw, response::IntoResponse, routing::{delete, get, post}, - Json, Router, + Router, }; use config::Config; -use reqwest::StatusCode; - -use serde_json::json; use std::sync::Arc; use tower_http::{ diff --git a/services/silo-api/src/middleware/auth.rs b/services/silo-api/src/middleware/auth.rs index 8a1accb..4e7752b 100644 --- a/services/silo-api/src/middleware/auth.rs +++ b/services/silo-api/src/middleware/auth.rs @@ -7,7 +7,7 @@ use axum::{ http::{self, Response, StatusCode}, middleware::Next, }; -use db::users::User; +use common::db::users::User; use uuid::Uuid; /// A middleware for checking the validity of the JWT token diff --git a/services/silo-api/src/routes/auth/mod.rs b/services/silo-api/src/routes/auth/mod.rs index 9564811..a95cc18 100644 --- a/services/silo-api/src/routes/auth/mod.rs +++ b/services/silo-api/src/routes/auth/mod.rs @@ -3,7 +3,7 @@ pub mod oauth; use std::sync::Arc; use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; -use db::users::User; +use common::db::users::User; use serde::{Deserialize, Serialize}; use crate::{jwt::encode_jwt, AppState}; diff --git a/services/silo-api/src/routes/auth/oauth/twitch.rs b/services/silo-api/src/routes/auth/oauth/twitch.rs index 4062135..180edff 100644 --- a/services/silo-api/src/routes/auth/oauth/twitch.rs +++ b/services/silo-api/src/routes/auth/oauth/twitch.rs @@ -5,7 +5,7 @@ use axum::{ Extension, }; use chrono::{Duration, Utc}; -use db::{accounts::Account, users::User}; +use common::db::{accounts::Account, users::User}; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::{env, sync::Arc}; diff --git a/services/silo-api/src/routes/upload/cloud.rs b/services/silo-api/src/routes/upload/cloud.rs index ac01946..5211d53 100644 --- a/services/silo-api/src/routes/upload/cloud.rs +++ b/services/silo-api/src/routes/upload/cloud.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use aws_sdk_s3::types::{CompletedMultipartUpload, CompletedPart}; use axum::{extract::State, Extension, Json}; -use db::{User, Video}; +use common::db::{User, Video}; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/services/silo-api/src/routes/upload/on_disk.rs b/services/silo-api/src/routes/upload/on_disk.rs index b6c2111..f1fa975 100644 --- a/services/silo-api/src/routes/upload/on_disk.rs +++ b/services/silo-api/src/routes/upload/on_disk.rs @@ -3,7 +3,7 @@ use axum::{ http::StatusCode, Extension, }; -use db::{users::User, Video}; +use common::db::{users::User, Video}; use sha2::{Digest, Sha256}; use std::sync::atomic::{AtomicU64, Ordering}; use std::{collections::HashMap, path::Path, sync::Arc}; diff --git a/services/silo-api/src/routes/user.rs b/services/silo-api/src/routes/user.rs index c913c14..6303db6 100644 --- a/services/silo-api/src/routes/user.rs +++ b/services/silo-api/src/routes/user.rs @@ -6,7 +6,7 @@ use axum::{ response::IntoResponse, Extension, Json, }; -use db::users::{User, UserRole}; +use common::db::users::{User, UserRole}; use serde::{Deserialize, Serialize}; use crate::AppState; diff --git a/services/silo-api/src/routes/video.rs b/services/silo-api/src/routes/video.rs index 095afa3..fa4bcd1 100644 --- a/services/silo-api/src/routes/video.rs +++ b/services/silo-api/src/routes/video.rs @@ -4,7 +4,7 @@ use axum::{ response::IntoResponse, Extension, Json, }; -use db::{ProcessingStatus, User, Video}; +use common::db::{self, ProcessingStatus, User, Video}; use serde::{Deserialize, Serialize}; use std::sync::Arc;