Support new delphi response type

This commit is contained in:
Jai A 2025-01-16 16:40:13 -08:00
parent 227386bb0d
commit 5c8e7a8b38
No known key found for this signature in database
GPG Key ID: 9A9F9B7250E9883C
5 changed files with 28 additions and 16 deletions

View File

@ -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>,

View File

@ -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<String>,
pub issues: HashMap<String, HashMap<String, String>>,
}
#[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![],

View File

@ -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(),

View File

@ -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<NewOAuthApp>,
pool: web::Data<PgPool>,
@ -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<ApiOAuthClientId>,
pool: web::Data<PgPool>,

View File

@ -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())
}