feat(settings): support per-channel WeChat OAuth and persist payment options
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, value := range values {
|
||||
if trimmed := strings.TrimSpace(value); trimmed != "" {
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type SystemSettings struct {
|
||||
RegistrationEnabled bool
|
||||
EmailVerifyEnabled bool
|
||||
@@ -32,16 +43,26 @@ type SystemSettings struct {
|
||||
LinuxDoConnectRedirectURL string
|
||||
|
||||
// WeChat Connect OAuth 登录
|
||||
WeChatConnectEnabled bool
|
||||
WeChatConnectAppID string
|
||||
WeChatConnectAppSecret string
|
||||
WeChatConnectAppSecretConfigured bool
|
||||
WeChatConnectOpenEnabled bool
|
||||
WeChatConnectMPEnabled bool
|
||||
WeChatConnectMode string
|
||||
WeChatConnectScopes string
|
||||
WeChatConnectRedirectURL string
|
||||
WeChatConnectFrontendRedirectURL string
|
||||
WeChatConnectEnabled bool
|
||||
WeChatConnectAppID string
|
||||
WeChatConnectAppSecret string
|
||||
WeChatConnectAppSecretConfigured bool
|
||||
WeChatConnectOpenAppID string
|
||||
WeChatConnectOpenAppSecret string
|
||||
WeChatConnectOpenAppSecretConfigured bool
|
||||
WeChatConnectMPAppID string
|
||||
WeChatConnectMPAppSecret string
|
||||
WeChatConnectMPAppSecretConfigured bool
|
||||
WeChatConnectMobileAppID string
|
||||
WeChatConnectMobileAppSecret string
|
||||
WeChatConnectMobileAppSecretConfigured bool
|
||||
WeChatConnectOpenEnabled bool
|
||||
WeChatConnectMPEnabled bool
|
||||
WeChatConnectMobileEnabled bool
|
||||
WeChatConnectMode string
|
||||
WeChatConnectScopes string
|
||||
WeChatConnectRedirectURL string
|
||||
WeChatConnectFrontendRedirectURL string
|
||||
|
||||
// Generic OIDC OAuth 登录
|
||||
OIDCConnectEnabled bool
|
||||
@@ -173,15 +194,16 @@ type PublicSettings struct {
|
||||
CustomMenuItems string // JSON array of custom menu items
|
||||
CustomEndpoints string // JSON array of custom endpoints
|
||||
|
||||
LinuxDoOAuthEnabled bool
|
||||
WeChatOAuthEnabled bool
|
||||
WeChatOAuthOpenEnabled bool
|
||||
WeChatOAuthMPEnabled bool
|
||||
BackendModeEnabled bool
|
||||
PaymentEnabled bool
|
||||
OIDCOAuthEnabled bool
|
||||
OIDCOAuthProviderName string
|
||||
Version string
|
||||
LinuxDoOAuthEnabled bool
|
||||
WeChatOAuthEnabled bool
|
||||
WeChatOAuthOpenEnabled bool
|
||||
WeChatOAuthMPEnabled bool
|
||||
WeChatOAuthMobileEnabled bool
|
||||
BackendModeEnabled bool
|
||||
PaymentEnabled bool
|
||||
OIDCOAuthEnabled bool
|
||||
OIDCOAuthProviderName string
|
||||
Version string
|
||||
|
||||
BalanceLowNotifyEnabled bool
|
||||
AccountQuotaNotifyEnabled bool
|
||||
@@ -191,10 +213,17 @@ type PublicSettings struct {
|
||||
|
||||
type WeChatConnectOAuthConfig struct {
|
||||
Enabled bool
|
||||
AppID string
|
||||
AppSecret string
|
||||
LegacyAppID string
|
||||
LegacyAppSecret string
|
||||
OpenAppID string
|
||||
OpenAppSecret string
|
||||
MPAppID string
|
||||
MPAppSecret string
|
||||
MobileAppID string
|
||||
MobileAppSecret string
|
||||
OpenEnabled bool
|
||||
MPEnabled bool
|
||||
MobileEnabled bool
|
||||
Mode string
|
||||
Scopes string
|
||||
RedirectURL string
|
||||
@@ -205,18 +234,43 @@ func (cfg WeChatConnectOAuthConfig) SupportsMode(mode string) bool {
|
||||
switch normalizeWeChatConnectModeSetting(mode) {
|
||||
case "mp":
|
||||
return cfg.MPEnabled
|
||||
case "mobile":
|
||||
return cfg.MobileEnabled
|
||||
default:
|
||||
return cfg.OpenEnabled
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg WeChatConnectOAuthConfig) ScopeForMode(mode string) string {
|
||||
if normalizeWeChatConnectModeSetting(mode) == "mp" {
|
||||
switch normalizeWeChatConnectModeSetting(mode) {
|
||||
case "mp":
|
||||
return normalizeWeChatConnectScopeSetting(cfg.Scopes, "mp")
|
||||
case "mobile":
|
||||
return ""
|
||||
}
|
||||
return defaultWeChatConnectScopeForMode("open")
|
||||
}
|
||||
|
||||
func (cfg WeChatConnectOAuthConfig) AppIDForMode(mode string) string {
|
||||
switch normalizeWeChatConnectModeSetting(mode) {
|
||||
case "mp":
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.MPAppID, cfg.LegacyAppID))
|
||||
case "mobile":
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.MobileAppID, cfg.LegacyAppID))
|
||||
}
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.OpenAppID, cfg.LegacyAppID))
|
||||
}
|
||||
|
||||
func (cfg WeChatConnectOAuthConfig) AppSecretForMode(mode string) string {
|
||||
switch normalizeWeChatConnectModeSetting(mode) {
|
||||
case "mp":
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.MPAppSecret, cfg.LegacyAppSecret))
|
||||
case "mobile":
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.MobileAppSecret, cfg.LegacyAppSecret))
|
||||
}
|
||||
return strings.TrimSpace(firstNonEmpty(cfg.OpenAppSecret, cfg.LegacyAppSecret))
|
||||
}
|
||||
|
||||
// StreamTimeoutSettings 流超时处理配置(仅控制超时后的处理方式,超时判定由网关配置控制)
|
||||
type StreamTimeoutSettings struct {
|
||||
// Enabled 是否启用流超时处理
|
||||
|
||||
Reference in New Issue
Block a user