From 19787a3f51aca28d71552dd020a2bad34369c0b2 Mon Sep 17 00:00:00 2001
From: Jai Agrawal <18202329+Geometrically@users.noreply.github.com>
Date: Sat, 1 Mar 2025 20:53:43 -0800
Subject: [PATCH] Subpackage common -> ariadne (#3323)
* Subpackage common -> ariadne
* add common
* Remove build
* only build labrinth
* common
* set sqlx offline
* copy dirs
* Fix build
---
.github/workflows/labrinth-docker.yml | 4 +++-
.idea/code.iml | 3 ++-
Cargo.lock | 18 ++++++++++++++++-
Cargo.toml | 1 +
apps/labrinth/Cargo.toml | 2 ++
apps/labrinth/Dockerfile | 8 +++++---
apps/labrinth/src/auth/mod.rs | 2 +-
apps/labrinth/src/auth/oauth/errors.rs | 2 +-
apps/labrinth/src/database/models/ids.rs | 4 ++--
.../src/database/models/organization_item.rs | 2 +-
apps/labrinth/src/database/models/pat_item.rs | 2 +-
.../src/database/models/project_item.rs | 2 +-
.../src/database/models/session_item.rs | 2 +-
.../labrinth/src/database/models/user_item.rs | 2 +-
apps/labrinth/src/database/redis.rs | 2 +-
apps/labrinth/src/lib.rs | 8 ++------
apps/labrinth/src/models/v3/ids.rs | 6 +++---
apps/labrinth/src/models/v3/users.rs | 2 +-
apps/labrinth/src/routes/internal/admin.rs | 9 ++++-----
apps/labrinth/src/routes/internal/billing.rs | 2 +-
apps/labrinth/src/routes/internal/flows.rs | 4 ++--
.../src/routes/internal/moderation.rs | 2 +-
apps/labrinth/src/routes/internal/statuses.rs | 10 +++++-----
apps/labrinth/src/routes/maven.rs | 2 +-
apps/labrinth/src/routes/mod.rs | 2 +-
apps/labrinth/src/routes/v3/analytics_get.rs | 2 +-
apps/labrinth/src/routes/v3/collections.rs | 2 +-
apps/labrinth/src/routes/v3/friends.rs | 2 +-
apps/labrinth/src/routes/v3/oauth_clients.rs | 2 +-
apps/labrinth/src/routes/v3/organizations.rs | 2 +-
.../src/routes/v3/project_creation.rs | 2 +-
apps/labrinth/src/routes/v3/projects.rs | 2 +-
apps/labrinth/src/routes/v3/reports.rs | 2 +-
apps/labrinth/src/routes/v3/versions.rs | 2 +-
apps/labrinth/src/search/indexing/mod.rs | 2 +-
apps/labrinth/src/util/webhook.rs | 2 +-
apps/labrinth/tests/analytics.rs | 2 +-
.../tests/common/api_common/generic.rs | 16 +++++++--------
.../tests/common/api_common/request_data.rs | 2 +-
apps/labrinth/tests/common/api_v2/project.rs | 2 +-
.../tests/common/api_v2/request_data.rs | 2 +-
apps/labrinth/tests/common/api_v2/user.rs | 2 +-
.../tests/common/api_v3/request_data.rs | 2 +-
apps/labrinth/tests/common/api_v3/user.rs | 2 +-
apps/labrinth/tests/common/asserts.rs | 2 +-
apps/labrinth/tests/common/database.rs | 2 +-
apps/labrinth/tests/common/permissions.rs | 2 +-
apps/labrinth/tests/loader_fields.rs | 10 ++++------
apps/labrinth/tests/notifications.rs | 2 +-
apps/labrinth/tests/organizations.rs | 4 ++--
apps/labrinth/tests/pats.rs | 2 +-
apps/labrinth/tests/project.rs | 10 +++++-----
apps/labrinth/tests/scopes.rs | 12 +++++------
apps/labrinth/tests/search.rs | 2 +-
apps/labrinth/tests/tags.rs | 2 +-
apps/labrinth/tests/teams.rs | 2 +-
apps/labrinth/tests/user.rs | 2 +-
apps/labrinth/tests/v2/error.rs | 6 +++---
apps/labrinth/tests/v2/notifications.rs | 2 +-
apps/labrinth/tests/v2/project.rs | 2 +-
apps/labrinth/tests/v2/scopes.rs | 18 ++++++++---------
apps/labrinth/tests/v2/search.rs | 20 +++++++++----------
apps/labrinth/tests/v2/tags.rs | 2 +-
apps/labrinth/tests/v2/version.rs | 12 +++++------
apps/labrinth/tests/version.rs | 12 +++++------
packages/app-lib/Cargo.toml | 2 +-
packages/app-lib/src/api/friends.rs | 2 +-
packages/app-lib/src/api/mod.rs | 2 +-
packages/app-lib/src/error.rs | 2 +-
packages/app-lib/src/event/mod.rs | 2 +-
packages/app-lib/src/state/friends.rs | 8 ++++----
packages/app-lib/src/state/tunnel.rs | 2 +-
packages/ariadne/Cargo.toml | 15 ++++++++++++++
.../common => packages/ariadne/src}/ids.rs | 8 +++-----
.../mod.rs => packages/ariadne/src/lib.rs | 0
packages/ariadne/src/mod.rs | 3 +++
.../ariadne/src}/networking/message.rs | 4 ++--
.../ariadne/src}/networking/mod.rs | 0
.../ariadne/src}/networking/serialization.rs | 0
.../common => packages/ariadne/src}/users.rs | 0
80 files changed, 181 insertions(+), 152 deletions(-)
create mode 100644 packages/ariadne/Cargo.toml
rename {apps/labrinth/src/common => packages/ariadne/src}/ids.rs (96%)
rename apps/labrinth/src/common/mod.rs => packages/ariadne/src/lib.rs (100%)
create mode 100644 packages/ariadne/src/mod.rs
rename {apps/labrinth/src/common => packages/ariadne/src}/networking/message.rs (94%)
rename {apps/labrinth/src/common => packages/ariadne/src}/networking/mod.rs (100%)
rename {apps/labrinth/src/common => packages/ariadne/src}/networking/serialization.rs (100%)
rename {apps/labrinth/src/common => packages/ariadne/src}/users.rs (100%)
diff --git a/.github/workflows/labrinth-docker.yml b/.github/workflows/labrinth-docker.yml
index 6f408025..1ed8e968 100644
--- a/.github/workflows/labrinth-docker.yml
+++ b/.github/workflows/labrinth-docker.yml
@@ -38,8 +38,10 @@ jobs:
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
+ env:
+ SQLX_OFFLINE: true
with:
- context: ./apps/labrinth
+ file: ./apps/labrinth/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
diff --git a/.idea/code.iml b/.idea/code.iml
index 5fda4410..a4489bea 100644
--- a/.idea/code.iml
+++ b/.idea/code.iml
@@ -11,9 +11,10 @@
+
-
+
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index a3923eb1..fdce2942 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -426,6 +426,21 @@ dependencies = [
"password-hash 0.5.0",
]
+[[package]]
+name = "ariadne"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "either",
+ "rand 0.8.5",
+ "serde",
+ "serde_bytes",
+ "serde_cbor",
+ "serde_json",
+ "thiserror 1.0.64",
+ "uuid 1.12.0",
+]
+
[[package]]
name = "arrayvec"
version = "0.7.6"
@@ -4238,6 +4253,7 @@ dependencies = [
"actix-web-prom",
"actix-ws",
"argon2",
+ "ariadne",
"async-stripe",
"async-trait",
"base64 0.21.7",
@@ -8900,6 +8916,7 @@ dependencies = [
name = "theseus"
version = "0.9.3"
dependencies = [
+ "ariadne",
"async-recursion",
"async-tungstenite",
"async_zip",
@@ -8916,7 +8933,6 @@ dependencies = [
"flate2",
"futures 0.3.30",
"indicatif",
- "labrinth",
"lazy_static",
"notify",
"notify-debouncer-mini",
diff --git a/Cargo.toml b/Cargo.toml
index 9afcf86c..97d69a24 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ members = [
'./apps/labrinth',
'./apps/daedalus_client',
'./packages/daedalus',
+ './packages/ariadne',
]
# Optimize for speed and reduce size on release builds
diff --git a/apps/labrinth/Cargo.toml b/apps/labrinth/Cargo.toml
index 7ae09784..e4915fec 100644
--- a/apps/labrinth/Cargo.toml
+++ b/apps/labrinth/Cargo.toml
@@ -127,6 +127,8 @@ async-stripe = { version = "0.39.1", features = ["runtime-tokio-hyper-rustls"] }
rusty-money = "0.4.1"
json-patch = "*"
+ariadne = { path = "../../packages/ariadne" }
+
[dev-dependencies]
actix-http = "3.4.0"
diff --git a/apps/labrinth/Dockerfile b/apps/labrinth/Dockerfile
index 851579f7..8c046449 100644
--- a/apps/labrinth/Dockerfile
+++ b/apps/labrinth/Dockerfile
@@ -3,7 +3,9 @@ ENV PKG_CONFIG_ALLOW_CROSS=1
WORKDIR /usr/src/labrinth
COPY . .
-RUN cargo build --release
+ENV SQLX_OFFLINE=true
+COPY apps/labrinth/.sqlx/ .sqlx/
+RUN cargo build --release --package labrinth
FROM debian:bookworm-slim
@@ -20,8 +22,8 @@ RUN apt-get update \
RUN update-ca-certificates
COPY --from=build /usr/src/labrinth/target/release/labrinth /labrinth/labrinth
-COPY --from=build /usr/src/labrinth/migrations/* /labrinth/migrations/
-COPY --from=build /usr/src/labrinth/assets /labrinth/assets
+COPY --from=build /usr/src/labrinth/apps/labrinth/migrations/* /labrinth/migrations/
+COPY --from=build /usr/src/labrinth/apps/labrinth/assets /labrinth/assets
WORKDIR /labrinth
CMD /labrinth/labrinth
\ No newline at end of file
diff --git a/apps/labrinth/src/auth/mod.rs b/apps/labrinth/src/auth/mod.rs
index 9a8a29c0..9b969caa 100644
--- a/apps/labrinth/src/auth/mod.rs
+++ b/apps/labrinth/src/auth/mod.rs
@@ -34,7 +34,7 @@ pub enum AuthenticationError {
#[error("Error uploading user profile picture")]
FileHosting(#[from] FileHostingError),
#[error("Error while decoding PAT: {0}")]
- Decoding(#[from] crate::common::ids::DecodingError),
+ Decoding(#[from] ariadne::ids::DecodingError),
#[error("{0}")]
Mail(#[from] email::MailError),
#[error("Invalid Authentication Credentials")]
diff --git a/apps/labrinth/src/auth/oauth/errors.rs b/apps/labrinth/src/auth/oauth/errors.rs
index bc2c66cb..af1d253e 100644
--- a/apps/labrinth/src/auth/oauth/errors.rs
+++ b/apps/labrinth/src/auth/oauth/errors.rs
@@ -1,9 +1,9 @@
use super::ValidatedRedirectUri;
use crate::auth::AuthenticationError;
-use crate::common::ids::DecodingError;
use crate::models::error::ApiError;
use actix_web::http::{header::LOCATION, StatusCode};
use actix_web::HttpResponse;
+use ariadne::ids::DecodingError;
#[derive(thiserror::Error, Debug)]
#[error("{}", .error_type)]
diff --git a/apps/labrinth/src/database/models/ids.rs b/apps/labrinth/src/database/models/ids.rs
index b7f33872..9c730a71 100644
--- a/apps/labrinth/src/database/models/ids.rs
+++ b/apps/labrinth/src/database/models/ids.rs
@@ -1,6 +1,6 @@
use super::DatabaseError;
-use crate::common::ids::base62_impl::to_base62;
-use crate::common::ids::{random_base62_rng, random_base62_rng_range};
+use ariadne::ids::base62_impl::to_base62;
+use ariadne::ids::{random_base62_rng, random_base62_rng_range};
use censor::Censor;
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
diff --git a/apps/labrinth/src/database/models/organization_item.rs b/apps/labrinth/src/database/models/organization_item.rs
index 51a9c8c0..32c779f5 100644
--- a/apps/labrinth/src/database/models/organization_item.rs
+++ b/apps/labrinth/src/database/models/organization_item.rs
@@ -1,5 +1,5 @@
-use crate::common::ids::base62_impl::parse_base62;
use crate::database::redis::RedisPool;
+use ariadne::ids::base62_impl::parse_base62;
use dashmap::DashMap;
use futures::TryStreamExt;
use std::fmt::{Debug, Display};
diff --git a/apps/labrinth/src/database/models/pat_item.rs b/apps/labrinth/src/database/models/pat_item.rs
index 2ae53666..f389cce9 100644
--- a/apps/labrinth/src/database/models/pat_item.rs
+++ b/apps/labrinth/src/database/models/pat_item.rs
@@ -1,8 +1,8 @@
use super::ids::*;
-use crate::common::ids::base62_impl::parse_base62;
use crate::database::models::DatabaseError;
use crate::database::redis::RedisPool;
use crate::models::pats::Scopes;
+use ariadne::ids::base62_impl::parse_base62;
use chrono::{DateTime, Utc};
use dashmap::DashMap;
use futures::TryStreamExt;
diff --git a/apps/labrinth/src/database/models/project_item.rs b/apps/labrinth/src/database/models/project_item.rs
index 2a40b686..e2ca2522 100644
--- a/apps/labrinth/src/database/models/project_item.rs
+++ b/apps/labrinth/src/database/models/project_item.rs
@@ -3,11 +3,11 @@ use super::loader_fields::{
VersionField,
};
use super::{ids::*, User};
-use crate::common::ids::base62_impl::parse_base62;
use crate::database::models;
use crate::database::models::DatabaseError;
use crate::database::redis::RedisPool;
use crate::models::projects::{MonetizationStatus, ProjectStatus};
+use ariadne::ids::base62_impl::parse_base62;
use chrono::{DateTime, Utc};
use dashmap::{DashMap, DashSet};
use futures::TryStreamExt;
diff --git a/apps/labrinth/src/database/models/session_item.rs b/apps/labrinth/src/database/models/session_item.rs
index 4717c2a8..57fd42ce 100644
--- a/apps/labrinth/src/database/models/session_item.rs
+++ b/apps/labrinth/src/database/models/session_item.rs
@@ -1,7 +1,7 @@
use super::ids::*;
-use crate::common::ids::base62_impl::parse_base62;
use crate::database::models::DatabaseError;
use crate::database::redis::RedisPool;
+use ariadne::ids::base62_impl::parse_base62;
use chrono::{DateTime, Utc};
use dashmap::DashMap;
use serde::{Deserialize, Serialize};
diff --git a/apps/labrinth/src/database/models/user_item.rs b/apps/labrinth/src/database/models/user_item.rs
index 09f01759..a231c2c6 100644
--- a/apps/labrinth/src/database/models/user_item.rs
+++ b/apps/labrinth/src/database/models/user_item.rs
@@ -1,10 +1,10 @@
use super::ids::{ProjectId, UserId};
use super::{CollectionId, ReportId, ThreadId};
-use crate::common::ids::base62_impl::{parse_base62, to_base62};
use crate::database::models;
use crate::database::models::{DatabaseError, OrganizationId};
use crate::database::redis::RedisPool;
use crate::models::users::Badges;
+use ariadne::ids::base62_impl::{parse_base62, to_base62};
use chrono::{DateTime, Utc};
use dashmap::DashMap;
use serde::{Deserialize, Serialize};
diff --git a/apps/labrinth/src/database/redis.rs b/apps/labrinth/src/database/redis.rs
index b28317fc..fa77707e 100644
--- a/apps/labrinth/src/database/redis.rs
+++ b/apps/labrinth/src/database/redis.rs
@@ -1,5 +1,5 @@
use super::models::DatabaseError;
-use crate::common::ids::base62_impl::{parse_base62, to_base62};
+use ariadne::ids::base62_impl::{parse_base62, to_base62};
use chrono::{TimeZone, Utc};
use dashmap::DashMap;
use deadpool_redis::{Config, Runtime};
diff --git a/apps/labrinth/src/lib.rs b/apps/labrinth/src/lib.rs
index 9856cfb1..2e4b6cf0 100644
--- a/apps/labrinth/src/lib.rs
+++ b/apps/labrinth/src/lib.rs
@@ -25,8 +25,6 @@ use crate::{
util::env::{parse_strings_from_var, parse_var},
};
-pub mod common;
-
pub mod auth;
pub mod clickhouse;
pub mod database;
@@ -299,10 +297,8 @@ pub fn app_setup(
}
let ip_salt = Pepper {
- pepper: crate::common::ids::Base62Id(
- crate::common::ids::random_base62(11),
- )
- .to_string(),
+ pepper: ariadne::ids::Base62Id(ariadne::ids::random_base62(11))
+ .to_string(),
};
let payouts_queue = web::Data::new(PayoutsQueue::new());
diff --git a/apps/labrinth/src/models/v3/ids.rs b/apps/labrinth/src/models/v3/ids.rs
index 3d8a8cfd..033bfdc0 100644
--- a/apps/labrinth/src/models/v3/ids.rs
+++ b/apps/labrinth/src/models/v3/ids.rs
@@ -12,12 +12,12 @@ pub use super::sessions::SessionId;
pub use super::teams::TeamId;
pub use super::threads::ThreadId;
pub use super::threads::ThreadMessageId;
-pub use super::users::UserId;
-use crate::common::ids::base62_id_impl;
-pub use crate::common::ids::Base62Id;
pub use crate::models::billing::{
ChargeId, ProductId, ProductPriceId, UserSubscriptionId,
};
+use ariadne::ids::base62_id_impl;
+pub use ariadne::ids::Base62Id;
+pub use ariadne::users::UserId;
base62_id_impl!(ProjectId, ProjectId);
base62_id_impl!(VersionId, VersionId);
diff --git a/apps/labrinth/src/models/v3/users.rs b/apps/labrinth/src/models/v3/users.rs
index 8e9427dd..0c44fa09 100644
--- a/apps/labrinth/src/models/v3/users.rs
+++ b/apps/labrinth/src/models/v3/users.rs
@@ -1,5 +1,5 @@
-pub use crate::common::users::{UserId, UserStatus};
use crate::{auth::AuthProvider, bitflags_serde_impl};
+pub use ariadne::users::{UserId, UserStatus};
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
diff --git a/apps/labrinth/src/routes/internal/admin.rs b/apps/labrinth/src/routes/internal/admin.rs
index 62562ab1..cf7f8a10 100644
--- a/apps/labrinth/src/routes/internal/admin.rs
+++ b/apps/labrinth/src/routes/internal/admin.rs
@@ -74,11 +74,10 @@ pub async fn count_download(
let project_id: crate::database::models::ids::ProjectId =
download_body.project_id.into();
- let id_option = crate::common::ids::base62_impl::parse_base62(
- &download_body.version_name,
- )
- .ok()
- .map(|x| x as i64);
+ let id_option =
+ ariadne::ids::base62_impl::parse_base62(&download_body.version_name)
+ .ok()
+ .map(|x| x as i64);
let (version_id, project_id) = if let Some(version) = sqlx::query!(
"
diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs
index 380533cd..28c9954c 100644
--- a/apps/labrinth/src/routes/internal/billing.rs
+++ b/apps/labrinth/src/routes/internal/billing.rs
@@ -1,5 +1,4 @@
use crate::auth::{get_user_from_headers, send_email};
-use crate::common::ids::base62_impl::{parse_base62, to_base62};
use crate::database::models::charge_item::ChargeItem;
use crate::database::models::{
generate_charge_id, generate_user_subscription_id, product_item,
@@ -16,6 +15,7 @@ use crate::models::users::Badges;
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
+use ariadne::ids::base62_impl::{parse_base62, to_base62};
use chrono::Utc;
use log::{info, warn};
use rust_decimal::prelude::ToPrimitive;
diff --git a/apps/labrinth/src/routes/internal/flows.rs b/apps/labrinth/src/routes/internal/flows.rs
index 5d20b6c8..31e3c620 100644
--- a/apps/labrinth/src/routes/internal/flows.rs
+++ b/apps/labrinth/src/routes/internal/flows.rs
@@ -1,8 +1,6 @@
use crate::auth::email::send_email;
use crate::auth::validate::get_user_record_from_bearer_token;
use crate::auth::{get_user_from_headers, AuthProvider, AuthenticationError};
-use crate::common::ids::base62_impl::{parse_base62, to_base62};
-use crate::common::ids::random_base62_rng;
use crate::database::models::flow_item::Flow;
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
@@ -20,6 +18,8 @@ use actix_web::web::{scope, Data, Query, ServiceConfig};
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
use argon2::password_hash::SaltString;
use argon2::{Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
+use ariadne::ids::base62_impl::{parse_base62, to_base62};
+use ariadne::ids::random_base62_rng;
use base64::Engine;
use chrono::{Duration, Utc};
use rand_chacha::rand_core::SeedableRng;
diff --git a/apps/labrinth/src/routes/internal/moderation.rs b/apps/labrinth/src/routes/internal/moderation.rs
index 28f604e3..06654100 100644
--- a/apps/labrinth/src/routes/internal/moderation.rs
+++ b/apps/labrinth/src/routes/internal/moderation.rs
@@ -1,5 +1,4 @@
use super::ApiError;
-use crate::common::ids::random_base62;
use crate::database;
use crate::database::redis::RedisPool;
use crate::models::projects::ProjectStatus;
@@ -7,6 +6,7 @@ use crate::queue::moderation::{ApprovalType, IdentifiedFile, MissingMetadata};
use crate::queue::session::AuthQueue;
use crate::{auth::check_is_moderator_from_headers, models::pats::Scopes};
use actix_web::{web, HttpRequest, HttpResponse};
+use ariadne::ids::random_base62;
use serde::Deserialize;
use sqlx::PgPool;
use std::collections::HashMap;
diff --git a/apps/labrinth/src/routes/internal/statuses.rs b/apps/labrinth/src/routes/internal/statuses.rs
index c531c5c7..5054ad67 100644
--- a/apps/labrinth/src/routes/internal/statuses.rs
+++ b/apps/labrinth/src/routes/internal/statuses.rs
@@ -1,10 +1,5 @@
use crate::auth::validate::get_user_record_from_bearer_token;
use crate::auth::AuthenticationError;
-use crate::common::ids::UserId;
-use crate::common::networking::message::{
- ClientToServerMessage, ServerToClientMessage,
-};
-use crate::common::users::UserStatus;
use crate::database::models::friend_item::FriendItem;
use crate::database::redis::RedisPool;
use crate::models::pats::Scopes;
@@ -17,6 +12,11 @@ use crate::routes::ApiError;
use actix_web::web::{Data, Payload};
use actix_web::{get, web, HttpRequest, HttpResponse};
use actix_ws::Message;
+use ariadne::ids::UserId;
+use ariadne::networking::message::{
+ ClientToServerMessage, ServerToClientMessage,
+};
+use ariadne::users::UserStatus;
use chrono::Utc;
use either::Either;
use futures_util::{StreamExt, TryStreamExt};
diff --git a/apps/labrinth/src/routes/maven.rs b/apps/labrinth/src/routes/maven.rs
index e53ec6a3..bf024784 100644
--- a/apps/labrinth/src/routes/maven.rs
+++ b/apps/labrinth/src/routes/maven.rs
@@ -164,7 +164,7 @@ async fn find_version(
pool: &PgPool,
redis: &RedisPool,
) -> Result