Skip to content

Commit

Permalink
🐛 fix(s3): correct order of ifs, fixed parsing edgecases
Browse files Browse the repository at this point in the history
  • Loading branch information
sladg committed Dec 12, 2023
1 parent c620bba commit ddcf30b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions imaginex_lambda/lib/img_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ def download_and_optimize(url: str,
raise HandlerError('height must be greater than zero')

with TemporaryFile() as buffer:
if is_absolute(url):
buffer, _ = download_image(buffer, url, chunk_size)
if is_s3(url):
bucket_name, key = unquote(url).replace('s3://', '').split('/', 1)
buffer, _ = get_s3_image(buffer, bucket_name, key, chunk_size)
dynamic_bucket, key = unquote(url).replace('s3://', '').split('/', 1)
logger.info("Dynamic bucket: %s", dynamic_bucket)
buffer, _ = get_s3_image(buffer, dynamic_bucket, key, chunk_size)
elif is_absolute(url):
buffer, _ = download_image(buffer, url, chunk_size)
else:
key = url.strip('/')
buffer, _ = get_s3_image(buffer, bucket_name, key, chunk_size)
Expand Down

0 comments on commit ddcf30b

Please sign in to comment.