diff --git a/.idea/labrinth.iml b/.idea/labrinth.iml index 3f4390b52..5faf0f4e2 100644 --- a/.idea/labrinth.iml +++ b/.idea/labrinth.iml @@ -76,6 +76,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.rs b/build.rs index bf021783f..238813892 100644 --- a/build.rs +++ b/build.rs @@ -12,8 +12,7 @@ fn main() { } pub fn copy, V: AsRef>(from: U, to: V) -> Result<(), std::io::Error> { - let mut stack = Vec::new(); - stack.push(PathBuf::from(from.as_ref())); + let mut stack = vec![PathBuf::from(from.as_ref())]; let output_root = PathBuf::from(to.as_ref()); let input_root = PathBuf::from(from.as_ref()).components().count(); diff --git a/src/file_hosting/backblaze.rs b/src/file_hosting/backblaze.rs index 737a4c5ec..914b5f3a1 100644 --- a/src/file_hosting/backblaze.rs +++ b/src/file_hosting/backblaze.rs @@ -19,8 +19,8 @@ impl BackblazeHost { .unwrap(); BackblazeHost { - authorization_data, upload_url_data, + authorization_data, } } } diff --git a/src/routes/project_creation.rs b/src/routes/project_creation.rs index 24d48b652..3b64ec307 100644 --- a/src/routes/project_creation.rs +++ b/src/routes/project_creation.rs @@ -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, file_host: Data>, - indexing_queue: Data>, ) -> Result { 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, - indexing_queue: &CreationQueue, ) -> Result { // 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 diff --git a/src/routes/projects.rs b/src/routes/projects.rs index c4e52715c..9530f7443 100644 --- a/src/routes/projects.rs +++ b/src/routes/projects.rs @@ -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?; diff --git a/src/routes/v1/mods.rs b/src/routes/v1/mods.rs index 443062934..c6c458c94 100644 --- a/src/routes/v1/mods.rs +++ b/src/routes/v1/mods.rs @@ -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, file_host: Data>, - indexing_queue: Data>, ) -> Result { 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; diff --git a/src/util/webhook.rs b/src/util/webhook.rs index d617ea98a..51b289728 100644 --- a/src/util/webhook.rs +++ b/src/util/webhook.rs @@ -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/{}",