You've already forked AstralRinth
forked from didirus/AstralRinth
Support new delphi response type
This commit is contained in:
@@ -405,7 +405,7 @@ impl TeamMember {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete<'a, 'b>(
|
pub async fn delete(
|
||||||
id: TeamId,
|
id: TeamId,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ pub struct DelphiIngest {
|
|||||||
pub url: String,
|
pub url: String,
|
||||||
pub project_id: crate::models::ids::ProjectId,
|
pub project_id: crate::models::ids::ProjectId,
|
||||||
pub version_id: crate::models::ids::VersionId,
|
pub version_id: crate::models::ids::VersionId,
|
||||||
pub issues: Vec<String>,
|
pub issues: HashMap<String, HashMap<String, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_delphi", guard = "admin_key_guard")]
|
#[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(
|
crate::util::webhook::send_slack_webhook(
|
||||||
body.project_id,
|
body.project_id,
|
||||||
&pool,
|
&pool,
|
||||||
&redis,
|
&redis,
|
||||||
webhook_url,
|
webhook_url,
|
||||||
Some(format!(
|
Some(header),
|
||||||
"Suspicious traces found at {}. Traces: {}",
|
|
||||||
body.url,
|
|
||||||
body.issues.join(", ")
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.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?;
|
let mut transaction = pool.begin().await?;
|
||||||
ThreadMessageBuilder {
|
ThreadMessageBuilder {
|
||||||
author_id: Some(crate::database::models::UserId(AUTOMOD_ID)),
|
author_id: Some(crate::database::models::UserId(AUTOMOD_ID)),
|
||||||
body: MessageBody::Text {
|
body: MessageBody::Text {
|
||||||
body: format!(
|
body: thread_header,
|
||||||
"WSR; Suspicious traces found for version_id {}. Traces: {}",
|
|
||||||
body.version_id,
|
|
||||||
body.issues.join(", ")
|
|
||||||
),
|
|
||||||
private: true,
|
private: true,
|
||||||
replying_to: None,
|
replying_to: None,
|
||||||
associated_images: vec![],
|
associated_images: vec![],
|
||||||
|
|||||||
@@ -884,7 +884,7 @@ pub async fn active_servers(
|
|||||||
.head()
|
.head()
|
||||||
.headers()
|
.headers()
|
||||||
.get("X-Master-Key")
|
.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(
|
return Err(ApiError::CustomAuthentication(
|
||||||
"Invalid master key".to_string(),
|
"Invalid master key".to_string(),
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ pub struct NewOAuthApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("app")]
|
#[post("app")]
|
||||||
pub async fn oauth_client_create<'a>(
|
pub async fn oauth_client_create(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
new_oauth_app: web::Json<NewOAuthApp>,
|
new_oauth_app: web::Json<NewOAuthApp>,
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
@@ -221,7 +221,7 @@ pub async fn oauth_client_create<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[delete("app/{id}")]
|
#[delete("app/{id}")]
|
||||||
pub async fn oauth_client_delete<'a>(
|
pub async fn oauth_client_delete(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
client_id: web::Path<ApiOAuthClientId>,
|
client_id: web::Path<ApiOAuthClientId>,
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ pub fn admin_key_guard(ctx: &GuardContext) -> bool {
|
|||||||
ctx.head()
|
ctx.head()
|
||||||
.headers()
|
.headers()
|
||||||
.get(ADMIN_KEY_HEADER)
|
.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())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user