Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func defaultBootstrapSettings() *database.SystemSettings {
BackgroundRefreshIntervalMinutes: 2,
UsageProbeMaxAgeMinutes: 10,
RecoveryProbeIntervalMinutes: 30,
LazyMode: false,
PgMaxConns: 50,
RedisPoolSize: 30,
PromptFilterMode: "monitor",
Expand Down
46 changes: 30 additions & 16 deletions admin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ type accountResponse struct {
ProxyURL string `json:"proxy_url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CodexUsageUpdatedAt string `json:"codex_usage_updated_at,omitempty"`
ActiveRequests int64 `json:"active_requests"`
TotalRequests int64 `json:"total_requests"`
LastUsedAt string `json:"last_used_at"`
Expand Down Expand Up @@ -517,8 +518,8 @@ func (h *Handler) ListAccounts(c *gin.Context) {
Status: row.Status,
ErrorMessage: row.ErrorMessage,
ATOnly: !isOpenAIResponsesAccount && row.GetCredential("refresh_token") == "" && row.GetCredential("access_token") != "",
CreditEnabled: row.CreditEnabled,
CreditSkipUsageWindow: row.CreditSkipUsageWindow,
CreditEnabled: row.CreditEnabled,
CreditSkipUsageWindow: row.CreditSkipUsageWindow,
AccountType: row.Type,
OpenAIResponsesAPI: isOpenAIResponsesAccount,
BaseURL: baseURL,
Expand All @@ -534,6 +535,7 @@ func (h *Handler) ListAccounts(c *gin.Context) {
BaseConcurrencyEffective: effectiveBaseConcurrency(row.BaseConcurrencyOverride, int64(h.store.GetMaxConcurrency())),
CreatedAt: row.CreatedAt.Format(time.RFC3339),
UpdatedAt: row.UpdatedAt.Format(time.RFC3339),
CodexUsageUpdatedAt: row.GetCredential("codex_usage_updated_at"),
}
if acc, ok := accountMap[row.ID]; ok {
acc.Mu().RLock()
Expand Down Expand Up @@ -1191,16 +1193,18 @@ func (h *Handler) AddAccount(c *gin.Context) {
}
h.store.AddAccount(newAcc)

// 异步刷新 AT
go func(accountID int64) {
refreshCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := h.store.RefreshSingle(refreshCtx, accountID); err != nil {
log.Printf("新账号 %d 刷新失败: %v", accountID, err)
} else {
log.Printf("新账号 %d 刷新成功,已加入号池", accountID)
}
}(id)
if !h.store.GetLazyMode() {
// 异步刷新 AT
go func(accountID int64) {
refreshCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := h.store.RefreshSingle(refreshCtx, accountID); err != nil {
log.Printf("新账号 %d 刷新失败: %v", accountID, err)
} else {
log.Printf("新账号 %d 刷新成功,已加入号池", accountID)
}
}(id)
}
}

// 记录安全审计日志
Expand Down Expand Up @@ -2300,7 +2304,7 @@ func (h *Handler) importAccountsCommon(c *gin.Context, tokens []importToken, pro
newAcc := accountFromCredentialSeed(id, proxyURL, seed)
h.store.AddAccount(newAcc)

if tok.accessToken == "" {
if tok.accessToken == "" && !h.store.GetLazyMode() {
// 后台异步刷新,不阻塞导入流程
go func(accountID int64) {
refreshCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Expand Down Expand Up @@ -3561,6 +3565,7 @@ type settingsResponse struct {
BackgroundRefreshIntervalMinutes int `json:"background_refresh_interval_minutes"`
UsageProbeMaxAgeMinutes int `json:"usage_probe_max_age_minutes"`
RecoveryProbeIntervalMinutes int `json:"recovery_probe_interval_minutes"`
LazyMode bool `json:"lazy_mode"`
ProxyURL string `json:"proxy_url"`
PgMaxConns int `json:"pg_max_conns"`
RedisPoolSize int `json:"redis_pool_size"`
Expand Down Expand Up @@ -3621,6 +3626,7 @@ type updateSettingsReq struct {
BackgroundRefreshIntervalMinutes *int `json:"background_refresh_interval_minutes"`
UsageProbeMaxAgeMinutes *int `json:"usage_probe_max_age_minutes"`
RecoveryProbeIntervalMinutes *int `json:"recovery_probe_interval_minutes"`
LazyMode *bool `json:"lazy_mode"`
ProxyURL *string `json:"proxy_url"`
PgMaxConns *int `json:"pg_max_conns"`
RedisPoolSize *int `json:"redis_pool_size"`
Expand Down Expand Up @@ -3761,6 +3767,7 @@ func (h *Handler) GetSettings(c *gin.Context) {
BackgroundRefreshIntervalMinutes: h.store.GetBackgroundRefreshIntervalMinutes(),
UsageProbeMaxAgeMinutes: h.store.GetUsageProbeMaxAgeMinutes(),
RecoveryProbeIntervalMinutes: h.store.GetRecoveryProbeIntervalMinutes(),
LazyMode: h.store.GetLazyMode(),
ProxyURL: h.store.GetProxyURL(),
PgMaxConns: h.pgMaxConns,
RedisPoolSize: h.redisPoolSize,
Expand All @@ -3773,7 +3780,7 @@ func (h *Handler) GetSettings(c *gin.Context) {
AutoCleanExpired: h.store.GetAutoCleanExpired(),
ProxyPoolEnabled: h.store.GetProxyPoolEnabled(),
FastSchedulerEnabled: h.store.FastSchedulerEnabled(),
SchedulerMode: h.store.GetSchedulerMode(),
SchedulerMode: h.store.GetSchedulerMode(),
MaxRetries: h.store.GetMaxRetries(),
MaxRateLimitRetries: h.store.GetMaxRateLimitRetries(),
AllowRemoteMigration: h.store.GetAllowRemoteMigration() && adminAuthSource != "disabled",
Expand Down Expand Up @@ -3929,6 +3936,11 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
log.Printf("设置已更新: recovery_probe_interval_minutes = %d", v)
}

if req.LazyMode != nil {
h.store.SetLazyMode(*req.LazyMode)
log.Printf("设置已更新: lazy_mode = %t", *req.LazyMode)
}

if req.ProxyURL != nil {
h.store.SetProxyURL(*req.ProxyURL)
log.Printf("设置已更新: proxy_url = %s", *req.ProxyURL)
Expand Down Expand Up @@ -4241,6 +4253,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
BackgroundRefreshIntervalMinutes: h.store.GetBackgroundRefreshIntervalMinutes(),
UsageProbeMaxAgeMinutes: h.store.GetUsageProbeMaxAgeMinutes(),
RecoveryProbeIntervalMinutes: h.store.GetRecoveryProbeIntervalMinutes(),
LazyMode: h.store.GetLazyMode(),
ProxyURL: h.store.GetProxyURL(),
PgMaxConns: h.pgMaxConns,
RedisPoolSize: h.redisPoolSize,
Expand All @@ -4252,7 +4265,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
AutoCleanExpired: h.store.GetAutoCleanExpired(),
ProxyPoolEnabled: h.store.GetProxyPoolEnabled(),
FastSchedulerEnabled: h.store.FastSchedulerEnabled(),
SchedulerMode: h.store.GetSchedulerMode(),
SchedulerMode: h.store.GetSchedulerMode(),
MaxRetries: h.store.GetMaxRetries(),
MaxRateLimitRetries: h.store.GetMaxRateLimitRetries(),
AllowRemoteMigration: h.store.GetAllowRemoteMigration() && hasAdminSecret,
Expand Down Expand Up @@ -4304,6 +4317,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
BackgroundRefreshIntervalMinutes: h.store.GetBackgroundRefreshIntervalMinutes(),
UsageProbeMaxAgeMinutes: h.store.GetUsageProbeMaxAgeMinutes(),
RecoveryProbeIntervalMinutes: h.store.GetRecoveryProbeIntervalMinutes(),
LazyMode: h.store.GetLazyMode(),
ProxyURL: h.store.GetProxyURL(),
PgMaxConns: h.pgMaxConns,
RedisPoolSize: h.redisPoolSize,
Expand All @@ -4316,7 +4330,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
AutoCleanExpired: h.store.GetAutoCleanExpired(),
ProxyPoolEnabled: h.store.GetProxyPoolEnabled(),
FastSchedulerEnabled: h.store.FastSchedulerEnabled(),
SchedulerMode: h.store.GetSchedulerMode(),
SchedulerMode: h.store.GetSchedulerMode(),
MaxRetries: h.store.GetMaxRetries(),
MaxRateLimitRetries: h.store.GetMaxRateLimitRetries(),
AllowRemoteMigration: h.store.GetAllowRemoteMigration() && adminAuthSource != "disabled",
Expand Down
Loading
Loading