2022-06-27 09:25:19 +00:00
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2022-08-03 06:26:59 +00:00
|
|
|
|
|
|
|
"github.com/alist-org/alist/v3/internal/db"
|
2022-06-27 09:25:19 +00:00
|
|
|
)
|
|
|
|
|
2022-06-27 13:34:13 +00:00
|
|
|
func GetByKey(key string, defaultValue ...string) string {
|
|
|
|
val, ok := db.GetSettingsMap()[key]
|
|
|
|
if !ok {
|
|
|
|
if len(defaultValue) > 0 {
|
|
|
|
return defaultValue[0]
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return val
|
2022-06-27 09:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetIntSetting(key string, defaultVal int) int {
|
|
|
|
i, err := strconv.Atoi(GetByKey(key))
|
|
|
|
if err != nil {
|
|
|
|
return defaultVal
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsTrue(key string) bool {
|
|
|
|
return GetByKey(key) == "true" || GetByKey(key) == "1"
|
|
|
|
}
|