mirror of
https://github.com/stashapp/stash.git
synced 2025-12-14 20:33:16 +01:00
Fix ui config conversion (#2672)
This commit is contained in:
parent
582ffa1420
commit
6029918d22
1 changed files with 30 additions and 16 deletions
|
|
@ -54,32 +54,46 @@ func toSnakeCaseMap(m map[string]interface{}) map[string]interface{} {
|
|||
|
||||
for key, val := range m {
|
||||
adjKey := toSnakeCase(key)
|
||||
switch v := val.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
nm[adjKey] = toSnakeCaseMap(cast.ToStringMap(v))
|
||||
case map[string]interface{}:
|
||||
nm[adjKey] = toSnakeCaseMap(v)
|
||||
default:
|
||||
nm[adjKey] = v
|
||||
}
|
||||
nm[adjKey] = val
|
||||
}
|
||||
|
||||
return nm
|
||||
}
|
||||
|
||||
// convertMapValue converts values into something that can be marshalled in JSON
|
||||
// This means converting map[interface{}]interface{} to map[string]interface{} where ever
|
||||
// encountered.
|
||||
func convertMapValue(val interface{}) interface{} {
|
||||
switch v := val.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
ret := cast.ToStringMap(v)
|
||||
for k, vv := range ret {
|
||||
ret[k] = convertMapValue(vv)
|
||||
}
|
||||
return ret
|
||||
case map[string]interface{}:
|
||||
ret := make(map[string]interface{})
|
||||
for k, vv := range v {
|
||||
ret[k] = convertMapValue(vv)
|
||||
}
|
||||
return ret
|
||||
case []interface{}:
|
||||
ret := make([]interface{}, len(v))
|
||||
for i, vv := range v {
|
||||
ret[i] = convertMapValue(vv)
|
||||
}
|
||||
return ret
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
func fromSnakeCaseMap(m map[string]interface{}) map[string]interface{} {
|
||||
nm := make(map[string]interface{})
|
||||
|
||||
for key, val := range m {
|
||||
adjKey := fromSnakeCase(key)
|
||||
switch v := val.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
nm[adjKey] = fromSnakeCaseMap(cast.ToStringMap(v))
|
||||
case map[string]interface{}:
|
||||
nm[adjKey] = fromSnakeCaseMap(v)
|
||||
default:
|
||||
nm[adjKey] = v
|
||||
}
|
||||
nm[adjKey] = convertMapValue(val)
|
||||
}
|
||||
|
||||
return nm
|
||||
|
|
|
|||
Loading…
Reference in a new issue