90 lines
2.5 KiB
Go
90 lines
2.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tradarr/backend/internal/ai"
|
|
"github.com/tradarr/backend/internal/auth"
|
|
"github.com/tradarr/backend/internal/companycatalog"
|
|
"github.com/tradarr/backend/internal/config"
|
|
"github.com/tradarr/backend/internal/crypto"
|
|
"github.com/tradarr/backend/internal/generation"
|
|
"github.com/tradarr/backend/internal/indices"
|
|
"github.com/tradarr/backend/internal/models"
|
|
"github.com/tradarr/backend/internal/scheduler"
|
|
"github.com/tradarr/backend/internal/scraper"
|
|
)
|
|
|
|
type Handler struct {
|
|
modelTester interface {
|
|
Test(context.Context, string) error
|
|
}
|
|
connectionTester interface {
|
|
Test(context.Context, string) error
|
|
}
|
|
companyCatalog CompanyCatalog
|
|
indexSearcher indices.IndexSearcher
|
|
generationJobs interface {
|
|
Start(context.Context, string) (models.GenerationJob, error)
|
|
}
|
|
repo *models.Repository
|
|
cfg *config.Config
|
|
enc *crypto.Encryptor
|
|
registry *scraper.Registry
|
|
pipeline *ai.Pipeline
|
|
scheduler *scheduler.Scheduler
|
|
reportManager *ai.ReportManager
|
|
}
|
|
|
|
func New(
|
|
repo *models.Repository,
|
|
cfg *config.Config,
|
|
enc *crypto.Encryptor,
|
|
registry *scraper.Registry,
|
|
pipeline *ai.Pipeline,
|
|
sched *scheduler.Scheduler,
|
|
) *Handler {
|
|
var catalog CompanyCatalog
|
|
if embedded, err := companycatalog.Default(); err == nil {
|
|
catalog = embedded
|
|
}
|
|
var decryptor ai.ConnectionDecryptor
|
|
if enc != nil {
|
|
decryptor = enc
|
|
}
|
|
return &Handler{
|
|
companyCatalog: catalog,
|
|
modelTester: ai.NewModelTester(repo, decryptor, ai.NewProvider),
|
|
connectionTester: ai.NewConnectionTester(repo, enc, func(name, key, endpoint string) (ai.Provider, error) {
|
|
return ai.NewProvider(name, key, "", endpoint)
|
|
}),
|
|
repo: repo,
|
|
cfg: cfg,
|
|
enc: enc,
|
|
registry: registry,
|
|
pipeline: pipeline,
|
|
scheduler: sched,
|
|
reportManager: ai.NewReportManager(),
|
|
}
|
|
}
|
|
|
|
func (h *Handler) SetGenerationUseCase(uc generation.UseCase) {
|
|
if h.repo != nil && uc != nil {
|
|
h.generationJobs = generation.NewJobs(h.repo, uc)
|
|
}
|
|
}
|
|
func (h *Handler) SetGenerationJobs(jobs interface {
|
|
Start(context.Context, string) (models.GenerationJob, error)
|
|
}) {
|
|
h.generationJobs = jobs
|
|
}
|
|
|
|
func (h *Handler) AdminOnly() gin.HandlerFunc { return auth.AdminOnly(h.repo) }
|
|
|
|
// SetModelTester supplies an isolated test port; production uses NewModelTester.
|
|
func (h *Handler) SetModelTester(tester interface {
|
|
Test(context.Context, string) error
|
|
}) {
|
|
h.modelTester = tester
|
|
}
|