From 7a2c005bf5a0267f364e750ca031b1b06241288a Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:24:59 +0000 Subject: [PATCH 1/3] fix: resolve image urls (#136) * fix: resolve image urls when image paths are not absolute resolve them from gui cache if possible * fix: resolve image urls when image paths are not absolute resolve them from gui cache if possible * Update ovos_bus_client/apis/gui.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: resolve image urls when image paths are not absolute resolve them from gui cache if possible --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- ovos_bus_client/apis/gui.py | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/ovos_bus_client/apis/gui.py b/ovos_bus_client/apis/gui.py index 2bd3be3..9bfece0 100644 --- a/ovos_bus_client/apis/gui.py +++ b/ovos_bus_client/apis/gui.py @@ -119,13 +119,15 @@ def _cache_gui_files(self): for framework, bpath in self.ui_directories.items(): if framework == "all": - LOG.warning(f"'all' is deprecated! ignoring path: {bpath}") + # mostly applies to image files + shutil.copytree(bpath, output_path) + LOG.debug(f"Copied {self.skill_id} shared GUI resources from {bpath} to {output_path}") continue if not os.path.isdir(bpath): LOG.error(f"invalid '{framework}' resources directory: {bpath}") continue shutil.copytree(bpath, f"{output_path}/{framework}") - LOG.debug(f"Copied {self.skill_id} resources from {bpath} to {output_path}/{framework}") + LOG.debug(f"Copied {self.skill_id} GUI resources from {bpath} to {output_path}/{framework}") def set_bus(self, bus=None): self._bus = bus or get_mycroft_bus() @@ -533,6 +535,43 @@ def show_text(self, text: str, title: Optional[str] = None, self.show_page("SYSTEM_TextFrame", override_idle, override_animations) + def _resolve_url(self, url: str) -> str: + """Resolve a URL to a valid file path. + + Args: + url (str): URL or file path to resolve + + Returns: + str: Resolved absolute file path or original URL + + Raises: + ValueError: If url is None or empty + """ + if not url or not isinstance(url, str): + raise ValueError("URL must be a non-empty string") + if url.startswith("http"): + return url + + # Sanitize the url to prevent path traversal + url = os.path.normpath(url) + if url.startswith("..") or url.startswith("/"): + return url + + if not os.path.isfile(url): + GUI_CACHE_PATH = get_xdg_cache_save_path('ovos_gui') + # Use os.path.join for path construction + gui_cache = os.path.join(GUI_CACHE_PATH, self.skill_id, url) + if os.path.isfile(gui_cache): + LOG.debug(f"Resolved image: {gui_cache}") + return gui_cache + else: + for framework in self.ui_directories: + gui_cache = os.path.join(GUI_CACHE_PATH, self.skill_id, framework, url) + if os.path.isfile(gui_cache): + LOG.debug(f"Resolved image: {gui_cache}") + return gui_cache + return url + def show_image(self, url: str, caption: Optional[str] = None, title: Optional[str] = None, fill: str = None, background_color: str = None, @@ -557,6 +596,10 @@ def show_image(self, url: str, caption: Optional[str] = None, True: Disables showing all platform skill animations. False: 'Default' always show animations. """ + url = self._resolve_url(url) + if not os.path.isfile(url): + LOG.error(f"Provided image file does not exist! '{url}'") + return self["image"] = url self["title"] = title self["caption"] = caption @@ -589,6 +632,10 @@ def show_animated_image(self, url: str, caption: Optional[str] = None, True: Disables showing all platform skill animations. False: 'Default' always show animations. """ + url = self._resolve_url(url) + if not os.path.isfile(url): + LOG.error(f"Provided image file does not exist! '{url}'") + return self["image"] = url self["title"] = title self["caption"] = caption From 654dfb6c688fcfde02bd9addfac5c9f1a5877efc Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Fri, 15 Nov 2024 13:25:17 +0000 Subject: [PATCH 2/3] Increment Version to 1.0.1a1 --- ovos_bus_client/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ovos_bus_client/version.py b/ovos_bus_client/version.py index a3d5a94..4aed667 100644 --- a/ovos_bus_client/version.py +++ b/ovos_bus_client/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_BUILD = 0 -VERSION_ALPHA = 0 +VERSION_BUILD = 1 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From 7bf707c14982eb08335352dc14e0e8d5297817b4 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Fri, 15 Nov 2024 13:25:50 +0000 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fd8f0..660d484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,12 @@ # Changelog -## [1.0.0a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.0a1) (2024-11-05) +## [1.0.1a1](https://github.com/OpenVoiceOS/ovos-bus-client/tree/1.0.1a1) (2024-11-15) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/0.1.6...1.0.0a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-bus-client/compare/1.0.0...1.0.1a1) -**Breaking changes:** +**Merged pull requests:** -- refactor!:deprecate QML upload from bus [\#120](https://github.com/OpenVoiceOS/ovos-bus-client/pull/120) ([JarbasAl](https://github.com/JarbasAl)) - -**Fixed bugs:** - -- Latest git tag is invalid [\#99](https://github.com/OpenVoiceOS/ovos-bus-client/issues/99) +- fix: resolve image urls [\#136](https://github.com/OpenVoiceOS/ovos-bus-client/pull/136) ([JarbasAl](https://github.com/JarbasAl))