From 3839e79934a96118376e9fd7a868f90b93593a08 Mon Sep 17 00:00:00 2001 From: Roy <88516395+moraroy@users.noreply.github.com> Date: Tue, 10 Dec 2024 03:57:02 -0800 Subject: [PATCH] Update proxycache.py --- proxycache/proxycache.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/proxycache/proxycache.py b/proxycache/proxycache.py index d5f964b..be078fe 100644 --- a/proxycache/proxycache.py +++ b/proxycache/proxycache.py @@ -82,19 +82,35 @@ class ProxyCacheHandler(BaseHTTPRequestHandler): return if path_parts[1] == 'search': + # Handle search request: /search/ + if len(path_parts) < 3: + self.send_response(400) + self.end_headers() + self.wfile.write(b'Game name is required for search') + return + game_name = unquote(path_parts[2]) # Decode the URL-encoded game name self.handle_search(game_name) else: + # Handle artwork request: // if len(path_parts) < 4: self.send_response(400) self.end_headers() - self.wfile.write(b'Invalid request') + self.wfile.write(b'Invalid request: art type and game ID are required') return - art_type = path_parts[1] - game_id = path_parts[3] + art_type = path_parts[1] # art type (e.g., grid, cover, etc.) + game_id = path_parts[2] # game ID (e.g., 123456) dimensions = parse_qs(parsed_path.query).get('dimensions', [None])[0] + # Ensure that the art_type is valid + valid_art_types = ['grid', 'cover', 'banner', 'logo', 'icon'] + if art_type not in valid_art_types: + self.send_response(400) + self.end_headers() + self.wfile.write(b'Invalid art type') + return + logger.info(f"Art type: {art_type}") logger.info(f"Game ID: {game_id}") logger.info(f"Dimensions: {dimensions}") @@ -102,17 +118,18 @@ class ProxyCacheHandler(BaseHTTPRequestHandler): self.handle_artwork(game_id, art_type, dimensions) def do_HEAD(self): - self.do_GET() - self.send_response(200) + self.do_GET() + self.send_response(200) self.end_headers() logger.info(f"HEAD request handled for: {self.path}") def do_OPTIONS(self): self.send_response(200) # OK status - self.send_header('Allow', 'GET, POST, HEAD, OPTIONS') + self.send_header('Allow', 'GET, POST, HEAD, OPTIONS') self.end_headers() logger.info(f"OPTIONS request handled for: {self.path}") + def handle_search(self, game_name): logger.info(f"Searching for game ID for: {game_name}")