Inherit dependencies from workspace manifest, and optimize some out (#3655)

* chore: inherit dependencies from workspace, optimize some deps out

* Update bitflags from 2.9.0 to 2.9.1

* Fix temp directory leak in check_java_at_filepath

* Fix build

* Fix lint

* chore(app-lib): refactor overkill `futures` executor usage to Tokio MPSC

* chore: fix Clippy lint

* tweak: optimize out dependency on OpenSSL source build

Contrary to what I expected before, this was caused due to the Tauri
updater plugin using a different TLS stack than everything else.

* chore(labrinth): drop now unused dependency

* Update zip because 2.6.1 got yanked

* Downgrade weezl to 0.1.8

* Mention that p256 is also a blocker for rand 0.9

* chore: sidestep GitHub review requirements

* chore: sidestep GitHub review requirements (2)

* chore: sidestep GitHub review requirements (3)

---------

Co-authored-by: Josiah Glosson <soujournme@gmail.com>
This commit is contained in:
Alejandro González
2025-05-15 22:47:29 +02:00
committed by GitHub
parent 37cc81a36d
commit f19643095e
35 changed files with 876 additions and 1020 deletions

View File

@@ -111,10 +111,10 @@ pub async fn init_oauth(
.map_err(|e| {
OAuthError::redirect(e, &oauth_info.state, &redirect_uri)
})?;
let redirect_uris = OAuthRedirectUris::new(
oauth_info.redirect_uri.clone(),
redirect_uri.clone(),
);
let redirect_uris = OAuthRedirectUris {
original: oauth_info.redirect_uri.clone(),
validated: redirect_uri.clone(),
};
match existing_authorization {
Some(existing_authorization)
if existing_authorization.scopes.contains(requested_scopes) =>

View File

@@ -3,7 +3,7 @@ use crate::auth::oauth::OAuthErrorType;
use crate::database::models::OAuthClientId;
use serde::{Deserialize, Serialize};
#[derive(derive_new::new, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct OAuthRedirectUris {
pub original: Option<String>,
pub validated: ValidatedRedirectUri,

View File

@@ -132,6 +132,8 @@ pub async fn payouts(
}
mod version_updater {
use std::sync::LazyLock;
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
use crate::database::redis::RedisPool;
use chrono::{DateTime, Utc};
@@ -197,36 +199,45 @@ mod version_updater {
("3D Shareware v1.34", "3D-Shareware-v1.34"),
];
lazy_static::lazy_static! {
/// Mojank for some reason has versions released at the same DateTime. This hardcodes them to fix this,
/// as most of our ordering logic is with DateTime
static ref HALL_OF_SHAME_2: [(&'static str, DateTime<Utc>); 4] = [
(
"1.4.5",
chrono::DateTime::parse_from_rfc3339("2012-12-19T22:00:00+00:00")
/// Mojank for some reason has versions released at the same DateTime. This hardcodes them to fix this,
/// as most of our ordering logic is with DateTime
static HALL_OF_SHAME_2: LazyLock<[(&'static str, DateTime<Utc>); 4]> =
LazyLock::new(|| {
[
(
"1.4.5",
chrono::DateTime::parse_from_rfc3339(
"2012-12-19T22:00:00+00:00",
)
.unwrap()
.into(),
),
(
"1.4.6",
chrono::DateTime::parse_from_rfc3339("2012-12-19T22:00:01+00:00")
),
(
"1.4.6",
chrono::DateTime::parse_from_rfc3339(
"2012-12-19T22:00:01+00:00",
)
.unwrap()
.into(),
),
(
"1.6.3",
chrono::DateTime::parse_from_rfc3339("2013-09-13T10:54:41+00:00")
),
(
"1.6.3",
chrono::DateTime::parse_from_rfc3339(
"2013-09-13T10:54:41+00:00",
)
.unwrap()
.into(),
),
(
"13w37b",
chrono::DateTime::parse_from_rfc3339("2013-09-13T10:54:42+00:00")
),
(
"13w37b",
chrono::DateTime::parse_from_rfc3339(
"2013-09-13T10:54:42+00:00",
)
.unwrap()
.into(),
),
];
}
),
]
});
for version in input.versions.into_iter() {
let mut name = version.id;

View File

@@ -117,11 +117,10 @@ impl GalleryItem {
}
}
#[derive(derive_new::new)]
pub struct ModCategory {
project_id: ProjectId,
category_id: CategoryId,
is_additional: bool,
pub project_id: ProjectId,
pub category_id: CategoryId,
pub is_additional: bool,
}
impl ModCategory {
@@ -245,12 +244,18 @@ impl ProjectBuilder {
let project_id = self.project_id;
let mod_categories = categories
.into_iter()
.map(|c| ModCategory::new(project_id, c, false))
.chain(
additional_categories
.into_iter()
.map(|c| ModCategory::new(project_id, c, true)),
)
.map(|category_id| ModCategory {
project_id,
category_id,
is_additional: false,
})
.chain(additional_categories.into_iter().map(|category_id| {
ModCategory {
project_id,
category_id,
is_additional: true,
}
}))
.collect_vec();
ModCategory::insert_many(mod_categories, &mut *transaction).await?;

View File

@@ -229,7 +229,10 @@ impl VersionBuilder {
let loader_versions = loaders
.iter()
.map(|l| LoaderVersion::new(*l, version_id))
.map(|&loader_id| LoaderVersion {
loader_id,
version_id,
})
.collect_vec();
LoaderVersion::insert_many(loader_versions, transaction).await?;
@@ -239,7 +242,7 @@ impl VersionBuilder {
}
}
#[derive(derive_new::new, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct LoaderVersion {
pub loader_id: LoaderId,
pub version_id: VersionId,

View File

@@ -152,7 +152,7 @@ async fn main() -> std::io::Result<()> {
.expect("Failed to register redis metrics");
#[cfg(target_os = "linux")]
labrinth::routes::debug::jemalloc_mmeory_stats(&prometheus.registry)
labrinth::routes::debug::jemalloc_memory_stats(&prometheus.registry)
.expect("Failed to register jemalloc metrics");
let labrinth_config = labrinth::app_setup(

View File

@@ -50,7 +50,7 @@ fn require_profiling_activated(
}
}
pub fn jemalloc_mmeory_stats(
pub fn jemalloc_memory_stats(
registry: &Registry,
) -> Result<(), prometheus::Error> {
let allocated_mem = IntGauge::new(

View File

@@ -13,7 +13,7 @@ use crate::util::captcha::check_hcaptcha;
use crate::util::env::parse_strings_from_var;
use crate::util::ext::get_image_ext;
use crate::util::img::upload_image_optimized;
use crate::util::validate::{RE_URL_SAFE, validation_errors_to_string};
use crate::util::validate::validation_errors_to_string;
use actix_web::web::{Data, Query, ServiceConfig, scope};
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
use argon2::password_hash::SaltString;
@@ -1318,7 +1318,7 @@ pub async fn sign_up_sendy(email: &str) -> Result<(), AuthenticationError> {
#[derive(Deserialize, Validate)]
pub struct NewAccount {
#[validate(length(min = 1, max = 39), regex(path = *RE_URL_SAFE))]
#[validate(length(min = 1, max = 39), regex(path = *crate::util::validate::RE_URL_SAFE))]
pub username: String,
#[validate(length(min = 8, max = 256))]
pub password: String,

View File

@@ -12,7 +12,7 @@ use crate::{auth::get_user_from_headers, database};
use actix_web::{HttpRequest, HttpResponse, get, route, web};
use sqlx::PgPool;
use std::collections::HashSet;
use yaserde_derive::YaSerialize;
use yaserde::YaSerialize;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(maven_metadata);

View File

@@ -9,8 +9,6 @@ use crate::models::v2::user::LegacyUser;
use crate::queue::session::AuthQueue;
use crate::routes::{ApiError, v2_reroute, v3};
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
use lazy_static::lazy_static;
use regex::Regex;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use std::sync::Arc;
@@ -135,20 +133,16 @@ pub async fn projects_list(
}
}
lazy_static! {
static ref RE_URL_SAFE: Regex = Regex::new(r"^[a-zA-Z0-9_-]*$").unwrap();
}
#[derive(Serialize, Deserialize, Validate)]
pub struct EditUser {
#[validate(length(min = 1, max = 39), regex(path = *RE_URL_SAFE))]
#[validate(length(min = 1, max = 39), regex(path = *crate::util::validate::RE_URL_SAFE))]
pub username: Option<String>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::double_option"
)]
#[validate(length(min = 1, max = 64), regex(path = *RE_URL_SAFE))]
#[validate(length(min = 1, max = 64), regex(path = *crate::util::validate::RE_URL_SAFE))]
pub name: Option<Option<String>>,
#[serde(
default,

View File

@@ -906,11 +906,11 @@ pub async fn edit_project_categories(
categories: &Vec<String>,
perms: &ProjectPermissions,
project_id: db_ids::ProjectId,
additional: bool,
is_additional: bool,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), ApiError> {
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
let additional_str = if additional { "additional " } else { "" };
let additional_str = if is_additional { "additional " } else { "" };
return Err(ApiError::CustomAuthentication(format!(
"You do not have the permissions to edit the {additional_str}categories of this project!"
)));
@@ -928,7 +928,11 @@ pub async fn edit_project_categories(
let mcategories = category_ids
.values()
.map(|x| ModCategory::new(project_id, *x, additional))
.map(|&category_id| ModCategory {
project_id,
category_id,
is_additional,
})
.collect::<Vec<_>>();
mod_categories.extend(mcategories);
}
@@ -1081,7 +1085,6 @@ pub async fn dependency_list(
}
}
#[derive(derive_new::new)]
pub struct CategoryChanges<'a> {
pub categories: &'a Option<Vec<String>>,
pub add_categories: &'a Option<Vec<String>>,
@@ -1241,11 +1244,11 @@ pub async fn projects_edit(
&categories,
&project.categories,
project.inner.id as db_ids::ProjectId,
CategoryChanges::new(
&bulk_edit_project.categories,
&bulk_edit_project.add_categories,
&bulk_edit_project.remove_categories,
),
CategoryChanges {
categories: &bulk_edit_project.categories,
add_categories: &bulk_edit_project.add_categories,
remove_categories: &bulk_edit_project.remove_categories,
},
3,
false,
&mut transaction,
@@ -1256,11 +1259,12 @@ pub async fn projects_edit(
&categories,
&project.additional_categories,
project.inner.id as db_ids::ProjectId,
CategoryChanges::new(
&bulk_edit_project.additional_categories,
&bulk_edit_project.add_additional_categories,
&bulk_edit_project.remove_additional_categories,
),
CategoryChanges {
categories: &bulk_edit_project.additional_categories,
add_categories: &bulk_edit_project.add_additional_categories,
remove_categories: &bulk_edit_project
.remove_additional_categories,
},
256,
true,
&mut transaction,
@@ -1383,11 +1387,11 @@ pub async fn bulk_edit_project_categories(
))
})?
.id;
mod_categories.push(ModCategory::new(
mod_categories.push(ModCategory {
project_id,
category_id,
is_additional,
));
});
}
ModCategory::insert_many(mod_categories, &mut *transaction).await?;
}

View File

@@ -1,8 +1,6 @@
use std::{collections::HashMap, sync::Arc};
use actix_web::{HttpRequest, HttpResponse, web};
use lazy_static::lazy_static;
use regex::Regex;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use validator::Validate;
@@ -358,13 +356,9 @@ pub async fn orgs_list(
}
}
lazy_static! {
static ref RE_URL_SAFE: Regex = Regex::new(r"^[a-zA-Z0-9_-]*$").unwrap();
}
#[derive(Serialize, Deserialize, Validate)]
pub struct EditUser {
#[validate(length(min = 1, max = 39), regex(path = *RE_URL_SAFE))]
#[validate(length(min = 1, max = 39), regex(path = *crate::util::validate::RE_URL_SAFE))]
pub username: Option<String>,
#[serde(
default,

View File

@@ -287,10 +287,10 @@ pub async fn version_edit_helper(
ApiError::Validation(validation_errors_to_string(err, None))
})?;
let version_id = info.0;
let id = version_id.into();
let version_id = info.0.into();
let result = database::models::Version::get(id, &**pool, &redis).await?;
let result =
database::models::Version::get(version_id, &**pool, &redis).await?;
if let Some(version_item) = result {
let team_member =
@@ -345,7 +345,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
name.trim(),
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -359,7 +359,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
number,
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -373,7 +373,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
version_type.as_str(),
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -384,7 +384,7 @@ pub async fn version_edit_helper(
"
DELETE FROM dependencies WHERE dependent_id = $1
",
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -448,7 +448,7 @@ pub async fn version_edit_helper(
WHERE version_id = $1
AND field_id = ANY($2)
",
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
&loader_field_ids
)
.execute(&mut *transaction)
@@ -476,7 +476,7 @@ pub async fn version_edit_helper(
.remove(&loader_field.id)
.unwrap_or_default();
let vf: VersionField = VersionField::check_parse(
version_id.into(),
version_id,
loader_field.clone(),
vf_value.clone(),
enum_variants,
@@ -493,7 +493,7 @@ pub async fn version_edit_helper(
"
DELETE FROM loaders_versions WHERE version_id = $1
",
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -513,7 +513,10 @@ pub async fn version_edit_helper(
.to_string(),
)
})?;
loader_versions.push(LoaderVersion::new(loader_id, id));
loader_versions.push(LoaderVersion {
loader_id,
version_id,
});
}
LoaderVersion::insert_many(loader_versions, &mut transaction)
.await?;
@@ -535,7 +538,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
featured,
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -549,7 +552,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
body,
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -569,7 +572,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
*downloads as i32,
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -604,7 +607,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
status.as_str(),
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;
@@ -652,7 +655,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
ordering.to_owned() as Option<i32>,
id as database::models::ids::VersionId,
version_id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
.await?;

View File

@@ -1,14 +1,13 @@
use std::sync::LazyLock;
use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
use validator::{ValidationErrors, ValidationErrorsKind};
use crate::models::pats::Scopes;
lazy_static! {
pub static ref RE_URL_SAFE: Regex =
Regex::new(r#"^[a-zA-Z0-9!@$()`.+,_"-]*$"#).unwrap();
}
pub static RE_URL_SAFE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z0-9_-]*$").unwrap());
//TODO: In order to ensure readability, only the first error is printed, this may need to be expanded on in the future!
pub fn validation_errors_to_string(