diff --git a/.env b/.env index f8e9b927..14b7aa23 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ DEBUG=true RUST_LOG=info,sqlx::query=warn SITE_URL=https://modrinth.com -CDN_URL=https://cdn.modrinth.com +CDN_URL=https://staging-cdn.modrinth.com LABRINTH_ADMIN_KEY=feedbeef RATE_LIMIT_IGNORE_KEY=feedbeef diff --git a/src/file_hosting/s3_host.rs b/src/file_hosting/s3_host.rs index e677f261..eaba327b 100644 --- a/src/file_hosting/s3_host.rs +++ b/src/file_hosting/s3_host.rs @@ -46,8 +46,6 @@ impl S3Host { ) })?; - bucket.add_header("x-amz-acl", "public-read"); - Ok(S3Host { bucket }) } } diff --git a/src/routes/projects.rs b/src/routes/projects.rs index d8c123d5..99760799 100644 --- a/src/routes/projects.rs +++ b/src/routes/projects.rs @@ -1046,7 +1046,7 @@ pub async fn project_icon_edit( } if let Some(icon) = project_item.icon_url { - let name = icon.split('/').next(); + let name = icon.split(&format!("{cdn_url}/")).nth(1); if let Some(icon_path) = name { file_host.delete_file_version("", icon_path).await?; @@ -1136,8 +1136,9 @@ pub async fn delete_project_icon( } } + let cdn_url = dotenv::var("CDN_URL")?; if let Some(icon) = project_item.icon_url { - let name = icon.split('/').next(); + let name = icon.split(&format!("{cdn_url}/")).nth(1); if let Some(icon_path) = name { file_host.delete_file_version("", icon_path).await?; @@ -1489,10 +1490,11 @@ pub async fn delete_gallery_item( })? .id; - let name = item.url.split('/').next(); + let cdn_url = dotenv::var("CDN_URL")?; + let name = item.url.split(&format!("{cdn_url}/")).nth(1); - if let Some(item_path) = name { - file_host.delete_file_version("", item_path).await?; + if let Some(icon_path) = name { + file_host.delete_file_version("", icon_path).await?; } let mut transaction = pool.begin().await?; diff --git a/src/routes/users.rs b/src/routes/users.rs index 43c4e33a..cccf653c 100644 --- a/src/routes/users.rs +++ b/src/routes/users.rs @@ -360,12 +360,10 @@ pub async fn user_icon_edit( } if let Some(icon) = icon_url { - if icon.starts_with(&cdn_url) { - let name = icon.split('/').next(); + let name = icon.split(&format!("{cdn_url}/")).nth(1); - if let Some(icon_path) = name { - file_host.delete_file_version("", icon_path).await?; - } + if let Some(icon_path) = name { + file_host.delete_file_version("", icon_path).await?; } } diff --git a/src/routes/v1/versions.rs b/src/routes/v1/versions.rs index 04a4420a..591a3af3 100644 --- a/src/routes/v1/versions.rs +++ b/src/routes/v1/versions.rs @@ -357,18 +357,6 @@ pub async fn delete_file( .execute(&mut *transaction) .await?; - let project_id: models::projects::ProjectId = - database::models::ids::ProjectId(row.project_id).into(); - file_host - .delete_file_version( - "", - &format!( - "data/{}/versions/{}/{}", - project_id, row.version_number, row.filename - ), - ) - .await?; - transaction.commit().await?; Ok(HttpResponse::NoContent().body("")) diff --git a/src/routes/version_file.rs b/src/routes/version_file.rs index c1044e93..3651a894 100644 --- a/src/routes/version_file.rs +++ b/src/routes/version_file.rs @@ -206,18 +206,6 @@ pub async fn delete_file( .execute(&mut *transaction) .await?; - let project_id: models::projects::ProjectId = - database::models::ids::ProjectId(row.project_id).into(); - file_host - .delete_file_version( - "", - &format!( - "data/{}/versions/{}/{}", - project_id, row.version_number, row.filename - ), - ) - .await?; - transaction.commit().await?; Ok(HttpResponse::NoContent().body(""))