mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix ui config conversion (#2672)
This commit is contained in:
@@ -54,32 +54,46 @@ func toSnakeCaseMap(m map[string]interface{}) map[string]interface{} {
|
|||||||
|
|
||||||
for key, val := range m {
|
for key, val := range m {
|
||||||
adjKey := toSnakeCase(key)
|
adjKey := toSnakeCase(key)
|
||||||
switch v := val.(type) {
|
nm[adjKey] = val
|
||||||
case map[interface{}]interface{}:
|
|
||||||
nm[adjKey] = toSnakeCaseMap(cast.ToStringMap(v))
|
|
||||||
case map[string]interface{}:
|
|
||||||
nm[adjKey] = toSnakeCaseMap(v)
|
|
||||||
default:
|
|
||||||
nm[adjKey] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nm
|
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{} {
|
func fromSnakeCaseMap(m map[string]interface{}) map[string]interface{} {
|
||||||
nm := make(map[string]interface{})
|
nm := make(map[string]interface{})
|
||||||
|
|
||||||
for key, val := range m {
|
for key, val := range m {
|
||||||
adjKey := fromSnakeCase(key)
|
adjKey := fromSnakeCase(key)
|
||||||
switch v := val.(type) {
|
nm[adjKey] = convertMapValue(val)
|
||||||
case map[interface{}]interface{}:
|
|
||||||
nm[adjKey] = fromSnakeCaseMap(cast.ToStringMap(v))
|
|
||||||
case map[string]interface{}:
|
|
||||||
nm[adjKey] = fromSnakeCaseMap(v)
|
|
||||||
default:
|
|
||||||
nm[adjKey] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nm
|
return nm
|
||||||
|
|||||||
Reference in New Issue
Block a user