From 5c8e7a8b3898250451dafba9fe80cf6b563b71c1 Mon Sep 17 00:00:00 2001 From: Jai A Date: Thu, 16 Jan 2025 16:40:13 -0800 Subject: [PATCH] Support new delphi response type --- .../labrinth/src/database/models/team_item.rs | 2 +- apps/labrinth/src/routes/internal/admin.rs | 34 +++++++++++++------ apps/labrinth/src/routes/internal/billing.rs | 2 +- apps/labrinth/src/routes/v3/oauth_clients.rs | 4 +-- apps/labrinth/src/util/guards.rs | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/labrinth/src/database/models/team_item.rs b/apps/labrinth/src/database/models/team_item.rs index 8f6f811ef..d343596cf 100644 --- a/apps/labrinth/src/database/models/team_item.rs +++ b/apps/labrinth/src/database/models/team_item.rs @@ -405,7 +405,7 @@ impl TeamMember { Ok(()) } - pub async fn delete<'a, 'b>( + pub async fn delete( id: TeamId, user_id: UserId, transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>, diff --git a/apps/labrinth/src/routes/internal/admin.rs b/apps/labrinth/src/routes/internal/admin.rs index e983bae84..f52667d9a 100644 --- a/apps/labrinth/src/routes/internal/admin.rs +++ b/apps/labrinth/src/routes/internal/admin.rs @@ -189,7 +189,7 @@ pub struct DelphiIngest { pub url: String, pub project_id: crate::models::ids::ProjectId, pub version_id: crate::models::ids::VersionId, - pub issues: Vec, + pub issues: HashMap>, } #[post("/_delphi", guard = "admin_key_guard")] @@ -218,29 +218,41 @@ pub async fn delphi_result_ingest( )) })?; + let mut header = format!("Suspicious traces found at {}", body.url); + + for (issue, trace) in &body.issues { + for (path, code) in trace { + header.push_str(&format!( + "\n issue {issue} found at file {}: \n ```\n{}\n```", + path, code + )); + } + } + crate::util::webhook::send_slack_webhook( body.project_id, &pool, &redis, webhook_url, - Some(format!( - "Suspicious traces found at {}. Traces: {}", - body.url, - body.issues.join(", ") - )), + Some(header), ) .await .ok(); + let mut thread_header = format!("Suspicious traces found at [version {}](https://modrinth.com/project/{}/version/{})", body.version_id, body.project_id, body.version_id); + + for (issue, trace) in &body.issues { + for path in trace.keys() { + thread_header + .push_str(&format!("\n issue {issue} found at file {}", path)); + } + } + let mut transaction = pool.begin().await?; ThreadMessageBuilder { author_id: Some(crate::database::models::UserId(AUTOMOD_ID)), body: MessageBody::Text { - body: format!( - "WSR; Suspicious traces found for version_id {}. Traces: {}", - body.version_id, - body.issues.join(", ") - ), + body: thread_header, private: true, replying_to: None, associated_images: vec![], diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index 38a130c59..8d313a4dc 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -884,7 +884,7 @@ pub async fn active_servers( .head() .headers() .get("X-Master-Key") - .map_or(false, |it| it.as_bytes() == master_key.as_bytes()) + .is_some_and(|it| it.as_bytes() == master_key.as_bytes()) { return Err(ApiError::CustomAuthentication( "Invalid master key".to_string(), diff --git a/apps/labrinth/src/routes/v3/oauth_clients.rs b/apps/labrinth/src/routes/v3/oauth_clients.rs index a65dcc75d..3a9648f9f 100644 --- a/apps/labrinth/src/routes/v3/oauth_clients.rs +++ b/apps/labrinth/src/routes/v3/oauth_clients.rs @@ -160,7 +160,7 @@ pub struct NewOAuthApp { } #[post("app")] -pub async fn oauth_client_create<'a>( +pub async fn oauth_client_create( req: HttpRequest, new_oauth_app: web::Json, pool: web::Data, @@ -221,7 +221,7 @@ pub async fn oauth_client_create<'a>( } #[delete("app/{id}")] -pub async fn oauth_client_delete<'a>( +pub async fn oauth_client_delete( req: HttpRequest, client_id: web::Path, pool: web::Data, diff --git a/apps/labrinth/src/util/guards.rs b/apps/labrinth/src/util/guards.rs index f7ad43ccf..e6401fa4f 100644 --- a/apps/labrinth/src/util/guards.rs +++ b/apps/labrinth/src/util/guards.rs @@ -8,5 +8,5 @@ pub fn admin_key_guard(ctx: &GuardContext) -> bool { ctx.head() .headers() .get(ADMIN_KEY_HEADER) - .map_or(false, |it| it.as_bytes() == admin_key.as_bytes()) + .is_some_and(|it| it.as_bytes() == admin_key.as_bytes()) }