From e8ff476a107dad0ddc53f0199d97206775ce5bd8 Mon Sep 17 00:00:00 2001 From: Zach Keatings Date: Thu, 8 Jan 2026 20:43:14 -0500 Subject: [PATCH 1/3] Handles relative image URLs and ensures dir exists Ensures that relative image URLs are correctly handled by prepending the host URL. This prevents broken image links when the URL is relative. Creates the destination directory for catalogue entries if it does not already exist. --- RomM/api.py | 1 + RomM/imageutils.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/RomM/api.py b/RomM/api.py index d4a790d..0a10673 100644 --- a/RomM/api.py +++ b/RomM/api.py @@ -652,6 +652,7 @@ def download_rom(self) -> None: ) if not catalogue_path: continue + os.makedirs(catalogue_path, exist_ok=True) filename = self._sanitize_filename(rom.fs_name_no_ext) if rom.summary: diff --git a/RomM/imageutils.py b/RomM/imageutils.py index cc09853..b345688 100644 --- a/RomM/imageutils.py +++ b/RomM/imageutils.py @@ -54,6 +54,10 @@ def add_rounded_corners(self, image: Image.Image, radius: int = 20): def load_image_from_url(self, url: str, headers: dict) -> Image.Image | None: try: + # If URL is relative (doesn't start with http:// or https://), prepend host + if url and not url.startswith(("http://", "https://")): + url = f"{self.host}{url}" + req = Request(url.split("?")[0], headers=headers) with urlopen(req, timeout=60) as response: # trunk-ignore(bandit/B310) data = response.read() From e72d546089f51266a89989ebb836a74c88d5b1a4 Mon Sep 17 00:00:00 2001 From: Zach Keatings Date: Thu, 8 Jan 2026 21:52:28 -0500 Subject: [PATCH 2/3] Replaces manual string checking with urljoin for robustness --- RomM/imageutils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/RomM/imageutils.py b/RomM/imageutils.py index b345688..2a37c16 100644 --- a/RomM/imageutils.py +++ b/RomM/imageutils.py @@ -3,6 +3,7 @@ from typing import Optional from urllib.error import HTTPError, URLError from urllib.request import Request, urlopen +from urllib.parse import urljoin from PIL import Image, ImageDraw @@ -54,9 +55,9 @@ def add_rounded_corners(self, image: Image.Image, radius: int = 20): def load_image_from_url(self, url: str, headers: dict) -> Image.Image | None: try: - # If URL is relative (doesn't start with http:// or https://), prepend host - if url and not url.startswith(("http://", "https://")): - url = f"{self.host}{url}" + # Use urljoin to properly resolve relative URLs against the host + if url: + url = urljoin(f'{self.host}/', url) req = Request(url.split("?")[0], headers=headers) with urlopen(req, timeout=60) as response: # trunk-ignore(bandit/B310) From 32f87e37ec72c79006dc2e8f8e849de6b7bacdcb Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 8 Jan 2026 22:41:50 -0500 Subject: [PATCH 3/3] run turnk fmt --- RomM/imageutils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RomM/imageutils.py b/RomM/imageutils.py index 2a37c16..c39c062 100644 --- a/RomM/imageutils.py +++ b/RomM/imageutils.py @@ -2,8 +2,8 @@ from io import BytesIO from typing import Optional from urllib.error import HTTPError, URLError -from urllib.request import Request, urlopen from urllib.parse import urljoin +from urllib.request import Request, urlopen from PIL import Image, ImageDraw @@ -57,8 +57,8 @@ def load_image_from_url(self, url: str, headers: dict) -> Image.Image | None: try: # Use urljoin to properly resolve relative URLs against the host if url: - url = urljoin(f'{self.host}/', url) - + url = urljoin(f"{self.host}/", url) + req = Request(url.split("?")[0], headers=headers) with urlopen(req, timeout=60) as response: # trunk-ignore(bandit/B310) data = response.read()