domain/portal: try to re-implement portal logo

This commit is contained in:
Alexandre Aubin 2023-11-13 19:02:25 +01:00
parent 90aa6b86f1
commit 566f5d29a7
4 changed files with 31 additions and 4 deletions

2
debian/control vendored
View file

@ -15,7 +15,7 @@ Depends: ${python3:Depends}, ${misc:Depends}
, python3-miniupnpc, python3-dbus, python3-jinja2
, python3-toml, python3-packaging, python3-publicsuffix2
, python3-ldap, python3-zeroconf (>= 0.47), python3-lexicon,
, python3-cryptography, python3-jwt
, python3-cryptography, python3-jwt, python3-magic
, python-is-python3, python3-pydantic, python3-email-validator
, nginx, nginx-extras (>=1.22)
, apt, apt-transport-https, apt-utils, dirmngr

View file

@ -71,6 +71,9 @@ do_init_regen() {
mkdir -p /etc/yunohost/portal
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
# YunoHost services
cp yunohost-api.service /etc/systemd/system/yunohost-api.service
@ -253,6 +256,9 @@ do_post_regen() {
mkdir -p /etc/yunohost/portal
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
# Domain settings
mkdir -p /etc/yunohost/domains

View file

@ -15,8 +15,8 @@ name = "Features"
type = "string"
default = "YunoHost"
# [feature.portal.portal_logo]
# type = "file"
[feature.portal.portal_logo]
type = "file"
[feature.portal.portal_theme]
type = "select"

View file

@ -758,9 +758,30 @@ class DomainConfigPanel(ConfigPanel):
"default_app",
"show_other_domains_apps",
"portal_title",
# "portal_logo",
"portal_logo",
"portal_theme",
]
if "portal_logo" in next_settings:
import magic, hashlib
with open(next_settings["portal_logo"], "rb") as f:
file_content = f.read()
mimetype = magic.Magic(mime=True).from_buffer(file_content)
if mimetype not in ["image/png", "image/jpeg"]:
raise YunohostValidationError(f"Unsupported image type : {mimetype}", raw=True)
ext = mimetype.split("/")[-1]
m = hashlib.sha256()
m.update(file_content)
sha256sum = m.hexdigest()
filename = f"/usr/share/yunohost/portallogos/{sha256sum}.{ext}"
with open(filename, "wb") as f:
f.write(file_content)
next_settings["portal_logo"] = filename
# FIXME : the previous line doesn't actually set anything in the actual form ...
# ... and calling `form.portal_logo = filename` would actually make it sort of "re-upload" the file to another place ...
# not sure how to address this issue ...
if _get_parent_domain_of(self.entity, topest=True) is None and any(
option in next_settings for option in portal_options
):