feat(remote): 增加远端控制台与日志汇总导出
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"douyu_go/internal/activity"
|
||||
"douyu_go/internal/constants"
|
||||
@@ -231,11 +232,18 @@ func LoadConfig(path string) types.Config {
|
||||
cfg.RetryStages = defaultRetryStages()
|
||||
}
|
||||
normalizeProxyConfig(&cfg)
|
||||
normalizeRemoteConfig(&cfg)
|
||||
normalizeXiaodianConfig(&cfg)
|
||||
logger.LogEvent("配置", "success", "配置加载完成: %s", path)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func normalizeRemoteConfig(cfg *types.Config) {
|
||||
cfg.RemoteURL = strings.TrimSpace(cfg.RemoteURL)
|
||||
cfg.RemoteToken = strings.TrimSpace(cfg.RemoteToken)
|
||||
cfg.RemoteMachineName = strings.TrimSpace(cfg.RemoteMachineName)
|
||||
}
|
||||
|
||||
func normalizeProxyConfig(cfg *types.Config) {
|
||||
if cfg.AccountsPerProxy <= 0 {
|
||||
cfg.AccountsPerProxy = constants.DefaultAccountsPerProxy
|
||||
|
||||
@@ -65,8 +65,8 @@ func LoadSharedProxyConfig(path string) (types.SharedProxyConfig, error) {
|
||||
shared.SchemaVersion, SharedProxyConfigSchemaVersion,
|
||||
)
|
||||
}
|
||||
if !hasSharedProxySettings(shared.Proxy) {
|
||||
return types.SharedProxyConfig{}, errors.New("共享代理配置中没有 proxy 设置")
|
||||
if !hasSharedProxySettings(shared.Proxy) && !hasSharedRemoteSettings(shared.Remote) {
|
||||
return types.SharedProxyConfig{}, errors.New("共享配置中没有 proxy 或 remote 设置")
|
||||
}
|
||||
return shared, nil
|
||||
}
|
||||
@@ -104,6 +104,19 @@ func ApplySharedProxyConfig(cfg *types.Config, shared types.SharedProxyConfig) {
|
||||
if proxy.WhitelistSignKey != nil {
|
||||
cfg.ProxyWhitelistSignKey = strings.TrimSpace(*proxy.WhitelistSignKey)
|
||||
}
|
||||
remote := shared.Remote
|
||||
if remote.Enabled != nil {
|
||||
cfg.RemoteEnabled = *remote.Enabled
|
||||
}
|
||||
if remote.URL != nil {
|
||||
cfg.RemoteURL = strings.TrimSpace(*remote.URL)
|
||||
}
|
||||
if remote.Token != nil {
|
||||
cfg.RemoteToken = strings.TrimSpace(*remote.Token)
|
||||
}
|
||||
if remote.MachineName != nil {
|
||||
cfg.RemoteMachineName = strings.TrimSpace(*remote.MachineName)
|
||||
}
|
||||
normalizeProxyConfig(cfg)
|
||||
}
|
||||
|
||||
@@ -127,6 +140,12 @@ func SaveSharedProxyConfig(path string, cfg types.Config) error {
|
||||
WhitelistPassword: stringPointer(cfg.ProxyWhitelistPassword),
|
||||
WhitelistSignKey: stringPointer(cfg.ProxyWhitelistSignKey),
|
||||
},
|
||||
Remote: types.SharedRemoteSettings{
|
||||
Enabled: boolPointer(cfg.RemoteEnabled),
|
||||
URL: stringPointer(cfg.RemoteURL),
|
||||
Token: stringPointer(cfg.RemoteToken),
|
||||
MachineName: stringPointer(cfg.RemoteMachineName),
|
||||
},
|
||||
}
|
||||
data, err := json.MarshalIndent(shared, "", " ")
|
||||
if err != nil {
|
||||
@@ -179,6 +198,13 @@ func hasSharedProxySettings(proxy types.SharedProxySettings) bool {
|
||||
proxy.WhitelistSignKey != nil
|
||||
}
|
||||
|
||||
func hasSharedRemoteSettings(remote types.SharedRemoteSettings) bool {
|
||||
return remote.Enabled != nil ||
|
||||
remote.URL != nil ||
|
||||
remote.Token != nil ||
|
||||
remote.MachineName != nil
|
||||
}
|
||||
|
||||
func boolPointer(value bool) *bool { return &value }
|
||||
func intPointer(value int) *int { return &value }
|
||||
func stringPointer(value string) *string { return &value }
|
||||
|
||||
@@ -22,6 +22,10 @@ func TestSharedProxyConfigRoundTripExcludesRuntimeProxy(t *testing.T) {
|
||||
ProxyWhitelistReplace: true,
|
||||
ProxyWhitelistPassword: "login-pass",
|
||||
ProxyWhitelistSignKey: "0123456789abcdef",
|
||||
RemoteEnabled: true,
|
||||
RemoteURL: "https://control.example.com",
|
||||
RemoteToken: "remote-token",
|
||||
RemoteMachineName: "PC-01",
|
||||
}
|
||||
if err := SaveSharedProxyConfig(path, cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -48,6 +52,10 @@ func TestSharedProxyConfigRoundTripExcludesRuntimeProxy(t *testing.T) {
|
||||
if !local.ProxyEnabled || local.ProxyAPI != cfg.ProxyAPI || local.AccountsPerProxy != 5 {
|
||||
t.Fatalf("unexpected merged config: %+v", local)
|
||||
}
|
||||
if !local.RemoteEnabled || local.RemoteURL != cfg.RemoteURL ||
|
||||
local.RemoteToken != cfg.RemoteToken || local.RemoteMachineName != cfg.RemoteMachineName {
|
||||
t.Fatalf("remote settings were not merged: %+v", local)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplySharedProxyConfigSupportsPartialOverrides(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user