|
|
|
|
@@ -63,7 +63,13 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
promoService := service.NewPromoService(promoCodeRepository, userRepository, billingCacheService, client, apiKeyAuthCacheInvalidator)
|
|
|
|
|
authService := service.NewAuthService(userRepository, configConfig, settingService, emailService, turnstileService, emailQueueService, promoService)
|
|
|
|
|
userService := service.NewUserService(userRepository, apiKeyAuthCacheInvalidator)
|
|
|
|
|
authHandler := handler.NewAuthHandler(configConfig, authService, userService, settingService, promoService)
|
|
|
|
|
secretEncryptor, err := repository.NewAESEncryptor(configConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
totpCache := repository.NewTotpCache(redisClient)
|
|
|
|
|
totpService := service.NewTotpService(userRepository, secretEncryptor, totpCache, settingService, emailService, emailQueueService)
|
|
|
|
|
authHandler := handler.NewAuthHandler(configConfig, authService, userService, settingService, promoService, totpService)
|
|
|
|
|
userHandler := handler.NewUserHandler(userService)
|
|
|
|
|
apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService)
|
|
|
|
|
usageLogRepository := repository.NewUsageLogRepository(client, db)
|
|
|
|
|
@@ -75,6 +81,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
redeemService := service.NewRedeemService(redeemCodeRepository, userRepository, subscriptionService, redeemCache, billingCacheService, client, apiKeyAuthCacheInvalidator)
|
|
|
|
|
redeemHandler := handler.NewRedeemHandler(redeemService)
|
|
|
|
|
subscriptionHandler := handler.NewSubscriptionHandler(subscriptionService)
|
|
|
|
|
announcementRepository := repository.NewAnnouncementRepository(client)
|
|
|
|
|
announcementReadRepository := repository.NewAnnouncementReadRepository(client)
|
|
|
|
|
announcementService := service.NewAnnouncementService(announcementRepository, announcementReadRepository, userRepository, userSubscriptionRepository)
|
|
|
|
|
announcementHandler := handler.NewAnnouncementHandler(announcementService)
|
|
|
|
|
dashboardAggregationRepository := repository.NewDashboardAggregationRepository(db)
|
|
|
|
|
dashboardStatsCache := repository.NewDashboardCache(redisClient, configConfig)
|
|
|
|
|
dashboardService := service.NewDashboardService(usageLogRepository, dashboardAggregationRepository, dashboardStatsCache, configConfig)
|
|
|
|
|
@@ -84,7 +94,8 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
}
|
|
|
|
|
dashboardAggregationService := service.ProvideDashboardAggregationService(dashboardAggregationRepository, timingWheelService, configConfig)
|
|
|
|
|
dashboardHandler := admin.NewDashboardHandler(dashboardService, dashboardAggregationService)
|
|
|
|
|
accountRepository := repository.NewAccountRepository(client, db)
|
|
|
|
|
schedulerCache := repository.NewSchedulerCache(redisClient)
|
|
|
|
|
accountRepository := repository.NewAccountRepository(client, db, schedulerCache)
|
|
|
|
|
proxyRepository := repository.NewProxyRepository(client, db)
|
|
|
|
|
proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig)
|
|
|
|
|
proxyLatencyCache := repository.NewProxyLatencyCache(redisClient)
|
|
|
|
|
@@ -105,21 +116,23 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
geminiTokenCache := repository.NewGeminiTokenCache(redisClient)
|
|
|
|
|
compositeTokenCacheInvalidator := service.NewCompositeTokenCacheInvalidator(geminiTokenCache)
|
|
|
|
|
rateLimitService := service.ProvideRateLimitService(accountRepository, usageLogRepository, configConfig, geminiQuotaService, tempUnschedCache, timeoutCounterCache, settingService, compositeTokenCacheInvalidator)
|
|
|
|
|
claudeUsageFetcher := repository.NewClaudeUsageFetcher()
|
|
|
|
|
httpUpstream := repository.NewHTTPUpstream(configConfig)
|
|
|
|
|
claudeUsageFetcher := repository.NewClaudeUsageFetcher(httpUpstream)
|
|
|
|
|
antigravityQuotaFetcher := service.NewAntigravityQuotaFetcher(proxyRepository)
|
|
|
|
|
usageCache := service.NewUsageCache()
|
|
|
|
|
accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache)
|
|
|
|
|
identityCache := repository.NewIdentityCache(redisClient)
|
|
|
|
|
accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache, identityCache)
|
|
|
|
|
geminiTokenProvider := service.NewGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService)
|
|
|
|
|
gatewayCache := repository.NewGatewayCache(redisClient)
|
|
|
|
|
antigravityTokenProvider := service.NewAntigravityTokenProvider(accountRepository, geminiTokenCache, antigravityOAuthService)
|
|
|
|
|
httpUpstream := repository.NewHTTPUpstream(configConfig)
|
|
|
|
|
antigravityGatewayService := service.NewAntigravityGatewayService(accountRepository, gatewayCache, antigravityTokenProvider, rateLimitService, httpUpstream, settingService)
|
|
|
|
|
accountTestService := service.NewAccountTestService(accountRepository, geminiTokenProvider, antigravityGatewayService, httpUpstream, configConfig)
|
|
|
|
|
concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig)
|
|
|
|
|
concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig)
|
|
|
|
|
crsSyncService := service.NewCRSSyncService(accountRepository, proxyRepository, oAuthService, openAIOAuthService, geminiOAuthService, configConfig)
|
|
|
|
|
sessionLimitCache := repository.ProvideSessionLimitCache(redisClient, configConfig)
|
|
|
|
|
accountHandler := admin.NewAccountHandler(adminService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, rateLimitService, accountUsageService, accountTestService, concurrencyService, crsSyncService, sessionLimitCache)
|
|
|
|
|
accountHandler := admin.NewAccountHandler(adminService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, rateLimitService, accountUsageService, accountTestService, concurrencyService, crsSyncService, sessionLimitCache, compositeTokenCacheInvalidator)
|
|
|
|
|
adminAnnouncementHandler := admin.NewAnnouncementHandler(announcementService)
|
|
|
|
|
oAuthHandler := admin.NewOAuthHandler(oAuthService)
|
|
|
|
|
openAIOAuthHandler := admin.NewOpenAIOAuthHandler(openAIOAuthService, adminService)
|
|
|
|
|
geminiOAuthHandler := admin.NewGeminiOAuthHandler(geminiOAuthService)
|
|
|
|
|
@@ -128,7 +141,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
adminRedeemHandler := admin.NewRedeemHandler(adminService)
|
|
|
|
|
promoHandler := admin.NewPromoHandler(promoService)
|
|
|
|
|
opsRepository := repository.NewOpsRepository(db)
|
|
|
|
|
schedulerCache := repository.NewSchedulerCache(redisClient)
|
|
|
|
|
schedulerOutboxRepository := repository.NewSchedulerOutboxRepository(db)
|
|
|
|
|
schedulerSnapshotService := service.ProvideSchedulerSnapshotService(schedulerCache, schedulerOutboxRepository, accountRepository, groupRepository, configConfig)
|
|
|
|
|
pricingRemoteClient := repository.ProvidePricingRemoteClient(configConfig)
|
|
|
|
|
@@ -137,7 +149,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
billingService := service.NewBillingService(configConfig, pricingService)
|
|
|
|
|
identityCache := repository.NewIdentityCache(redisClient)
|
|
|
|
|
identityService := service.NewIdentityService(identityCache)
|
|
|
|
|
deferredService := service.ProvideDeferredService(accountRepository, timingWheelService)
|
|
|
|
|
claudeTokenProvider := service.NewClaudeTokenProvider(accountRepository, geminiTokenCache, oAuthService)
|
|
|
|
|
@@ -154,16 +165,19 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
updateService := service.ProvideUpdateService(updateCache, gitHubReleaseClient, serviceBuildInfo)
|
|
|
|
|
systemHandler := handler.ProvideSystemHandler(updateService)
|
|
|
|
|
adminSubscriptionHandler := admin.NewSubscriptionHandler(subscriptionService)
|
|
|
|
|
adminUsageHandler := admin.NewUsageHandler(usageService, apiKeyService, adminService)
|
|
|
|
|
usageCleanupRepository := repository.NewUsageCleanupRepository(client, db)
|
|
|
|
|
usageCleanupService := service.ProvideUsageCleanupService(usageCleanupRepository, timingWheelService, dashboardAggregationService, configConfig)
|
|
|
|
|
adminUsageHandler := admin.NewUsageHandler(usageService, apiKeyService, adminService, usageCleanupService)
|
|
|
|
|
userAttributeDefinitionRepository := repository.NewUserAttributeDefinitionRepository(client)
|
|
|
|
|
userAttributeValueRepository := repository.NewUserAttributeValueRepository(client)
|
|
|
|
|
userAttributeService := service.NewUserAttributeService(userAttributeDefinitionRepository, userAttributeValueRepository)
|
|
|
|
|
userAttributeHandler := admin.NewUserAttributeHandler(userAttributeService)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler)
|
|
|
|
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, configConfig)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler)
|
|
|
|
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, configConfig)
|
|
|
|
|
openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService, configConfig)
|
|
|
|
|
handlerSettingHandler := handler.ProvideSettingHandler(settingService, buildInfo)
|
|
|
|
|
handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, handlerSettingHandler)
|
|
|
|
|
totpHandler := handler.NewTotpHandler(totpService)
|
|
|
|
|
handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, announcementHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, handlerSettingHandler, totpHandler)
|
|
|
|
|
jwtAuthMiddleware := middleware.NewJWTAuthMiddleware(authService, userService)
|
|
|
|
|
adminAuthMiddleware := middleware.NewAdminAuthMiddleware(authService, userService, settingService)
|
|
|
|
|
apiKeyAuthMiddleware := middleware.NewAPIKeyAuthMiddleware(apiKeyService, subscriptionService, configConfig)
|
|
|
|
|
@@ -174,9 +188,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
opsAlertEvaluatorService := service.ProvideOpsAlertEvaluatorService(opsService, opsRepository, emailService, redisClient, configConfig)
|
|
|
|
|
opsCleanupService := service.ProvideOpsCleanupService(opsRepository, db, redisClient, configConfig)
|
|
|
|
|
opsScheduledReportService := service.ProvideOpsScheduledReportService(opsService, userService, emailService, redisClient, configConfig)
|
|
|
|
|
tokenRefreshService := service.ProvideTokenRefreshService(accountRepository, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, compositeTokenCacheInvalidator, configConfig)
|
|
|
|
|
tokenRefreshService := service.ProvideTokenRefreshService(accountRepository, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, compositeTokenCacheInvalidator, schedulerCache, configConfig)
|
|
|
|
|
accountExpiryService := service.ProvideAccountExpiryService(accountRepository)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, schedulerSnapshotService, tokenRefreshService, accountExpiryService, pricingService, emailQueueService, billingCacheService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService)
|
|
|
|
|
subscriptionExpiryService := service.ProvideSubscriptionExpiryService(userSubscriptionRepository)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, pricingService, emailQueueService, billingCacheService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService)
|
|
|
|
|
application := &Application{
|
|
|
|
|
Server: httpServer,
|
|
|
|
|
Cleanup: v,
|
|
|
|
|
@@ -209,6 +224,8 @@ func provideCleanup(
|
|
|
|
|
schedulerSnapshot *service.SchedulerSnapshotService,
|
|
|
|
|
tokenRefresh *service.TokenRefreshService,
|
|
|
|
|
accountExpiry *service.AccountExpiryService,
|
|
|
|
|
subscriptionExpiry *service.SubscriptionExpiryService,
|
|
|
|
|
usageCleanup *service.UsageCleanupService,
|
|
|
|
|
pricing *service.PricingService,
|
|
|
|
|
emailQueue *service.EmailQueueService,
|
|
|
|
|
billingCache *service.BillingCacheService,
|
|
|
|
|
@@ -261,6 +278,12 @@ func provideCleanup(
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"UsageCleanupService", func() error {
|
|
|
|
|
if usageCleanup != nil {
|
|
|
|
|
usageCleanup.Stop()
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"TokenRefreshService", func() error {
|
|
|
|
|
tokenRefresh.Stop()
|
|
|
|
|
return nil
|
|
|
|
|
@@ -269,6 +292,10 @@ func provideCleanup(
|
|
|
|
|
accountExpiry.Stop()
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"SubscriptionExpiryService", func() error {
|
|
|
|
|
subscriptionExpiry.Stop()
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"PricingService", func() error {
|
|
|
|
|
pricing.Stop()
|
|
|
|
|
return nil
|
|
|
|
|
|