Handles relative image URLs and ensures dir exists#74
Conversation
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.
Summary of ChangesHello @ZacharyKeatings, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of ROM asset downloading by addressing two common failure points. It introduces logic to correctly resolve relative image URLs by prepending the configured host, ensuring images are always fetched from a complete URL. Additionally, it guarantees that target directories for ROM metadata and assets are created automatically if they don't already exist, preventing file system errors during the download process. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces two improvements: handling relative image URLs and ensuring the existence of catalogue directories. The change to handle relative URLs in imageutils.py is a good idea, but the implementation could be made more robust by using urllib.parse.urljoin to correctly handle all types of relative URLs. The change in api.py to create the catalogue directory is helpful, but it appears to be redundant as other parts of the code already ensure the necessary directories are created. My review includes suggestions to address these points for improved robustness and code clarity.
Description
Explain the changes or enhancements you are proposing with this pull request.
This PR addresses two issues that could cause failures when downloading and processing ROM assets:
Relative URL handling: The
load_image_from_urlmethod inImageUtilsnow automatically prepends the host URL (from theHOSTenvironment variable) to relative image URLs. Previously, relative URLs like/api/images/cover.pngwould fail to load because they lacked a full domain. Now, if a URL doesn't start withhttp://orhttps://, the host is automatically prepended, ensuring images load correctly regardless of whether the API returns absolute or relative URLs.Directory creation: Added
os.makedirs(catalogue_path, exist_ok=True)in thedownload_rommethod to ensure the catalogue directory exists before attempting to write ROM metadata and assets. This preventsFileNotFoundErrorexceptions when the catalogue directory structure hasn't been initialized yet.Changes Made
RomM/imageutils.py: Added logic to detect and prepend host URL to relative image URLs inload_image_from_urlmethodRomM/api.py: Added directory creation for catalogue path before writing ROM metadata and assetsTesting
Checklist
Please check all that apply.
Screenshots