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)) 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 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