|
|
|
@@ -14,6 +14,7 @@ import (
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/handler/admin"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/payment"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/repository"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/securityaudit"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/server"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
|
|
@@ -248,6 +249,13 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
contentModerationHashCache := repository.NewContentModerationHashCache(redisClient)
|
|
|
|
|
contentModerationService := service.NewContentModerationService(settingRepository, contentModerationRepository, contentModerationHashCache, groupRepository, userRepository, apiKeyAuthCacheInvalidator, emailService)
|
|
|
|
|
contentModerationHandler := admin.NewContentModerationHandler(contentModerationService)
|
|
|
|
|
configManager := securityaudit.NewConfigManager(db, settingRepository, redisClient, secretEncryptor)
|
|
|
|
|
postgreSQLRepository := securityaudit.NewPostgreSQLRepository(db)
|
|
|
|
|
redisPayloadStore := securityaudit.NewRedisPayloadStore(redisClient)
|
|
|
|
|
openAICompatibleScanner := securityaudit.NewOpenAICompatibleScanner()
|
|
|
|
|
atomicMetrics := securityaudit.NewAtomicMetrics()
|
|
|
|
|
promptService := securityaudit.NewPromptService(configManager, postgreSQLRepository, redisPayloadStore, openAICompatibleScanner, atomicMetrics)
|
|
|
|
|
promptAdminHandler := securityaudit.NewPromptAdminHandler(promptService)
|
|
|
|
|
paymentHandler := admin.NewPaymentHandler(paymentService, paymentConfigService)
|
|
|
|
|
affiliateHandler := admin.NewAffiliateHandler(affiliateService, adminService)
|
|
|
|
|
complianceHandler := admin.NewComplianceHandler(settingService)
|
|
|
|
@@ -255,12 +263,14 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
auditLogService := service.ProvideAuditLogService(auditLogRepository, settingService)
|
|
|
|
|
auditLogHandler := admin.NewAuditLogHandler(auditLogService, totpService)
|
|
|
|
|
upstreamBillingProbeService := service.ProvideUpstreamBillingProbeService(accountRepository, accountTestService, settingService, leaderLockCache, db)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, grokOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, tlsFingerprintProfileHandler, adminAPIKeyHandler, scheduledTestHandler, channelHandler, channelMonitorHandler, channelMonitorRequestTemplateHandler, contentModerationHandler, paymentHandler, affiliateHandler, complianceHandler, auditLogHandler, upstreamBillingProbeService)
|
|
|
|
|
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, grokOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, tlsFingerprintProfileHandler, adminAPIKeyHandler, scheduledTestHandler, channelHandler, channelMonitorHandler, channelMonitorRequestTemplateHandler, contentModerationHandler, promptAdminHandler, paymentHandler, affiliateHandler, complianceHandler, auditLogHandler, upstreamBillingProbeService)
|
|
|
|
|
usageRecordWorkerPool := service.NewUsageRecordWorkerPool(configConfig)
|
|
|
|
|
userMsgQueueCache := repository.NewUserMsgQueueCache(redisClient)
|
|
|
|
|
userMessageQueueService := service.ProvideUserMessageQueueService(userMsgQueueCache, rpmCache, configConfig)
|
|
|
|
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, contentModerationService, userMessageQueueService, configConfig, settingService)
|
|
|
|
|
openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, contentModerationService, opsService, configConfig)
|
|
|
|
|
legacyEngine := securityaudit.NewLegacyModerationAdapter(contentModerationService)
|
|
|
|
|
coordinator := securityaudit.NewCoordinator(legacyEngine, promptService)
|
|
|
|
|
gatewayHandler := handler.ProvideGatewayHandler(gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, userService, concurrencyService, billingCacheService, usageService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, contentModerationService, userMessageQueueService, configConfig, settingService, coordinator)
|
|
|
|
|
openAIGatewayHandler := handler.ProvideOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService, apiKeyService, usageRecordWorkerPool, errorPassthroughService, contentModerationService, opsService, configConfig, coordinator)
|
|
|
|
|
handlerSettingHandler := handler.ProvideSettingHandler(settingService, buildInfo, notificationEmailService)
|
|
|
|
|
totpHandler := handler.NewTotpHandler(totpService)
|
|
|
|
|
handlerPaymentHandler := handler.NewPaymentHandler(paymentService, paymentConfigService)
|
|
|
|
@@ -280,7 +290,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
batchImageDownloadLimiter := repository.NewBatchImageDownloadLimiter(redisClient, configConfig)
|
|
|
|
|
batchImageDownloadService := service.NewBatchImageDownloadService(batchImageRepository, accountRepository, batchImageDownloadLimiter, configConfig)
|
|
|
|
|
batchImageCleanupService := service.ProvideBatchImageCleanupService(batchImageRepository, accountRepository, configConfig)
|
|
|
|
|
batchImageHandler := handler.NewBatchImageHandler(batchImagePublicService, batchImageDownloadService, batchImageCleanupService)
|
|
|
|
|
batchImageHandler := handler.ProvideBatchImageHandler(batchImagePublicService, batchImageDownloadService, batchImageCleanupService, openAIGatewayHandler)
|
|
|
|
|
idempotencyCoordinator := service.ProvideIdempotencyCoordinator(idempotencyRepository, configConfig)
|
|
|
|
|
idempotencyCleanupService := service.ProvideIdempotencyCleanupService(idempotencyRepository, configConfig)
|
|
|
|
|
handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, announcementHandler, channelMonitorUserHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, handlerSettingHandler, totpHandler, handlerPaymentHandler, paymentWebhookHandler, availableChannelHandler, asyncImageHandler, batchImageHandler, idempotencyCoordinator, idempotencyCleanupService)
|
|
|
|
@@ -304,10 +314,11 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
paymentOrderExpiryService := service.ProvidePaymentOrderExpiryService(paymentService, leaderLockCache, db)
|
|
|
|
|
channelMonitorRunner := service.ProvideChannelMonitorRunner(channelMonitorService, settingService)
|
|
|
|
|
userPlatformQuotaUsageFlusher := service.ProvideUserPlatformQuotaUsageFlusher(configConfig, billingCache, serviceUserPlatformQuotaRepository, timingWheelService)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, schedulerSnapshotService, tokenRefreshService, accountExpiryService, proxyExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, batchImageCleanupService, batchImageWorkerRuntime, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, grokOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService, paymentOrderExpiryService, channelMonitorRunner, userPlatformQuotaUsageFlusher, upstreamBillingProbeService, auditLogService)
|
|
|
|
|
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, schedulerSnapshotService, tokenRefreshService, accountExpiryService, proxyExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, batchImageCleanupService, batchImageWorkerRuntime, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, grokOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService, paymentOrderExpiryService, channelMonitorRunner, userPlatformQuotaUsageFlusher, upstreamBillingProbeService, auditLogService, promptService)
|
|
|
|
|
application := &Application{
|
|
|
|
|
Server: httpServer,
|
|
|
|
|
Cleanup: v,
|
|
|
|
|
Server: httpServer,
|
|
|
|
|
PromptAudit: promptService,
|
|
|
|
|
Cleanup: v,
|
|
|
|
|
}
|
|
|
|
|
return application, nil
|
|
|
|
|
}
|
|
|
|
@@ -315,8 +326,9 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
|
|
|
// wire.go:
|
|
|
|
|
|
|
|
|
|
type Application struct {
|
|
|
|
|
Server *http.Server
|
|
|
|
|
Cleanup func()
|
|
|
|
|
Server *http.Server
|
|
|
|
|
PromptAudit *securityaudit.PromptService
|
|
|
|
|
Cleanup func()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func providePrivacyClientFactory() service.PrivacyClientFactory {
|
|
|
|
@@ -366,6 +378,7 @@ func provideCleanup(
|
|
|
|
|
quotaFlusher *service.UserPlatformQuotaUsageFlusher,
|
|
|
|
|
upstreamBillingProbe *service.UpstreamBillingProbeService,
|
|
|
|
|
auditLog *service.AuditLogService,
|
|
|
|
|
promptAudit *securityaudit.PromptService,
|
|
|
|
|
) func() {
|
|
|
|
|
return func() {
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
@@ -377,6 +390,12 @@ func provideCleanup(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parallelSteps := []cleanupStep{
|
|
|
|
|
{"PromptAuditService", func() error {
|
|
|
|
|
if promptAudit != nil {
|
|
|
|
|
return promptAudit.Shutdown(ctx)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}},
|
|
|
|
|
{"OpsScheduledReportService", func() error {
|
|
|
|
|
if opsScheduledReport != nil {
|
|
|
|
|
opsScheduledReport.Stop()
|
|
|
|
|