From c77d05e69344643b44e735e7bce11ca2b2eb7dd7 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 3 Feb 2024 21:07:45 +0100 Subject: [PATCH] portal: store custom logos in a /usr/share/yunohost/customassets, and only store the file id which the front should then query as a regular asset --- hooks/conf_regen/01-yunohost | 6 +++--- share/config_domain.toml | 2 +- src/domain.py | 11 +---------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/hooks/conf_regen/01-yunohost b/hooks/conf_regen/01-yunohost index c4db1455f..feb4f5977 100755 --- a/hooks/conf_regen/01-yunohost +++ b/hooks/conf_regen/01-yunohost @@ -30,9 +30,9 @@ base_folder_and_perm_init() { chmod 500 /etc/yunohost/portal chown ynh-portal:ynh-portal /etc/yunohost/portal - mkdir -p /usr/share/yunohost/portallogos - chmod 550 /usr/share/yunohost/portallogos - chown ynh-portal:www-data /usr/share/yunohost/portallogos + mkdir -p /usr/share/yunohost/portal/customassets + chmod 775 /usr/share/yunohost/portal/customassets + chown root:root /usr/share/yunohost/customassets touch /var/log/yunohost-portalapi.log chown ynh-portal:root /var/log/yunohost-portalapi.log diff --git a/share/config_domain.toml b/share/config_domain.toml index f6459785f..620d6e7c0 100644 --- a/share/config_domain.toml +++ b/share/config_domain.toml @@ -20,7 +20,7 @@ name = "Features" type = "file" accept = ["image/png", "image/jpeg", "image/svg+xml"] mode = "python" - bind = "/usr/share/yunohost/portallogos/{filename}{ext}" + bind = "/usr/share/yunohost/portal/customassets/{filename}{ext}" [feature.portal.portal_theme] type = "select" diff --git a/src/domain.py b/src/domain.py index 27b092038..0d24c243e 100644 --- a/src/domain.py +++ b/src/domain.py @@ -810,16 +810,7 @@ def _get_DomainConfigPanel(): portal_values["portal_logo"] = "" if next_settings["portal_logo"]: - # Save the file content as `{mimetype}:{base64content}` in portal settings - # while keeping the file path in the domain settings - from base64 import b64encode - from magic import Magic - - file_content = Path(next_settings["portal_logo"]).read_bytes() - mimetype = Magic(mime=True).from_buffer(file_content) - portal_values["portal_logo"] = ( - mimetype + ":" + b64encode(file_content).decode("utf-8") - ) + portal_values["portal_logo"] = Path(next_settings["portal_logo"]).name portal_settings_path = Path(f"{PORTAL_SETTINGS_DIR}/{self.entity}.json") portal_settings: dict[str, Any] = {"apps": {}}