From 8ba5bb7f94a2359e8ce1a1840db650dc6b664778 Mon Sep 17 00:00:00 2001 From: Roy <88516395+moraroy@users.noreply.github.com> Date: Tue, 10 Dec 2024 04:20:52 -0800 Subject: [PATCH] Update proxycache.py --- proxycache/proxycache.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/proxycache/proxycache.py b/proxycache/proxycache.py index 6f41386..6658c2f 100644 --- a/proxycache/proxycache.py +++ b/proxycache/proxycache.py @@ -177,7 +177,22 @@ def handle_artwork(self, game_id, art_type, dimensions): logger.info(f"Sending request to: {url}") response = limited_request(url, headers) data = response.json() - api_cache[cache_key] = {'data': data, 'timestamp': datetime.now()} + + # Check for image quality, dimension, or alternate style information and store all metadata + artwork_data = { + 'images': [{ + 'url': image['url'], + 'width': image.get('width'), + 'height': image.get('height'), + 'style': image.get('style', 'default'), + } for image in data.get('data', [])], + 'other_metadata': { + 'image_quality': data.get('quality', 'high'), + 'last_updated': data.get('last_updated', str(datetime.now())), + } + } + + api_cache[cache_key] = {'data': artwork_data, 'timestamp': datetime.now()} logger.info(f"Storing in cache: {cache_key}") except Exception as e: logger.error(f"Error making API call: {e}") @@ -190,8 +205,16 @@ def handle_artwork(self, game_id, art_type, dimensions): self.send_response(500) self.end_headers() self.wfile.write(b'Invalid response from API') + logger.error(f"Artwork for Game ID {game_id} ({art_type}) with dimensions {dimensions} not found. Error: No 'data' in response.") return + # Log why artwork wasn't found (if any) + if not data.get('data', []): + logger.error(f"Artwork for Game ID {game_id} ({art_type}) with dimensions {dimensions} not found. Error: No artwork data.") + self.send_response(404) + self.end_headers() + self.wfile.write(b'Artwork not found') + self.send_response(200) self.end_headers() self.wfile.write(json.dumps(data).encode())