mirror of
https://github.com/keven1024/015.git
synced 2026-05-31 17:39:35 +00:00
feat(backend): refactor GetConfig to extract enabled feature keys and include text-translate provider configuration
This commit is contained in:
@@ -10,12 +10,18 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func GetConfig(c *echo.Context) error {
|
||||
featureConfig := u.GetEnvMap("features")
|
||||
features := lo.FilterMap(lo.Entries(featureConfig), func(e lo.Entry[string, any], _ int) (string, bool) {
|
||||
func getEnabledKeys(config map[string]any) []string {
|
||||
return lo.FilterMap(lo.Entries(config), func(e lo.Entry[string, any], _ int) (string, bool) {
|
||||
node, ok := e.Value.(map[string]any)
|
||||
return e.Key, ok && cast.ToBool(node["enabled"])
|
||||
})
|
||||
}
|
||||
|
||||
func GetConfig(c *echo.Context) error {
|
||||
featureConfig := u.GetEnvMap("features")
|
||||
features := getEnabledKeys(featureConfig)
|
||||
textTranslateProviderConfig := u.GetEnvMap("features.text-translate.provider")
|
||||
textTranslateProviders := getEnabledKeys(textTranslateProviderConfig)
|
||||
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"site_title": u.GetEnvMap("site.title"),
|
||||
@@ -26,5 +32,10 @@ func GetConfig(c *echo.Context) error {
|
||||
"version": u.GetEnvWithDefault("VERSION", "dev"),
|
||||
"build_time": cast.ToInt(u.GetEnvWithDefault("BUILD_TIME", cast.ToString(time.Now().Unix()))),
|
||||
"features": features,
|
||||
"config": map[string]any{
|
||||
"text-translate": map[string]any{
|
||||
"provider": textTranslateProviders,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user