Files
tokens-reef/backend/internal/config/gateway.go
pham 0e057904e6
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled
refactor: 彻底移除 Sora 视频生成模块(全栈清理)
## 后端变更
- 删除 21 个 sora_*.go 服务文件(service/handler/repository/routes)
- 删除 Sora 相关 migration 文件(046/047/063/090)
- 清理 config 中的 sora_* 配置项和平台常量
- 清理 wire 依赖注入中的 Sora 组件
- 修复 wire_gen.go 语法错误(缺少逗号和闭合括号)
- 移除 go.mod 中的 go-sora2api 依赖
- 更新 ent schema usage_log.go 注释

## 前端变更
- 删除 SoraView、SoraAdminView 及 8 个 Sora 子组件
- 删除 sora API 层和路由配置
- 清理 UserEditModal 中的 Sora 存储配额 UI
- 清理 types/index.ts 中 Sora 相关类型定义
- 清理 stores/app.ts 默认配置
- 清理 i18n 翻译文件 en.ts/zh.ts (~110 行)
- 更新相关测试文件

## 文档更新
- README.md / README_CN.md / README_JA.md: 移除 Sora 状态说明和配置段落
- PROJECT_DIFF.md: 移除 Sora 相关差异描述

## 验证结果
-  Go 编译通过 (go build ./...)
-  TypeScript 类型检查通过 (vue-tsc --noEmit)
-  后端测试全通过 (0 failures)
-  前端测试全通过 (59 files, 329 tests, 0 failures)
-  前端生产构建成功 (23.81s)
2026-05-10 14:15:45 +08:00

96 lines
5.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import "time"
// GatewayConfig API网关相关配置
type GatewayConfig struct {
ResponseHeaderTimeout int `mapstructure:"response_header_timeout"` // 等待上游响应头超时0=无超时
MaxBodySize int64 `mapstructure:"max_body_size"` // 请求体最大字节数
UpstreamResponseReadMaxBytes int64 `mapstructure:"upstream_response_read_max_bytes"` // 非流式上游响应体读取上限
ProxyProbeResponseReadMaxBytes int64 `mapstructure:"proxy_probe_response_read_max_bytes"` // 代理探测响应读取上限
GeminiDebugResponseHeaders bool `mapstructure:"gemini_debug_response_headers"`
ConnectionPoolIsolation string `mapstructure:"connection_pool_isolation"` // proxy/account/account_proxy
ForceCodexCLI bool `mapstructure:"force_codex_cli"`
ForcedCodexInstructionsTemplateFile string `mapstructure:"forced_codex_instructions_template_file"`
ForcedCodexInstructionsTemplate string `mapstructure:"-"`
OpenAIPassthroughAllowTimeoutHeaders bool `mapstructure:"openai_passthrough_allow_timeout_headers"`
OpenAIWS GatewayOpenAIWSConfig `mapstructure:"openai_ws"`
// HTTP 上游连接池配置
MaxIdleConns int `mapstructure:"max_idle_conns"`
MaxIdleConnsPerHost int `mapstructure:"max_idle_conns_per_host"`
MaxConnsPerHost int `mapstructure:"max_conns_per_host"`
IdleConnTimeoutSeconds int `mapstructure:"idle_conn_timeout_seconds"`
MaxUpstreamClients int `mapstructure:"max_upstream_clients"`
ClientIdleTTLSeconds int `mapstructure:"client_idle_ttl_seconds"`
ConcurrencySlotTTLMinutes int `mapstructure:"concurrency_slot_ttl_minutes"`
SessionIdleTimeoutMinutes int `mapstructure:"session_idle_timeout_seconds"`
StreamDataIntervalTimeout int `mapstructure:"stream_data_interval_timeout"` // 流数据间隔超时0=禁用
StreamKeepaliveInterval int `mapstructure:"stream_keepalive_interval"` // 流式 keepalive 间隔0=禁用
MaxLineSize int `mapstructure:"max_line_size"` // SSE 单行最大字节数
LogUpstreamErrorBody bool `mapstructure:"log_upstream_error_body"`
LogUpstreamErrorBodyMaxBytes int `mapstructure:"log_upstream_error_body_max_bytes"`
InjectBetaForAPIKey bool `mapstructure:"inject_beta_for_apikey"`
FailoverOn400 bool `mapstructure:"failover_on_400"`
MaxAccountSwitches int `mapstructure:"max_account_switches"`
MaxAccountSwitchesGemini int `mapstructure:"max_account_switches_gemini"`
AntigravityFallbackCooldownMinutes int `mapstructure:"antigravity_fallback_cooldown_minutes"`
Scheduling GatewaySchedulingConfig `mapstructure:"scheduling"`
TLSFingerprint TLSFingerprintConfig `mapstructure:"tls_fingerprint"`
UsageRecord GatewayUsageRecordConfig `mapstructure:"usage_record"`
UserGroupRateCacheTTLSeconds int `mapstructure:"user_group_rate_cache_ttl_seconds"`
ModelsListCacheTTLSeconds int `mapstructure:"models_list_cache_ttl_seconds"`
UserMessageQueue UserMessageQueueConfig `mapstructure:"user_message_queue"`
}
// UserMessageQueueConfig 用户消息串行队列配置
type UserMessageQueueConfig struct {
Mode string `mapstructure:"mode"` // serialize/throttle/""
Enabled bool `mapstructure:"enabled"` // 向后兼容
LockTTLMs int `mapstructure:"lock_ttl_ms"`
WaitTimeoutMs int `mapstructure:"wait_timeout_ms"`
MinDelayMs int `mapstructure:"min_delay_ms"`
MaxDelayMs int `mapstructure:"max_delay_ms"`
CleanupIntervalSeconds int `mapstructure:"cleanup_interval_seconds"`
}
func (c *UserMessageQueueConfig) WaitTimeout() time.Duration {
if c.WaitTimeoutMs <= 0 { return 30 * time.Second }
return time.Duration(c.WaitTimeoutMs) * time.Millisecond
}
func (c *UserMessageQueueConfig) GetEffectiveMode() string {
if c.Mode == UMQModeSerialize || c.Mode == UMQModeThrottle { return c.Mode }
if c.Enabled { return UMQModeSerialize }
return ""
}
// GatewaySchedulingConfig 账号调度相关配置
type GatewaySchedulingConfig struct {
StickySessionMaxWaiting int `mapstructure:"sticky_session_max_waiting"`
StickySessionWaitTimeout time.Duration `mapstructure:"sticky_session_wait_timeout"`
FallbackWaitTimeout time.Duration `mapstructure:"fallback_wait_timeout"`
FallbackMaxWaiting int `mapstructure:"fallback_max_waiting"`
FallbackSelectionMode string `mapstructure:"fallback_selection_mode"`
LoadBatchEnabled bool `mapstructure:"load_batch_enabled"`
SnapshotMGetChunkSize int `mapstructure:"snapshot_mget_chunk_size"`
SnapshotWriteChunkSize int `mapstructure:"snapshot_write_chunk_size"`
SlotCleanupInterval time.Duration `mapstructure:"slot_cleanup_interval"`
DbFallbackEnabled bool `mapstructure:"db_fallback_enabled"`
DbFallbackTimeoutSeconds int `mapstructure:"db_fallback_timeout_seconds"`
DbFallbackMaxQPS int `mapstructure:"db_fallback_max_qps"`
OutboxPollIntervalSeconds int `mapstructure:"outbox_poll_interval_seconds"`
OutboxLagWarnSeconds int `mapstructure:"outbox_lag_warn_seconds"`
OutboxLagRebuildSeconds int `mapstructure:"outbox_lag_rebuild_seconds"`
OutboxLagRebuildFailures int `mapstructure:"outbox_lag_rebuild_failures"`
OutboxBacklogRebuildRows int `mapstructure:"outbox_backlog_rebuild_rows"`
FullRebuildIntervalSeconds int `mapstructure:"full_rebuild_interval_seconds"`
}