feat(indexers): update release baseurl on update (#1532)

This commit is contained in:
ze0s 2024-05-03 11:32:56 +02:00 committed by GitHub
parent 19e129e55f
commit 3202c6043d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 94 additions and 9 deletions

View file

@ -43,11 +43,12 @@ type Service interface {
}
type service struct {
log zerolog.Logger
config *domain.Config
repo domain.IndexerRepo
ApiService APIService
scheduler scheduler.Service
log zerolog.Logger
config *domain.Config
repo domain.IndexerRepo
releaseRepo domain.ReleaseRepo
ApiService APIService
scheduler scheduler.Service
// contains all raw indexer definitions
definitions map[string]domain.IndexerDefinition
@ -63,11 +64,12 @@ type service struct {
rssIndexers map[string]*domain.IndexerDefinition
}
func NewService(log logger.Logger, config *domain.Config, repo domain.IndexerRepo, apiService APIService, scheduler scheduler.Service) Service {
func NewService(log logger.Logger, config *domain.Config, repo domain.IndexerRepo, releaseRepo domain.ReleaseRepo, apiService APIService, scheduler scheduler.Service) Service {
return &service{
log: log.With().Str("module", "indexer").Logger(),
config: config,
repo: repo,
releaseRepo: releaseRepo,
ApiService: apiService,
scheduler: scheduler,
lookupIRCServerDefinition: make(map[string]map[string]*domain.IndexerDefinition),
@ -119,6 +121,28 @@ func (s *service) Update(ctx context.Context, indexer domain.Indexer) (*domain.I
indexer.Settings[key] = sanitize.String(val)
}
currentIndexer, err := s.repo.FindByID(ctx, int(indexer.ID))
if err != nil {
return nil, errors.Wrap(err, "could not find indexer by id: %v", indexer.ID)
}
// only IRC indexers have baseURL set
if indexer.Implementation == string(domain.IndexerImplementationIRC) {
if indexer.BaseURL == "" {
return nil, errors.New("indexer baseURL must not be empty")
}
// check if baseURL has been updated and update releases if it was
if currentIndexer.BaseURL != indexer.BaseURL {
// update urls of releases
err = s.releaseRepo.UpdateBaseURL(ctx, indexer.Identifier, currentIndexer.BaseURL, indexer.BaseURL)
if err != nil {
return nil, errors.Wrap(err, "could not update release urls with new baseURL: %s", indexer.BaseURL)
}
}
}
i, err := s.repo.Update(ctx, indexer)
if err != nil {
s.log.Error().Err(err).Msgf("could not update indexer: %+v", indexer)
@ -132,7 +156,7 @@ func (s *service) Update(ctx context.Context, indexer domain.Indexer) (*domain.I
}
if isImplFeed(indexer.Implementation) {
if !indexer.Enabled {
if currentIndexer.Enabled && !indexer.Enabled {
s.stopFeed(indexer.Identifier)
}
}