fix relay

This commit is contained in:
ryan
2026-06-22 11:56:31 +08:00
parent 53e6efa33b
commit 0a3cd250d1
12 changed files with 131 additions and 270 deletions
-8
View File
@@ -50,13 +50,9 @@ type statusView struct {
Version string `json:"version"`
StartTime int64 `json:"start_time"`
EmailVerification bool `json:"email_verification"`
GitHubOAuth bool `json:"github_oauth"`
GitHubClientID string `json:"github_client_id"`
SystemName string `json:"system_name"`
HomePageLink string `json:"home_page_link"`
FooterHTML string `json:"footer_html"`
WeChatQRCode string `json:"wechat_qrcode"`
WeChatLogin bool `json:"wechat_login"`
ServerAddress string `json:"server_address"`
PasswordRegisterEnabled bool `json:"password_register_enabled"`
CapLoginEnabled bool `json:"cap_login_enabled"`
@@ -168,13 +164,9 @@ func getStatus(ctx context.Context, baseAPIPath string) (*statusView, error) {
Version: buildinfo.Version,
StartTime: model.StartTime,
EmailVerification: model.EmailVerificationEnabled,
GitHubOAuth: model.GitHubOAuthEnabled,
GitHubClientID: model.GitHubClientID,
SystemName: model.SystemName,
HomePageLink: model.HomePageLink,
FooterHTML: model.Footer,
WeChatQRCode: model.WeChatAccountQRCodeImageURL,
WeChatLogin: model.WeChatAuthEnabled,
ServerAddress: model.ServerAddress,
PasswordRegisterEnabled: model.PasswordRegisterEnabled,
CapLoginEnabled: model.CapLoginEnabled,
@@ -40,16 +40,6 @@ func buildOptionValidationState(options []model.OpenFlareOption) map[string]stri
}
func validateOptionWithState(option model.OpenFlareOption, state map[string]string) error {
switch option.Key {
case "GitHubOAuthEnabled":
if option.Value == optionValueTrue && strings.TrimSpace(state["GitHubClientId"]) == "" {
return fmt.Errorf("无法启用 GitHub OAuth,请先填入 GitHub Client ID 以及 GitHub Client Secret!")
}
case "WeChatAuthEnabled":
if option.Value == optionValueTrue && strings.TrimSpace(state["WeChatServerAddress"]) == "" {
return fmt.Errorf("无法启用微信登录,请先填入微信登录相关配置信息!")
}
}
if err := validateOpenRestyOption(option.Key, option.Value); err != nil {
return err
+6 -15
View File
@@ -100,8 +100,7 @@ func TestMigrateUpgradesLegacyDatabaseAndPreservesData(t *testing.T) {
`INSERT INTO users (id, username, password, display_name, role, status, email)
VALUES (2, 'jack', 'hashed_pass_456', 'Normal User jack', 10, 1, 'jack@example.com');`,
// Legacy config options
`INSERT INTO options (key, value) VALUES ('GitHubClientId', 'Ov23lixMKW');`,
`INSERT INTO options (key, value) VALUES ('GitHubClientSecret', 'secret_abc_123');`,
`INSERT INTO options (key, value) VALUES ('SystemName', 'CustomOpenFlare');`,
// Legacy origin
`INSERT INTO origins (id, name, address, remark, created_at, updated_at)
VALUES (10, 'my_origin', '127.0.0.1:8080', 'original origin', '2026-06-01 12:00:00', '2026-06-01 12:00:00');`,
@@ -183,20 +182,12 @@ func TestMigrateUpgradesLegacyDatabaseAndPreservesData(t *testing.T) {
}
// Verify options migrated to of_options
var githubClientIDVal string
if err := sqliteDB.Table("of_options").Where("key = ?", "GitHubClientId").Select("value").Scan(&githubClientIDVal).Error; err != nil {
t.Fatalf("query GitHubClientId failed: %v", err)
var systemNameVal string
if err := sqliteDB.Table("of_options").Where("key = ?", "SystemName").Select("value").Scan(&systemNameVal).Error; err != nil {
t.Fatalf("query SystemName failed: %v", err)
}
if githubClientIDVal != "Ov23lixMKW" {
t.Errorf("GitHubClientId value incorrect: got %s, want Ov23lixMKW", githubClientIDVal)
}
var githubClientSecretVal string
if err := sqliteDB.Table("of_options").Where("key = ?", "GitHubClientSecret").Select("value").Scan(&githubClientSecretVal).Error; err != nil {
t.Fatalf("query GitHubClientSecret failed: %v", err)
}
if githubClientSecretVal != "secret_abc_123" {
t.Errorf("GitHubClientSecret value incorrect: got %s, want secret_abc_123", githubClientSecretVal)
if systemNameVal != "CustomOpenFlare" {
t.Errorf("SystemName value incorrect: got %s, want CustomOpenFlare", systemNameVal)
}
// Verify origin migrated to of_origins
@@ -0,0 +1,22 @@
-- +goose Up
DELETE FROM of_options
WHERE key IN (
'GitHubOAuthEnabled',
'GitHubClientId',
'GitHubClientSecret',
'WeChatAuthEnabled',
'WeChatServerAddress',
'WeChatServerToken',
'WeChatAccountQRCodeImageURL'
);
-- +goose Down
INSERT INTO of_options (key, value) VALUES
('GitHubOAuthEnabled', 'false'),
('GitHubClientId', ''),
('GitHubClientSecret', ''),
('WeChatAuthEnabled', 'false'),
('WeChatServerAddress', ''),
('WeChatServerToken', ''),
('WeChatAccountQRCodeImageURL', '')
ON CONFLICT (key) DO NOTHING;
@@ -0,0 +1,21 @@
-- +goose Up
DELETE FROM of_options
WHERE key IN (
'GitHubOAuthEnabled',
'GitHubClientId',
'GitHubClientSecret',
'WeChatAuthEnabled',
'WeChatServerAddress',
'WeChatServerToken',
'WeChatAccountQRCodeImageURL'
);
-- +goose Down
INSERT OR IGNORE INTO of_options (key, value) VALUES
('GitHubOAuthEnabled', 'false'),
('GitHubClientId', ''),
('GitHubClientSecret', ''),
('WeChatAuthEnabled', 'false'),
('WeChatServerAddress', ''),
('WeChatServerToken', ''),
('WeChatAccountQRCodeImageURL', '');
-11
View File
@@ -42,10 +42,6 @@ var (
CapLoginEnabled = true
PasswordRegisterEnabled = false
EmailVerificationEnabled = false
GitHubOAuthEnabled = false
WeChatAuthEnabled = false
GitHubClientID = ""
WeChatAccountQRCodeImageURL = ""
SMTPPort = 587
AgentDiscoveryToken = ""
AgentHeartbeatInterval = 10000
@@ -159,8 +155,6 @@ func DefaultOpenFlareOptions() map[string]string {
"CapLoginEnabled": strconv.FormatBool(CapLoginEnabled),
"PasswordRegisterEnabled": strconv.FormatBool(PasswordRegisterEnabled),
"EmailVerificationEnabled": strconv.FormatBool(EmailVerificationEnabled),
"GitHubOAuthEnabled": strconv.FormatBool(GitHubOAuthEnabled),
"WeChatAuthEnabled": strconv.FormatBool(WeChatAuthEnabled),
"SMTPServer": "",
"SMTPPort": strconv.Itoa(SMTPPort),
"SMTPAccount": "",
@@ -171,11 +165,6 @@ func DefaultOpenFlareOptions() map[string]string {
"HomePageLink": HomePageLink,
"SystemName": SystemName,
"ServerAddress": "",
"GitHubClientId": "",
"GitHubClientSecret": "",
"WeChatServerAddress": "",
"WeChatServerToken": "",
"WeChatAccountQRCodeImageURL": "",
"AgentDiscoveryToken": "",
"AgentHeartbeatInterval": strconv.Itoa(AgentHeartbeatInterval),
"AgentWebsocketUpgradeEnabled": strconv.FormatBool(AgentWebsocketUpgradeEnabled),
+11 -15
View File
@@ -11,27 +11,23 @@ var enabledOptionAppliers = map[string]func(bool){
"PasswordLoginEnabled": func(v bool) { PasswordLoginEnabled = v },
"CapLoginEnabled": func(v bool) { CapLoginEnabled = v },
"EmailVerificationEnabled": func(v bool) { EmailVerificationEnabled = v },
"GitHubOAuthEnabled": func(v bool) { GitHubOAuthEnabled = v },
"WeChatAuthEnabled": func(v bool) { WeChatAuthEnabled = v },
"AgentWebsocketUpgradeEnabled": func(v bool) { AgentWebsocketUpgradeEnabled = v },
"UptimeKumaEnabled": func(v bool) { UptimeKumaEnabled = v },
"DatabaseAutoCleanupEnabled": func(v bool) { DatabaseAutoCleanupEnabled = v },
}
var stringOptionAppliers = map[string]func(string){
"ServerAddress": func(v string) { ServerAddress = v },
"GitHubClientId": func(v string) { GitHubClientID = v },
"Footer": func(v string) { Footer = v },
"HomePageLink": func(v string) { HomePageLink = v },
"SystemName": func(v string) { SystemName = v },
"WeChatAccountQRCodeImageURL": func(v string) { WeChatAccountQRCodeImageURL = v },
"AgentDiscoveryToken": func(v string) { AgentDiscoveryToken = v },
"GeoIPProvider": func(v string) { GeoIPProvider = v },
"UptimeKumaUrl": func(v string) { UptimeKumaURL = v },
"UptimeKumaUsername": func(v string) { UptimeKumaUsername = v },
optionKeyUptimeKumaPassword: func(v string) { UptimeKumaPassword = v },
"UptimeKumaMonitorScope": func(v string) { UptimeKumaMonitorScope = v },
"UptimeKumaSelectedSites": func(v string) { UptimeKumaSelectedSites = v },
"ServerAddress": func(v string) { ServerAddress = v },
"Footer": func(v string) { Footer = v },
"HomePageLink": func(v string) { HomePageLink = v },
"SystemName": func(v string) { SystemName = v },
"AgentDiscoveryToken": func(v string) { AgentDiscoveryToken = v },
"GeoIPProvider": func(v string) { GeoIPProvider = v },
"UptimeKumaUrl": func(v string) { UptimeKumaURL = v },
"UptimeKumaUsername": func(v string) { UptimeKumaUsername = v },
optionKeyUptimeKumaPassword: func(v string) { UptimeKumaPassword = v },
"UptimeKumaMonitorScope": func(v string) { UptimeKumaMonitorScope = v },
"UptimeKumaSelectedSites": func(v string) { UptimeKumaSelectedSites = v },
}
func applyEnabledOptionMirror(key, value string) {