mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-11-04 08:40:20 +00:00
Merge upstream monitoring features preserving domain extensions and require fixed Go toolchain
This commit is contained in:
commit
71dd21269b
92 files changed
+8557
-874
No files matched your search
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@@ -29,7 +30,7 @@ func listConfig(c *gin.Context) (*model.SettingResponse, error) {
|
||||
isAdmin = user.Role.IsAdmin()
|
||||
}
|
||||
|
||||
config := *singleton.Conf
|
||||
config := singleton.Conf.SettingsSnapshot()
|
||||
config.Language = strings.ReplaceAll(config.Language, "_", "-")
|
||||
|
||||
conf := model.SettingResponse{
|
||||
@@ -92,11 +93,20 @@ func updateConfig(c *gin.Context) (any, error) {
|
||||
if !userTemplateValid {
|
||||
return nil, errors.New("invalid user template")
|
||||
}
|
||||
// 全部输入校验必须先于任何对 singleton.Conf 的写入:任一字段非法都应
|
||||
// 整体拒绝,避免"请求以错误收场、先处理的字段却已生效"的半提交状态
|
||||
if sf.OnlineStatsDays != nil &&
|
||||
(*sf.OnlineStatsDays < model.MinOnlineStatsDays || *sf.OnlineStatsDays > model.MaxOnlineStatsDays) {
|
||||
return nil, fmt.Errorf("online_stats_days must be between %d and %d", model.MinOnlineStatsDays, model.MaxOnlineStatsDays)
|
||||
}
|
||||
|
||||
singleton.Conf.Language = strings.ReplaceAll(sf.Language, "-", "_")
|
||||
|
||||
singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification
|
||||
singleton.Conf.EnablePlainIPInNotification = sf.EnablePlainIPInNotification
|
||||
if sf.AllowJWTIPChange != nil {
|
||||
singleton.Conf.SetJWTIPChangeAllowed(*sf.AllowJWTIPChange)
|
||||
}
|
||||
singleton.Conf.Cover = sf.Cover
|
||||
singleton.Conf.InstallHost = sf.InstallHost
|
||||
singleton.Conf.DashboardHost = sf.DashboardHost
|
||||
@@ -124,18 +134,22 @@ func updateConfig(c *gin.Context) (any, error) {
|
||||
singleton.Conf.DomainExpiryNotificationDays = sf.DomainExpiryNotificationDays
|
||||
singleton.Conf.ServerExpiryNotificationDays = sf.ServerExpiryNotificationDays
|
||||
|
||||
mcpWasEnabled := singleton.Conf.MCPEnabled()
|
||||
mcpNext := resolveSettingEnableMCP(sf.EnableMCP, mcpWasEnabled)
|
||||
|
||||
if err := applyEnableMCPTransition(
|
||||
mcpWasEnabled, mcpNext,
|
||||
singleton.Conf.SetMCPEnabled,
|
||||
singleton.Conf.Save,
|
||||
fireMCPKillSwitch,
|
||||
); err != nil {
|
||||
if err := singleton.Conf.CommitOnlineHistoryRetention(sf.OnlineStatsDays, func() error {
|
||||
mcpWasEnabled := singleton.Conf.MCPEnabled()
|
||||
mcpNext := resolveSettingEnableMCP(sf.EnableMCP, mcpWasEnabled)
|
||||
return applyEnableMCPTransition(
|
||||
mcpWasEnabled, mcpNext,
|
||||
singleton.Conf.SetMCPEnabled,
|
||||
singleton.Conf.Save,
|
||||
fireMCPKillSwitch,
|
||||
)
|
||||
}); err != nil {
|
||||
return nil, newGormError("%v", err)
|
||||
}
|
||||
|
||||
// applyEnableMCPTransition already persisted every setting, even when MCP
|
||||
// is unchanged. A second save could fail after irreversible cleanup.
|
||||
|
||||
singleton.OnUpdateLang(singleton.Conf.Language)
|
||||
singleton.InitTelegramBot()
|
||||
return nil, nil
|
||||
@@ -174,6 +188,12 @@ func fireMCPKillSwitch() {
|
||||
// the current config to avoid accidentally tripping the kill switch on
|
||||
// partial PATCH calls that omit enable_mcp.
|
||||
func resolveSettingEnableMCP(formValue *bool, current bool) bool {
|
||||
return resolveOptionalBool(formValue, current)
|
||||
}
|
||||
|
||||
// resolveOptionalBool preserves a setting for partial PATCH requests when its
|
||||
// boolean field is absent, while still allowing an explicit false value.
|
||||
func resolveOptionalBool(formValue *bool, current bool) bool {
|
||||
if formValue == nil {
|
||||
return current
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user