You've already forked AstralRinth
forked from didirus/AstralRinth
Fix caching bug, and moderation webhook being sent at the wrong time (#215)
This commit is contained in:
@@ -19,8 +19,8 @@ impl BackblazeHost {
|
||||
.unwrap();
|
||||
|
||||
BackblazeHost {
|
||||
authorization_data,
|
||||
upload_url_data,
|
||||
authorization_data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::models::projects::{
|
||||
};
|
||||
use crate::models::users::UserId;
|
||||
use crate::routes::version_creation::InitialVersionData;
|
||||
use crate::search::indexing::{queue::CreationQueue, IndexingError};
|
||||
use crate::search::indexing::IndexingError;
|
||||
use crate::util::auth::{get_user_from_headers, AuthenticationError};
|
||||
use crate::util::validate::validation_errors_to_string;
|
||||
use actix_multipart::{Field, Multipart};
|
||||
@@ -207,7 +207,6 @@ pub async fn project_create(
|
||||
payload: Multipart,
|
||||
client: Data<PgPool>,
|
||||
file_host: Data<Arc<dyn FileHost + Send + Sync>>,
|
||||
indexing_queue: Data<Arc<CreationQueue>>,
|
||||
) -> Result<HttpResponse, CreateError> {
|
||||
let mut transaction = client.begin().await?;
|
||||
let mut uploaded_files = Vec::new();
|
||||
@@ -218,7 +217,6 @@ pub async fn project_create(
|
||||
&mut transaction,
|
||||
&***file_host,
|
||||
&mut uploaded_files,
|
||||
&***indexing_queue,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -275,7 +273,6 @@ pub async fn project_create_inner(
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
file_host: &dyn FileHost,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
indexing_queue: &CreationQueue,
|
||||
) -> Result<HttpResponse, CreateError> {
|
||||
// The base URL for files uploaded to backblaze
|
||||
let cdn_url = dotenv::var("CDN_URL")?;
|
||||
@@ -623,14 +620,7 @@ pub async fn project_create_inner(
|
||||
|
||||
let _project_id = project_builder.insert(&mut *transaction).await?;
|
||||
|
||||
if status.is_searchable() {
|
||||
let index_project = crate::search::indexing::local_import::query_one(
|
||||
project_id.into(),
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
indexing_queue.add(index_project);
|
||||
|
||||
if status == ProjectStatus::Processing {
|
||||
if let Ok(webhook_url) = dotenv::var("MODERATION_DISCORD_WEBHOOK") {
|
||||
crate::util::webhook::send_discord_webhook(response.clone(), webhook_url)
|
||||
.await
|
||||
|
||||
@@ -500,6 +500,15 @@ pub async fn project_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
if let Ok(webhook_url) = dotenv::var("MODERATION_DISCORD_WEBHOOK") {
|
||||
crate::util::webhook::send_discord_webhook(
|
||||
convert_project(project_item.clone()),
|
||||
webhook_url,
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
if project_item.status.is_searchable() && !status.is_searchable() {
|
||||
@@ -510,15 +519,6 @@ pub async fn project_edit(
|
||||
.await?;
|
||||
|
||||
indexing_queue.add(index_project);
|
||||
|
||||
if let Ok(webhook_url) = dotenv::var("MODERATION_DISCORD_WEBHOOK") {
|
||||
crate::util::webhook::send_discord_webhook(
|
||||
convert_project(project_item.clone()),
|
||||
webhook_url,
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,8 +901,14 @@ pub async fn project_edit(
|
||||
.await?;
|
||||
}
|
||||
|
||||
remove_cache_project(string.clone()).await;
|
||||
remove_cache_query_project(string).await;
|
||||
let id: ProjectId = project_item.inner.id.into();
|
||||
remove_cache_project(id.to_string().clone()).await;
|
||||
remove_cache_query_project(id.to_string()).await;
|
||||
|
||||
if let Some(slug) = project_item.inner.slug {
|
||||
remove_cache_project(slug.clone()).await;
|
||||
remove_cache_query_project(slug).await;
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -1006,8 +1012,14 @@ pub async fn project_icon_edit(
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
|
||||
remove_cache_project(string.clone()).await;
|
||||
remove_cache_query_project(string).await;
|
||||
let id: ProjectId = project_item.id.into();
|
||||
remove_cache_project(id.to_string().clone()).await;
|
||||
remove_cache_query_project(id.to_string()).await;
|
||||
|
||||
if let Some(slug) = project_item.slug {
|
||||
remove_cache_project(slug.clone()).await;
|
||||
remove_cache_query_project(slug).await;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
@@ -1060,8 +1072,14 @@ pub async fn project_delete(
|
||||
|
||||
let result = database::models::Project::remove_full(project.id, &mut transaction).await?;
|
||||
|
||||
remove_cache_project(string.clone()).await;
|
||||
remove_cache_query_project(string).await;
|
||||
let id: ProjectId = project.id.into();
|
||||
remove_cache_project(id.to_string().clone()).await;
|
||||
remove_cache_query_project(id.to_string()).await;
|
||||
|
||||
if let Some(slug) = project.slug {
|
||||
remove_cache_project(slug.clone()).await;
|
||||
remove_cache_query_project(slug).await;
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::models::projects::SearchRequest;
|
||||
use crate::routes::project_creation::{project_create_inner, undo_uploads, CreateError};
|
||||
use crate::routes::projects::{convert_project, ProjectIds};
|
||||
use crate::routes::ApiError;
|
||||
use crate::search::indexing::queue::CreationQueue;
|
||||
use crate::search::{search_for_project, SearchConfig, SearchError};
|
||||
use crate::util::auth::get_user_from_headers;
|
||||
use crate::{database, models};
|
||||
@@ -139,7 +138,6 @@ pub async fn mod_create(
|
||||
payload: Multipart,
|
||||
client: Data<PgPool>,
|
||||
file_host: Data<Arc<dyn FileHost + Send + Sync>>,
|
||||
indexing_queue: Data<Arc<CreationQueue>>,
|
||||
) -> Result<HttpResponse, CreateError> {
|
||||
let mut transaction = client.begin().await?;
|
||||
let mut uploaded_files = Vec::new();
|
||||
@@ -150,7 +148,6 @@ pub async fn mod_create(
|
||||
&mut transaction,
|
||||
&***file_host,
|
||||
&mut uploaded_files,
|
||||
&***indexing_queue,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -34,13 +34,33 @@ pub async fn send_discord_webhook(
|
||||
project: Project,
|
||||
webhook_url: String,
|
||||
) -> Result<(), reqwest::Error> {
|
||||
let mut fields = Vec::new();
|
||||
|
||||
fields.push(DiscordEmbedField {
|
||||
name: "id".to_string(),
|
||||
value: project.id.to_string(),
|
||||
inline: true,
|
||||
});
|
||||
let mut fields = vec![
|
||||
DiscordEmbedField {
|
||||
name: "id".to_string(),
|
||||
value: project.id.to_string(),
|
||||
inline: true,
|
||||
},
|
||||
DiscordEmbedField {
|
||||
name: "project_type".to_string(),
|
||||
value: project.project_type.to_string(),
|
||||
inline: true,
|
||||
},
|
||||
DiscordEmbedField {
|
||||
name: "client_side".to_string(),
|
||||
value: project.client_side.to_string(),
|
||||
inline: true,
|
||||
},
|
||||
DiscordEmbedField {
|
||||
name: "server_side".to_string(),
|
||||
value: project.server_side.to_string(),
|
||||
inline: true,
|
||||
},
|
||||
DiscordEmbedField {
|
||||
name: "categories".to_string(),
|
||||
value: project.categories.join(", "),
|
||||
inline: true,
|
||||
},
|
||||
];
|
||||
|
||||
if let Some(slug) = project.slug.clone() {
|
||||
fields.push(DiscordEmbedField {
|
||||
@@ -50,30 +70,6 @@ pub async fn send_discord_webhook(
|
||||
});
|
||||
}
|
||||
|
||||
fields.push(DiscordEmbedField {
|
||||
name: "project_type".to_string(),
|
||||
value: project.project_type.to_string(),
|
||||
inline: true,
|
||||
});
|
||||
|
||||
fields.push(DiscordEmbedField {
|
||||
name: "client_side".to_string(),
|
||||
value: project.client_side.to_string(),
|
||||
inline: true,
|
||||
});
|
||||
|
||||
fields.push(DiscordEmbedField {
|
||||
name: "server_side".to_string(),
|
||||
value: project.server_side.to_string(),
|
||||
inline: true,
|
||||
});
|
||||
|
||||
fields.push(DiscordEmbedField {
|
||||
name: "categories".to_string(),
|
||||
value: project.categories.join(", "),
|
||||
inline: true,
|
||||
});
|
||||
|
||||
let embed = DiscordEmbed {
|
||||
url: format!(
|
||||
"{}/mod/{}",
|
||||
|
||||
Reference in New Issue
Block a user