You've already forked AstralRinth
forked from didirus/AstralRinth
Add delphi integration, fix search showing plugins
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||
use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::analytics::Download;
|
||||
use crate::models::ids::ProjectId;
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::threads::MessageBody;
|
||||
use crate::queue::analytics::AnalyticsQueue;
|
||||
use crate::queue::maxmind::MaxMindIndexer;
|
||||
use crate::queue::moderation::AUTOMOD_ID;
|
||||
use crate::queue::payouts::PayoutsQueue;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
@@ -23,7 +26,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
web::scope("admin")
|
||||
.service(count_download)
|
||||
.service(force_reindex)
|
||||
.service(get_balances),
|
||||
.service(get_balances)
|
||||
.service(delphi_result_ingest),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,3 +182,70 @@ pub async fn get_balances(
|
||||
"tremendous": tremendous,
|
||||
})))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DelphiIngest {
|
||||
pub url: String,
|
||||
pub project_id: crate::models::ids::ProjectId,
|
||||
pub version_id: crate::models::ids::VersionId,
|
||||
pub issues: Vec<String>,
|
||||
}
|
||||
|
||||
#[post("/_delphi", guard = "admin_key_guard")]
|
||||
pub async fn delphi_result_ingest(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
body: web::Json<DelphiIngest>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let webhook_url = dotenvy::var("DELPHI_SLACK_WEBHOOK")?;
|
||||
|
||||
let project = crate::database::models::Project::get_id(
|
||||
body.project_id.into(),
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Project {} does not exist",
|
||||
body.project_id
|
||||
))
|
||||
})?;
|
||||
|
||||
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(", ")
|
||||
)),
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
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(", ")
|
||||
),
|
||||
private: true,
|
||||
replying_to: None,
|
||||
associated_images: vec![],
|
||||
},
|
||||
thread_id: project.thread_id,
|
||||
hide_identity: false,
|
||||
}
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user