diff --git a/supervisor/addons/model.py b/supervisor/addons/model.py index 27dabd5d6..00aeaee02 100644 --- a/supervisor/addons/model.py +++ b/supervisor/addons/model.py @@ -478,11 +478,21 @@ class AddonModel(CoreSysAttributes, ABC): """Return True if an icon exists.""" return self.path_icon.exists() + @property + def with_dark_icon(self) -> bool: + """Return True if an dark icon exists.""" + return self.path_dark_icon.exists() + @property def with_logo(self) -> bool: """Return True if a logo exists.""" return self.path_logo.exists() + @property + def with_dark_logo(self) -> bool: + """Return True if a dark logo exists.""" + return self.path_dark_logo.exists() + @property def with_changelog(self) -> bool: """Return True if a changelog exists.""" diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index be6ee0595..fe8da213f 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -382,7 +382,9 @@ class RestAPI(CoreSysAttributes): web.post("/addons/{addon}/rebuild", api_addons.rebuild), web.get("/addons/{addon}/logs", api_addons.logs), web.get("/addons/{addon}/icon", api_addons.icon), + web.get("/addons/{addon}/dark_icon", api_addons.dark_icon), web.get("/addons/{addon}/logo", api_addons.logo), + web.get("/addons/{addon}/dark_logo", api_addons.dark_logo), web.get("/addons/{addon}/changelog", api_addons.changelog), web.get("/addons/{addon}/documentation", api_addons.documentation), web.post("/addons/{addon}/stdin", api_addons.stdin), diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index 041ae5147..b8336d644 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -69,7 +69,6 @@ from ..const import ( ATTR_NETWORK_RX, ATTR_NETWORK_TX, ATTR_OPTIONS, - ATTR_PREFER_DARK, ATTR_PRIVILEGED, ATTR_PROTECTED, ATTR_PWNED, @@ -114,12 +113,6 @@ _LOGGER: logging.Logger = logging.getLogger(__name__) SCHEMA_VERSION = vol.Schema({vol.Optional(ATTR_VERSION): str}) -SCHEMA_DARK = vol.Schema( - { - vol.Optional(ATTR_PREFER_DARK, default=False): bool, - } -) - # pylint: disable=no-value-for-parameter SCHEMA_OPTIONS = vol.Schema( { @@ -470,8 +463,17 @@ class APIAddons(CoreSysAttributes): if not addon.with_icon: raise APIError(f"No icon found for add-on {addon.slug}!") - body = await api_validate(SCHEMA_DARK, request) - if body[ATTR_PREFER_DARK] and addon.path_dark_icon.exists(): + with addon.path_icon.open("rb") as png: + return png.read() + + @api_process_raw(CONTENT_TYPE_PNG) + async def dark_icon(self, request: web.Request) -> bytes: + """Return dark icon from add-on.""" + addon = self._extract_addon(request) + if not addon.with_icon: + raise APIError(f"No icon found for add-on {addon.slug}!") + + if addon.with_dark_icon: with addon.path_dark_icon.open("rb") as png: return png.read() @@ -485,8 +487,17 @@ class APIAddons(CoreSysAttributes): if not addon.with_logo: raise APIError(f"No logo found for add-on {addon.slug}!") - body = await api_validate(SCHEMA_DARK, request) - if body[ATTR_PREFER_DARK] and addon.path_dark_logo.exists(): + with addon.path_logo.open("rb") as png: + return png.read() + + @api_process_raw(CONTENT_TYPE_PNG) + async def dark_logo(self, request: web.Request) -> bytes: + """Return dark logo from add-on.""" + addon = self._extract_addon(request) + if not addon.with_logo: + raise APIError(f"No logo found for add-on {addon.slug}!") + + if addon.with_dark_logo: with addon.path_dark_logo.open("rb") as png: return png.read() diff --git a/supervisor/const.py b/supervisor/const.py index 69ac77edc..3c35e2b87 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -255,7 +255,6 @@ ATTR_PASSWORD = "password" ATTR_PORT = "port" ATTR_PORTS = "ports" ATTR_PORTS_DESCRIPTION = "ports_description" -ATTR_PREFER_DARK = "prefer_dark_icon" ATTR_PREFIX = "prefix" ATTR_PRIMARY = "primary" ATTR_PRIORITY = "priority"