add common part, make the logic theme name agnostic

This commit is contained in:
Michael Barz
2023-03-06 10:45:33 +01:00
parent e3d9b810bd
commit e05e3b980f
2 changed files with 22 additions and 24 deletions

View File

@@ -3,4 +3,5 @@ Enhancement: Add endpoints to upload a custom logo
Added endpoints to upload and reset custom logos. The files are stored under the `WEB_ASSET_PATH`
which defaults to `$OCIS_BASE_DATA_PATH/web/assets`.
https://github.com/owncloud/ocis/pull/5735
https://github.com/owncloud/ocis/pull/5559

View File

@@ -167,37 +167,34 @@ func (p Web) updateLogoThemeConfig(logoPath string) error {
var m map[string]interface{}
_ = json.NewDecoder(f).Decode(&m)
// change logo in common part
commonCfg, ok := m["common"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
commonCfg["logo"] = logoPath
webCfg, ok := m["web"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
defaultCfg, ok := webCfg["default"].(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 := defaultCfg["logo"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoCfg["login"] = logoPath
logoCfg["topbar"] = logoPath
defaultDarkCfg, ok := webCfg["default-dark"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoDarkCfg, ok := defaultDarkCfg["logo"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}
logoDarkCfg["login"] = logoPath
logoDarkCfg["topbar"] = logoPath
dst, err := p.fs.Create(_themesConfigPath)
if err != nil {
return err