Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/endpoints/mod_version_submissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,12 @@ pub async fn upload_attachments(
for webp_bytes in &processed {
let filename = data
.public_storage()
.store_hashed("submission-attachments", webp_bytes, Some("webp"))
.store_hashed(
"submission-attachments",
webp_bytes,
Some("webp"),
"image/webp",
)
.await?;
stored_filenames.push(filename.clone());
let row =
Expand Down
8 changes: 5 additions & 3 deletions src/s3_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn migrate_geode_version_opt(
let bytes = resp.error_for_status()?.bytes().await?;
let public_url = storage.asset_url(&new_path);
let hash = sha256::digest(&bytes[..]);
storage.store(&new_path, &bytes).await?;
storage.store(&new_path, &bytes, "application/zip").await?;

if platform == "resources" {
update_resources_download(tag, &public_url, &hash, db).await?;
Expand Down Expand Up @@ -132,7 +132,7 @@ async fn upload_mod_logo(
};

if let Some(logo_bytes) = current_logo {
storage.store(&logo_path, &logo_bytes).await?;
storage.store(&logo_path, &logo_bytes, "image/png").await?;

update_mod_logo_url(mod_id, &logo_public_url, db).await?;

Expand Down Expand Up @@ -160,7 +160,9 @@ async fn process_task(
let path = path_for_mod(&mod_id, &version);
let public_url = storage.asset_url(&path);

storage.store(&path, &bytes).await?;
storage
.store(&path, &bytes, "application/octet-stream")
.await?;

update_managed_download_link(version_id, Some(&public_url), &mut db).await?;

Expand Down
1 change: 1 addition & 0 deletions src/storage/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl StorageBackend for LocalBackend {
&'a self,
relative_path: &'a str,
data: &'a [u8],
_mime_type: &'a str,
) -> BoxFuture<'a, StorageResult<()>> {
Box::pin(async move {
let path = self.safe_join(relative_path)?;
Expand Down
32 changes: 22 additions & 10 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ pub trait StorageBackend: Send + Sync {
fn init(&self) -> BoxFuture<'_, StorageResult<()>> {
Box::pin(async { Ok(()) })
}
fn store<'a>(&'a self, path: &'a str, data: &'a [u8]) -> BoxFuture<'a, StorageResult<()>>;
fn store<'a>(
&'a self,
path: &'a str,
data: &'a [u8],
mime_type: &'a str,
) -> BoxFuture<'a, StorageResult<()>>;
fn read<'a>(&'a self, path: &'a str) -> BoxFuture<'a, StorageResult<Vec<u8>>>;
#[allow(dead_code)]
fn exists<'a>(&'a self, path: &'a str) -> BoxFuture<'a, StorageResult<bool>>;
Expand All @@ -44,6 +49,7 @@ impl DiskCore {
relative_path: &str,
data: &[u8],
extension: Option<&str>,
mime_type: &str,
) -> StorageResult<String> {
let hash = sha256::digest(data);

Expand All @@ -57,11 +63,11 @@ impl DiskCore {
ext.trim_start_matches('.')
))
);
self.store(&hashed_path, data).await?;
self.store(&hashed_path, data, mime_type).await?;
Ok(hashed_path)
}
pub async fn store(&self, path: &str, data: &[u8]) -> StorageResult<()> {
self.backend.store(path, data).await
pub async fn store(&self, path: &str, data: &[u8], mime_type: &str) -> StorageResult<()> {
self.backend.store(path, data, mime_type).await
}
pub async fn read(&self, path: &str) -> StorageResult<Vec<u8>> {
self.backend.read(path).await
Expand Down Expand Up @@ -98,11 +104,14 @@ impl PublicDisk {
relative_path: &str,
data: &[u8],
extension: Option<&str>,
mime_type: &str,
) -> StorageResult<String> {
self.core.store_hashed(relative_path, data, extension).await
self.core
.store_hashed(relative_path, data, extension, mime_type)
.await
}
pub async fn store(&self, path: &str, data: &[u8]) -> StorageResult<()> {
self.core.store(path, data).await
pub async fn store(&self, path: &str, data: &[u8], mime_type: &str) -> StorageResult<()> {
self.core.store(path, data, mime_type).await
}
pub async fn read(&self, path: &str) -> StorageResult<Vec<u8>> {
self.core.read(path).await
Expand Down Expand Up @@ -136,12 +145,15 @@ impl PrivateDisk {
relative_path: &str,
data: &[u8],
extension: Option<&str>,
mime_type: &str,
) -> StorageResult<String> {
self.core.store_hashed(relative_path, data, extension).await
self.core
.store_hashed(relative_path, data, extension, mime_type)
.await
}
#[allow(dead_code)]
pub async fn store(&self, path: &str, data: &[u8]) -> StorageResult<()> {
self.core.store(path, data).await
pub async fn store(&self, path: &str, data: &[u8], mime_type: &str) -> StorageResult<()> {
self.core.store(path, data, mime_type).await
}
#[allow(dead_code)]
pub async fn read(&self, path: &str) -> StorageResult<Vec<u8>> {
Expand Down
6 changes: 5 additions & 1 deletion src/storage/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ impl StorageBackend for S3Backend {
&'a self,
relative_path: &'a str,
data: &'a [u8],
mime_type: &'a str,
) -> BoxFuture<'a, StorageResult<()>> {
Box::pin(async move {
let _ = self.bucket.put_object(relative_path, data).await?;
let _ = self
.bucket
.put_object_with_content_type(relative_path, data, mime_type)
.await?;
Ok(())
})
}
Expand Down
Loading