|
|
|
|
@@ -58,15 +58,16 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
promoCodeRepository := repository.NewPromoCodeRepository(client)
|
|
|
|
|
billingCache := repository.NewBillingCache(redisClient)
|
|
|
|
|
userSubscriptionRepository := repository.NewUserSubscriptionRepository(client)
|
|
|
|
|
billingCacheService := service.NewBillingCacheService(billingCache, userRepository, userSubscriptionRepository, configConfig)
|
|
|
|
|
apiKeyRepository := repository.NewAPIKeyRepository(client)
|
|
|
|
|
apiKeyRepository := repository.NewAPIKeyRepository(client, db)
|
|
|
|
|
billingCacheService := service.NewBillingCacheService(billingCache, userRepository, userSubscriptionRepository, apiKeyRepository, configConfig)
|
|
|
|
|
userGroupRateRepository := repository.NewUserGroupRateRepository(db)
|
|
|
|
|
apiKeyCache := repository.NewAPIKeyCache(redisClient)
|
|
|
|
|
apiKeyService := service.NewAPIKeyService(apiKeyRepository, userRepository, groupRepository, userSubscriptionRepository, userGroupRateRepository, apiKeyCache, configConfig)
|
|
|
|
|
apiKeyService.SetRateLimitCacheInvalidator(billingCache)
|
|
|
|
|
apiKeyAuthCacheInvalidator := service.ProvideAPIKeyAuthCacheInvalidator(apiKeyService)
|
|
|
|
|
promoService := service.NewPromoService(promoCodeRepository, userRepository, billingCacheService, client, apiKeyAuthCacheInvalidator)
|
|
|
|
|
subscriptionService := service.NewSubscriptionService(groupRepository, userSubscriptionRepository, billingCacheService, client, configConfig)
|
|
|
|
|
authService := service.NewAuthService(userRepository, redeemCodeRepository, refreshTokenCache, configConfig, settingService, emailService, turnstileService, emailQueueService, promoService, subscriptionService)
|
|
|
|
|
authService := service.NewAuthService(client, userRepository, redeemCodeRepository, refreshTokenCache, configConfig, settingService, emailService, turnstileService, emailQueueService, promoService, subscriptionService)
|
|
|
|
|
userService := service.NewUserService(userRepository, apiKeyAuthCacheInvalidator, billingCache)
|
|
|
|
|
redeemCache := repository.NewRedeemCache(redisClient)
|
|
|
|
|
redeemService := service.NewRedeemService(redeemCodeRepository, userRepository, subscriptionService, redeemCache, billingCacheService, client, apiKeyAuthCacheInvalidator)
|
|
|
|
|
@@ -80,6 +81,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
userHandler := handler.NewUserHandler(userService)
|
|
|
|
|
apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService)
|
|
|
|
|
usageLogRepository := repository.NewUsageLogRepository(client, db)
|
|
|
|
|
usageBillingRepository := repository.NewUsageBillingRepository(client, db)
|
|
|
|
|
usageService := service.NewUsageService(usageLogRepository, userRepository, client, apiKeyAuthCacheInvalidator)
|
|
|
|
|
usageHandler := handler.NewUsageHandler(usageService, apiKeyService)
|
|
|
|
|
redeemHandler := handler.NewRedeemHandler(redeemService)
|
|
|
|
|
@@ -103,7 +105,8 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
proxyRepository := repository.NewProxyRepository(client, db)
|
|
|
|
|
proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig)
|
|
|
|
|
proxyLatencyCache := repository.NewProxyLatencyCache(redisClient)
|
|
|
|
|
adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, soraAccountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService)
|
|
|
|
|
privacyClientFactory := providePrivacyClientFactory()
|
|
|
|
|
adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, soraAccountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory)
|
|
|
|
|
concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig)
|
|
|
|
|
concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig)
|
|
|
|
|
adminUserHandler := admin.NewUserHandler(adminService, concurrencyService)
|
|
|
|
|
@@ -121,6 +124,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
tempUnschedCache := repository.NewTempUnschedCache(redisClient)
|
|
|
|
|
timeoutCounterCache := repository.NewTimeoutCounterCache(redisClient)
|
|
|
|
|
geminiTokenCache := repository.NewGeminiTokenCache(redisClient)
|
|
|
|
|
oauthRefreshAPI := service.NewOAuthRefreshAPI(accountRepository, geminiTokenCache)
|
|
|
|
|
compositeTokenCacheInvalidator := service.NewCompositeTokenCacheInvalidator(geminiTokenCache)
|
|
|
|
|
rateLimitService := service.ProvideRateLimitService(accountRepository, usageLogRepository, configConfig, geminiQuotaService, tempUnschedCache, timeoutCounterCache, settingService, compositeTokenCacheInvalidator)
|
|
|
|
|
httpUpstream := repository.NewHTTPUpstream(configConfig)
|
|
|
|
|
@@ -129,11 +133,11 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
usageCache := service.NewUsageCache()
|
|
|
|
|
identityCache := repository.NewIdentityCache(redisClient)
|
|
|
|
|
accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache, identityCache)
|
|
|
|
|
geminiTokenProvider := service.NewGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService)
|
|
|
|
|
geminiTokenProvider := service.ProvideGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService, oauthRefreshAPI)
|
|
|
|
|
gatewayCache := repository.NewGatewayCache(redisClient)
|
|
|
|
|
schedulerOutboxRepository := repository.NewSchedulerOutboxRepository(db)
|
|
|
|
|
schedulerSnapshotService := service.ProvideSchedulerSnapshotService(schedulerCache, schedulerOutboxRepository, accountRepository, groupRepository, configConfig)
|
|
|
|
|
antigravityTokenProvider := service.NewAntigravityTokenProvider(accountRepository, geminiTokenCache, antigravityOAuthService)
|
|
|
|
|
antigravityTokenProvider := service.ProvideAntigravityTokenProvider(accountRepository, geminiTokenCache, antigravityOAuthService, oauthRefreshAPI)
|
|
|
|
|
antigravityGatewayService := service.NewAntigravityGatewayService(accountRepository, gatewayCache, schedulerSnapshotService, antigravityTokenProvider, rateLimitService, httpUpstream, settingService)
|
|
|
|
|
accountTestService := service.NewAccountTestService(accountRepository, geminiTokenProvider, antigravityGatewayService, httpUpstream, configConfig)
|
|
|
|
|
crsSyncService := service.NewCRSSyncService(accountRepository, proxyRepository, oAuthService, openAIOAuthService, geminiOAuthService, configConfig)
|
|
|
|
|
@@ -143,6 +147,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
adminAnnouncementHandler := admin.NewAnnouncementHandler(announcementService)
|
|
|
|
|
dataManagementService := service.NewDataManagementService()
|
|
|
|
|
dataManagementHandler := admin.NewDataManagementHandler(dataManagementService)
|
|
|
|
|
backupObjectStoreFactory := repository.NewS3BackupStoreFactory()
|
|
|
|
|
dbDumper := repository.NewPgDumper(configConfig)
|
|
|
|
|
backupService := service.ProvideBackupService(settingRepository, configConfig, secretEncryptor, backupObjectStoreFactory, dbDumper)
|
|
|
|
|
backupHandler := admin.NewBackupHandler(backupService, userService)
|
|
|
|
|
oAuthHandler := admin.NewOAuthHandler(oAuthService)
|
|
|
|
|
openAIOAuthHandler := admin.NewOpenAIOAuthHandler(openAIOAuthService, adminService)
|
|
|
|
|
geminiOAuthHandler := admin.NewGeminiOAuthHandler(geminiOAuthService)
|
|
|
|
|
@@ -159,11 +167,11 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
billingService := service.NewBillingService(configConfig, pricingService)
|
|
|
|
|
identityService := service.NewIdentityService(identityCache)
|
|
|
|
|
deferredService := service.ProvideDeferredService(accountRepository, timingWheelService)
|
|
|
|
|
claudeTokenProvider := service.NewClaudeTokenProvider(accountRepository, geminiTokenCache, oAuthService)
|
|
|
|
|
claudeTokenProvider := service.ProvideClaudeTokenProvider(accountRepository, geminiTokenCache, oAuthService, oauthRefreshAPI)
|
|
|
|
|
digestSessionStore := service.NewDigestSessionStore()
|
|
|
|
|
gatewayService := service.NewGatewayService(accountRepository, groupRepository, usageLogRepository, userRepository, userSubscriptionRepository, userGroupRateRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, identityService, httpUpstream, deferredService, claudeTokenProvider, sessionLimitCache, rpmCache, digestSessionStore)
|
|
|
|
|
openAITokenProvider := service.NewOpenAITokenProvider(accountRepository, geminiTokenCache, openAIOAuthService)
|
|
|
|
|
openAIGatewayService := service.NewOpenAIGatewayService(accountRepository, usageLogRepository, userRepository, userSubscriptionRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, httpUpstream, deferredService, openAITokenProvider)
|
|
|
|
|
gatewayService := service.NewGatewayService(accountRepository, groupRepository, usageLogRepository, usageBillingRepository, userRepository, userSubscriptionRepository, userGroupRateRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, identityService, httpUpstream, deferredService, claudeTokenProvider, sessionLimitCache, rpmCache, digestSessionStore, settingService)
|
|
|
|
|
openAITokenProvider := service.ProvideOpenAITokenProvider(accountRepository, geminiTokenCache, openAIOAuthService, oauthRefreshAPI)
|
|
|
|
|
openAIGatewayService := service.NewOpenAIGatewayService(accountRepository, usageLogRepository, usageBillingRepository, userRepository, userSubscriptionRepository, userGroupRateRepository, gatewayCache, configConfig, schedulerSnapshotService, concurrencyService, billingService, rateLimitService, billingCacheService, httpUpstream, deferredService, openAITokenProvider)
|
|
|
|
|
geminiMessagesCompatService := service.NewGeminiMessagesCompatService(accountRepository, groupRepository, gatewayCache, schedulerSnapshotService, geminiTokenProvider, rateLimitService, httpUpstream, antigravityGatewayService, configConfig)
|
|
|
|
|
opsSystemLogSink := service.ProvideOpsSystemLogSink(opsRepository)
|
|
|
|
|
opsService := service.NewOpsService(opsRepository, settingRepository, configConfig, accountRepository, userRepository, concurrencyService, gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, opsSystemLogSink)
|
|
|
|
|
@@ -194,9 +202,15 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
errorPassthroughService := service.NewErrorPassthroughService(errorPassthroughRepository, errorPassthroughCache)
|
|
|
|
|
errorPassthroughHandler := admin.NewErrorPassthroughHandler(errorPassthroughService)
|
|
|
|
|
adminAPIKeyHandler := admin.NewAdminAPIKeyHandler(adminService)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, adminAPIKeyHandler)
|
|
|
|
|
scheduledTestPlanRepository := repository.NewScheduledTestPlanRepository(db)
|
|
|
|
|
scheduledTestResultRepository := repository.NewScheduledTestResultRepository(db)
|
|
|
|
|
scheduledTestService := service.ProvideScheduledTestService(scheduledTestPlanRepository, scheduledTestResultRepository)
|
|
|
|
|
scheduledTestHandler := admin.NewScheduledTestHandler(scheduledTestService)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, adminAPIKeyHandler, scheduledTestHandler)
|
|
|
|
|
usageRecordWorkerPool := service.NewUsageRecordWorkerPool(configConfig)
|
|
|
|
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, configConfig, settingService)
|
|
|
|
|
userMsgQueueCache := repository.NewUserMsgQueueCache(redisClient)
|
|
|
|
|
userMessageQueueService := service.ProvideUserMessageQueueService(userMsgQueueCache, rpmCache, configConfig)
|
|
|
|
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, userMessageQueueService, configConfig, settingService)
|
|
|
|
|
openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, configConfig)
|
|
|
|
|
soraSDKClient := service.ProvideSoraSDKClient(configConfig, httpUpstream, openAITokenProvider, accountRepository, soraAccountRepository)
|
|
|
|
|
soraMediaStorage := service.ProvideSoraMediaStorage(configConfig)
|
|
|
|
|
@@ -219,10 +233,11 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
opsCleanupService := service.ProvideOpsCleanupService(opsRepository, db, redisClient, configConfig)
|
|
|
|
|
opsScheduledReportService := service.ProvideOpsScheduledReportService(opsService, userService, emailService, redisClient, configConfig)
|
|
|
|
|
soraMediaCleanupService := service.ProvideSoraMediaCleanupService(soraMediaStorage, configConfig)
|
|
|
|
|
tokenRefreshService := service.ProvideTokenRefreshService(accountRepository, soraAccountRepository, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, compositeTokenCacheInvalidator, schedulerCache, configConfig)
|
|
|
|
|
tokenRefreshService := service.ProvideTokenRefreshService(accountRepository, soraAccountRepository, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, compositeTokenCacheInvalidator, schedulerCache, configConfig, tempUnschedCache, privacyClientFactory, proxyRepository, oauthRefreshAPI)
|
|
|
|
|
accountExpiryService := service.ProvideAccountExpiryService(accountRepository)
|
|
|
|
|
subscriptionExpiryService := service.ProvideSubscriptionExpiryService(userSubscriptionRepository)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, soraMediaCleanupService, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, openAIGatewayService)
|
|
|
|
|
scheduledTestRunnerService := service.ProvideScheduledTestRunnerService(scheduledTestPlanRepository, scheduledTestService, accountTestService, rateLimitService, configConfig)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, soraMediaCleanupService, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService)
|
|
|
|
|
application := &Application{
|
|
|
|
|
Server: httpServer,
|
|
|
|
|
Cleanup: v,
|
|
|
|
|
@@ -237,6 +252,10 @@ type Application struct {
|
|
|
|
|
Cleanup func()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func providePrivacyClientFactory() service.PrivacyClientFactory {
|
|
|
|
|
return repository.CreatePrivacyReqClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func provideServiceBuildInfo(buildInfo handler.BuildInfo) service.BuildInfo {
|
|
|
|
|
return service.BuildInfo{
|
|
|
|
|
Version: buildInfo.Version,
|
|
|
|
|
@@ -270,6 +289,8 @@ func provideCleanup(
|
|
|
|
|
geminiOAuth *service.GeminiOAuthService,
|
|
|
|
|
antigravityOAuth *service.AntigravityOAuthService,
|
|
|
|
|
openAIGateway *service.OpenAIGatewayService,
|
|
|
|
|
scheduledTestRunner *service.ScheduledTestRunnerService,
|
|
|
|
|
backupSvc *service.BackupService,
|
|
|
|
|
) func() {
|
|
|
|
|
return func() {
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
|
@@ -399,6 +420,18 @@ func provideCleanup(
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"ScheduledTestRunnerService", func() error {
|
|
|
|
|
if scheduledTestRunner != nil {
|
|
|
|
|
scheduledTestRunner.Stop()
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"BackupService", func() error {
|
|
|
|
|
if backupSvc != nil {
|
|
|
|
|
backupSvc.Stop()
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infraSteps := []cleanupStep{
|
|
|
|
|
|