fix: updating logo with new theme structure

Fixes updating and resetting the logo when using the new `theme.json` structure in Web.
This commit is contained in:
Jannik Stehle
2023-12-11 13:37:55 +01:00
parent 197f14a5e3
commit 973849e0e0
2 changed files with 14 additions and 22 deletions
+9 -22
View File
@@ -145,17 +145,12 @@ func (p Web) getLogoPath(r io.Reader) (string, error) {
var m map[string]interface{}
_ = json.NewDecoder(r).Decode(&m)
webCfg, ok := m["web"].(map[string]interface{})
webCfg, ok := m["clients"].(map[string]interface{})["web"].(map[string]interface{})
if !ok {
return "", errInvalidThemeConfig
}
defaultCfg, ok := webCfg["default"].(map[string]interface{})
if !ok {
return "", errInvalidThemeConfig
}
logoCfg, ok := defaultCfg["logo"].(map[string]interface{})
logoCfg, ok := webCfg["defaults"].(map[string]interface{})["logo"].(map[string]interface{})
if !ok {
return "", errInvalidThemeConfig
}
@@ -186,27 +181,19 @@ func (p Web) updateLogoThemeConfig(logoPath string) error {
}
commonCfg["logo"] = logoPath
webCfg, ok := m["web"].(map[string]interface{})
webCfg, ok := m["clients"].(map[string]interface{})["web"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
// iterate over all possible themes and replace logo
for theme := range webCfg {
themeCfg, ok := webCfg[theme].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoCfg, ok := themeCfg["logo"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoCfg["login"] = logoPath
logoCfg["topbar"] = logoPath
logoCfg, ok := webCfg["defaults"].(map[string]interface{})["logo"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoCfg["login"] = logoPath
logoCfg["topbar"] = logoPath
dst, err := p.fs.Create(_themesConfigPath)
if err != nil {
return err