Skip to content

Commit

Permalink
Fix integration with backblaze API (#461)
Browse files Browse the repository at this point in the history
* Fix integration with backblaze API

* Remove keys (already reset, dw)
  • Loading branch information
Geometrically committed Oct 10, 2022
1 parent 3e52f80 commit 07edb99
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .env
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/file_hosting/s3_host.rs
Expand Up @@ -46,8 +46,6 @@ impl S3Host {
)
})?;

bucket.add_header("x-amz-acl", "public-read");

Ok(S3Host { bucket })
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/routes/projects.rs
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
8 changes: 3 additions & 5 deletions src/routes/users.rs
Expand Up @@ -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?;
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/routes/v1/versions.rs
Expand Up @@ -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(""))
Expand Down
12 changes: 0 additions & 12 deletions src/routes/version_file.rs
Expand Up @@ -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(""))
Expand Down

0 comments on commit 07edb99

Please sign in to comment.