c26b06f1cc
Go 控制面(SQLite + REST API)嵌入 Mihomo 数据面,Vue 3 多语言 Web 管理台。 含订阅/节点/规则/出站/监控/日志、OpenAPI、API Key、Gitea Actions CI 与开源文档; CI 使用 ubuntu-latest runner,Go/Docker 步骤走国内镜像与 shell,避免 GitHub 下载超时。 Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package settings
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/prism/proxy/internal/geodata"
|
|
)
|
|
|
|
// Display merges stored settings with effective defaults for the settings UI.
|
|
func Display(raw map[string]string) map[string]string {
|
|
out := make(map[string]string, len(raw)+8)
|
|
for k, v := range raw {
|
|
out[k] = v
|
|
}
|
|
applyGeoDisplayDefaults(out)
|
|
applyScalarDisplayDefaults(out)
|
|
applyLocaleDisplayDefaults(out)
|
|
return out
|
|
}
|
|
|
|
// NormalizeSubmit clears values that match built-in defaults so empty means default.
|
|
func NormalizeSubmit(req map[string]string) {
|
|
normalizeGeoSubmit(req)
|
|
normalizeLocaleSubmit(req)
|
|
}
|
|
|
|
func applyGeoDisplayDefaults(out map[string]string) {
|
|
def := geodata.DefaultConfig()
|
|
if strings.TrimSpace(out["geo_country_mmdb_url"]) == "" {
|
|
out["geo_country_mmdb_url"] = def.CountryMmdbURL
|
|
}
|
|
if strings.TrimSpace(out["geo_geoip_url"]) == "" {
|
|
out["geo_geoip_url"] = def.GeoIPURL
|
|
}
|
|
if strings.TrimSpace(out["geo_geosite_url"]) == "" {
|
|
out["geo_geosite_url"] = def.GeoSiteURL
|
|
}
|
|
}
|
|
|
|
func normalizeGeoSubmit(req map[string]string) {
|
|
def := geodata.DefaultConfig()
|
|
if strings.TrimSpace(req["geo_country_mmdb_url"]) == def.CountryMmdbURL {
|
|
req["geo_country_mmdb_url"] = ""
|
|
}
|
|
if strings.TrimSpace(req["geo_geoip_url"]) == def.GeoIPURL {
|
|
req["geo_geoip_url"] = ""
|
|
}
|
|
if strings.TrimSpace(req["geo_geosite_url"]) == def.GeoSiteURL {
|
|
req["geo_geosite_url"] = ""
|
|
}
|
|
}
|
|
|
|
func applyScalarDisplayDefaults(out map[string]string) {
|
|
if strings.TrimSpace(out["login_max_attempts"]) == "" {
|
|
out["login_max_attempts"] = strconv.Itoa(5)
|
|
}
|
|
if strings.TrimSpace(out["login_lock_minutes"]) == "" {
|
|
out["login_lock_minutes"] = strconv.Itoa(15)
|
|
}
|
|
}
|