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
105 changes: 82 additions & 23 deletions Cargo.lock
Comment thread
sentry-junior[bot] marked this conversation as resolved.
Resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ java-properties = "2.0.0"
lazy_static = "1.4.0"
libc = "0.2.139"
log = { version = "0.4.17", features = ["std"] }
objectstore-client = { version = "0.1.12" , default-features = false, features = ["native-tls"] }
objectstore-client = { version = "0.3.2", default-features = false, features = ["native-tls"] }
open = "3.2.0"
parking_lot = "0.12.1"
percent-encoding = "2.2.0"
Expand Down
40 changes: 28 additions & 12 deletions src/commands/snapshots/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ fn is_image_file(path: &Path) -> bool {
.unwrap_or(false)
}

/// Returns the MIME type of an image based on its file extension.
fn image_content_type(path: &Path) -> Option<&'static str> {
let ext = path.extension()?.to_str()?;
if ext.eq_ignore_ascii_case("png") {
Some("image/png")
} else if ext.eq_ignore_ascii_case("jpg") || ext.eq_ignore_ascii_case("jpeg") {
Some("image/jpeg")
} else {
None
}
}

/// Reads the companion JSON sidecar for an image, if it exists.
///
/// For an image at `path/to/button.png`, looks for `path/to/button.json`.
Expand Down Expand Up @@ -425,11 +437,9 @@ fn upload_images(
let expiration = ExpirationPolicy::from_str(&options.objectstore.expiration_policy)
.context("Failed to parse expiration policy from upload options")?;

let mut builder = ClientBuilder::new(options.objectstore.url);
if let Some(token) = options.objectstore.auth_token {
builder = builder.token(token.expose_secret().to_owned());
}
let client = builder
let auth_token = options.objectstore.auth_token.as_ref();
let client = ClientBuilder::new(options.objectstore.url)
.token(auth_token.map(|token| token.expose_secret().as_str()))
.configure_reqwest(|r| r.connect_timeout(Duration::from_secs(10)))
.build()?;

Expand All @@ -445,7 +455,9 @@ fn upload_images(
let project_id = find_scope("project").context("Missing project in UploadOptions scope")?;

debug!("Using objectstore usecase {}", options.objectstore.usecase);
let mut scope = Usecase::new(&options.objectstore.usecase).scope();
let mut scope = Usecase::new(&options.objectstore.usecase)
.context("Invalid objectstore usecase in upload options")?
.scope();
for (key, value) in scopes {
scope = scope.push(&key, value);
}
Expand Down Expand Up @@ -538,12 +550,16 @@ fn upload_images(
if upload_count > 0 {
let mut many_builder = session.many();
for prepared in missing_uploads {
many_builder = many_builder.push(
session
.put_path(prepared.path.clone())
.key(&prepared.key)
.expiration_policy(expiration),
);
// Images are already compressed, so skip client-side compression.
let mut put = session
.put_path(prepared.path.clone())
.key(&prepared.key)
.expiration_policy(expiration)
.compress(None);
if let Some(content_type) = image_content_type(&prepared.path) {
put = put.content_type(content_type);
}
many_builder = many_builder.push(put);
}

let result =
Expand Down
Loading
Loading