新增功能: - 新增 Sora 账号管理和 OAuth 认证 - 新增 Sora 视频/图片生成 API 网关 - 新增 Sora 任务调度和缓存机制 - 新增 Sora 使用统计和计费支持 - 前端增加 Sora 平台配置界面 安全修复(代码审核): - [SEC-001] 限制媒体下载响应体大小(图片 20MB、视频 200MB),防止 DoS 攻击 - [SEC-002] 限制 SDK API 响应大小(1MB),防止内存耗尽 - [SEC-003] 修复 SSRF 风险,添加 URL 验证并强制使用代理配置 BUG 修复(代码审核): - [BUG-001] 修复 for 循环内 defer 累积导致的资源泄漏 - [BUG-002] 修复图片并发槽位获取失败时已持有锁未释放的永久泄漏 性能优化(代码审核): - [PERF-001] 添加 Sentinel Token 缓存(3 分钟有效期),减少 PoW 计算开销 技术细节: - 使用 io.LimitReader 限制所有外部输入的大小 - 添加 urlvalidator 验证防止 SSRF 攻击 - 使用 sync.Map 实现线程安全的包级缓存 - 优化并发槽位管理,添加 releaseAll 模式防止泄漏 影响范围: - 后端:新增 Sora 相关数据模型、服务、网关和管理接口 - 前端:新增 Sora 平台配置、账号管理和监控界面 - 配置:新增 Sora 相关配置项和环境变量 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
127 lines
4.1 KiB
Go
127 lines
4.1 KiB
Go
package service
|
|
|
|
type SystemSettings struct {
|
|
RegistrationEnabled bool
|
|
EmailVerifyEnabled bool
|
|
PromoCodeEnabled bool
|
|
|
|
SMTPHost string
|
|
SMTPPort int
|
|
SMTPUsername string
|
|
SMTPPassword string
|
|
SMTPPasswordConfigured bool
|
|
SMTPFrom string
|
|
SMTPFromName string
|
|
SMTPUseTLS bool
|
|
|
|
TurnstileEnabled bool
|
|
TurnstileSiteKey string
|
|
TurnstileSecretKey string
|
|
TurnstileSecretKeyConfigured bool
|
|
|
|
// LinuxDo Connect OAuth 登录
|
|
LinuxDoConnectEnabled bool
|
|
LinuxDoConnectClientID string
|
|
LinuxDoConnectClientSecret string
|
|
LinuxDoConnectClientSecretConfigured bool
|
|
LinuxDoConnectRedirectURL string
|
|
|
|
SiteName string
|
|
SiteLogo string
|
|
SiteSubtitle string
|
|
APIBaseURL string
|
|
ContactInfo string
|
|
DocURL string
|
|
HomeContent string
|
|
HideCcsImportButton bool
|
|
|
|
DefaultConcurrency int
|
|
DefaultBalance float64
|
|
|
|
// Model fallback configuration
|
|
EnableModelFallback bool `json:"enable_model_fallback"`
|
|
FallbackModelAnthropic string `json:"fallback_model_anthropic"`
|
|
FallbackModelOpenAI string `json:"fallback_model_openai"`
|
|
FallbackModelGemini string `json:"fallback_model_gemini"`
|
|
FallbackModelAntigravity string `json:"fallback_model_antigravity"`
|
|
|
|
// Identity patch configuration (Claude -> Gemini)
|
|
EnableIdentityPatch bool `json:"enable_identity_patch"`
|
|
IdentityPatchPrompt string `json:"identity_patch_prompt"`
|
|
|
|
// Sora configuration
|
|
SoraBaseURL string
|
|
SoraTimeout int
|
|
SoraMaxRetries int
|
|
SoraPollInterval float64
|
|
SoraCallLogicMode string
|
|
SoraCacheEnabled bool
|
|
SoraCacheBaseDir string
|
|
SoraCacheVideoDir string
|
|
SoraCacheMaxBytes int64
|
|
SoraCacheAllowedHosts []string
|
|
SoraCacheUserDirEnabled bool
|
|
SoraWatermarkFreeEnabled bool
|
|
SoraWatermarkFreeParseMethod string
|
|
SoraWatermarkFreeCustomParseURL string
|
|
SoraWatermarkFreeCustomParseToken string
|
|
SoraWatermarkFreeFallbackOnFailure bool
|
|
SoraTokenRefreshEnabled bool
|
|
|
|
// Ops monitoring (vNext)
|
|
OpsMonitoringEnabled bool
|
|
OpsRealtimeMonitoringEnabled bool
|
|
OpsQueryModeDefault string
|
|
OpsMetricsIntervalSeconds int
|
|
}
|
|
|
|
type PublicSettings struct {
|
|
RegistrationEnabled bool
|
|
EmailVerifyEnabled bool
|
|
PromoCodeEnabled bool
|
|
TurnstileEnabled bool
|
|
TurnstileSiteKey string
|
|
SiteName string
|
|
SiteLogo string
|
|
SiteSubtitle string
|
|
APIBaseURL string
|
|
ContactInfo string
|
|
DocURL string
|
|
HomeContent string
|
|
HideCcsImportButton bool
|
|
LinuxDoOAuthEnabled bool
|
|
Version string
|
|
}
|
|
|
|
// StreamTimeoutSettings 流超时处理配置(仅控制超时后的处理方式,超时判定由网关配置控制)
|
|
type StreamTimeoutSettings struct {
|
|
// Enabled 是否启用流超时处理
|
|
Enabled bool `json:"enabled"`
|
|
// Action 超时后的处理方式: "temp_unsched" | "error" | "none"
|
|
Action string `json:"action"`
|
|
// TempUnschedMinutes 临时不可调度持续时间(分钟)
|
|
TempUnschedMinutes int `json:"temp_unsched_minutes"`
|
|
// ThresholdCount 触发阈值次数(累计多少次超时才触发)
|
|
ThresholdCount int `json:"threshold_count"`
|
|
// ThresholdWindowMinutes 阈值窗口时间(分钟)
|
|
ThresholdWindowMinutes int `json:"threshold_window_minutes"`
|
|
}
|
|
|
|
// StreamTimeoutAction 流超时处理方式常量
|
|
const (
|
|
StreamTimeoutActionTempUnsched = "temp_unsched" // 临时不可调度
|
|
StreamTimeoutActionError = "error" // 标记为错误状态
|
|
StreamTimeoutActionNone = "none" // 不处理
|
|
)
|
|
|
|
// DefaultStreamTimeoutSettings 返回默认的流超时配置
|
|
func DefaultStreamTimeoutSettings() *StreamTimeoutSettings {
|
|
return &StreamTimeoutSettings{
|
|
Enabled: false,
|
|
Action: StreamTimeoutActionTempUnsched,
|
|
TempUnschedMinutes: 5,
|
|
ThresholdCount: 3,
|
|
ThresholdWindowMinutes: 10,
|
|
}
|
|
}
|