From ddcf30b38a4386abb6ed2655d925af169bca2cff Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 12 Dec 2023 15:56:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(s3):=20correct=20order=20of?= =?UTF-8?q?=20ifs,=20fixed=20parsing=20edgecases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imaginex_lambda/lib/img_lib.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imaginex_lambda/lib/img_lib.py b/imaginex_lambda/lib/img_lib.py index fd92803..efc5e4a 100644 --- a/imaginex_lambda/lib/img_lib.py +++ b/imaginex_lambda/lib/img_lib.py @@ -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)