Skip to content

Commit

Permalink
Merge pull request #137 from OpenVoiceOS/release-1.0.1a1
Browse files Browse the repository at this point in the history
Release 1.0.1a1
  • Loading branch information
JarbasAl authored Nov 15, 2024
2 parents 7318b50 + 7bf707c commit 5162479
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))



Expand Down
51 changes: 49 additions & 2 deletions ovos_bus_client/apis/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ovos_bus_client/version.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5162479

Please sign in to comment.