Add support for using freeleech tokens if available

This commit is contained in:
Daniel Mason 2025-07-11 10:12:43 +12:00
parent 74f777340e
commit 1242c19883
Signed by: idanoo
GPG key ID: 387387CDBC02F132
21 changed files with 88 additions and 34 deletions

View file

@ -210,6 +210,7 @@ func (r *FilterRepo) FindByID(ctx context.Context, filterID int) (*domain.Filter
"f.scene",
"f.freeleech",
"f.freeleech_percent",
"f.freeleech_token",
"f.smart_episode",
"f.shows",
"f.seasons",
@ -438,6 +439,7 @@ func (r *FilterRepo) findByIndexerIdentifier(ctx context.Context, indexer string
"f.scene",
"f.freeleech",
"f.freeleech_percent",
"f.freeleech_token",
"f.smart_episode",
"f.shows",
"f.seasons",
@ -832,6 +834,7 @@ func (r *FilterRepo) Store(ctx context.Context, filter *domain.Filter) error {
"scene",
"freeleech",
"freeleech_percent",
"freeleech_token",
"smart_episode",
"shows",
"seasons",
@ -988,6 +991,7 @@ func (r *FilterRepo) Update(ctx context.Context, filter *domain.Filter) error {
Set("scene", filter.Scene).
Set("freeleech", filter.Freeleech).
Set("freeleech_percent", filter.FreeleechPercent).
Set("freeleech_token", filter.FreeleechToken).
Set("smart_episode", filter.SmartEpisode).
Set("shows", filter.Shows).
Set("seasons", filter.Seasons).
@ -1128,6 +1132,9 @@ func (r *FilterRepo) UpdatePartial(ctx context.Context, filter domain.FilterUpda
if filter.FreeleechPercent != nil {
q = q.Set("freeleech_percent", filter.FreeleechPercent)
}
if filter.FreeleechToken != nil {
q = q.Set("freeleech_token", filter.FreeleechToken)
}
if filter.SmartEpisode != nil {
q = q.Set("smart_episode", filter.SmartEpisode)
}

View file

@ -2018,5 +2018,9 @@ CREATE INDEX release_hybrid_index
FROM irc_network
WHERE server = 'irc.rocket-hd.cc'
);
`,
`ALTER TABLE filters
ADD COLUMN freeleach_tokens BOOLEAN
AFTER freeleech_percent;
`,
}

View file

@ -114,6 +114,7 @@ type Filter struct {
Bonus []string `json:"bonus,omitempty"`
Freeleech bool `json:"freeleech,omitempty"`
FreeleechPercent string `json:"freeleech_percent,omitempty"`
FreeleechToken bool `json:"freeleech_token,omitempty"`
SmartEpisode bool `json:"smart_episode"`
Shows string `json:"shows,omitempty"`
Seasons string `json:"seasons,omitempty"`
@ -248,6 +249,7 @@ type FilterUpdate struct {
Bonus *[]string `json:"bonus,omitempty"`
Freeleech *bool `json:"freeleech,omitempty"`
FreeleechPercent *string `json:"freeleech_percent,omitempty"`
FreeleechToken *bool `json:"freeleech_token,omitempty"`
SmartEpisode *bool `json:"smart_episode,omitempty"`
Shows *string `json:"shows,omitempty"`
Seasons *string `json:"seasons,omitempty"`

View file

@ -558,7 +558,7 @@ func (s *service) AdditionalSizeCheck(ctx context.Context, f *domain.Filter, rel
if (release.Size == 0 && release.AdditionalSizeCheckRequired) || (release.Uploader == "" && release.AdditionalUploaderCheckRequired) || (release.RecordLabel == "" && release.AdditionalRecordLabelCheckRequired) {
l.Trace().Msgf("(%s) preparing to check size via api", f.Name)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
if err != nil || torrentInfo == nil {
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
return false, err
@ -643,7 +643,7 @@ func (s *service) AdditionalUploaderCheck(ctx context.Context, f *domain.Filter,
case "redacted", "ops", "mock":
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
if err != nil || torrentInfo == nil {
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
return false, err
@ -722,7 +722,7 @@ func (s *service) AdditionalRecordLabelCheck(ctx context.Context, f *domain.Filt
case "redacted", "ops", "mock":
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
if err != nil || torrentInfo == nil {
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
return false, err

View file

@ -20,13 +20,13 @@ import (
type APIService interface {
TestConnection(ctx context.Context, req domain.IndexerTestApiRequest) (bool, error)
GetTorrentByID(ctx context.Context, indexer string, torrentID string) (*domain.TorrentBasic, error)
GetTorrentByID(ctx context.Context, indexer string, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
AddClient(indexer string, settings map[string]string) error
RemoveClient(indexer string) error
}
type apiClient interface {
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
TestAPI(ctx context.Context) (bool, error)
}
@ -42,7 +42,7 @@ func NewAPIService(log logger.Logger) APIService {
}
}
func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrentID string) (*domain.TorrentBasic, error) {
func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
client, err := s.getApiClient(indexer)
if err != nil {
s.log.Error().Stack().Err(err).Msgf("could not get api client for: %s", indexer)
@ -51,7 +51,7 @@ func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrent
s.log.Trace().Str("method", "GetTorrentByID").Msgf("%s fetching torrent from api...", indexer)
torrent, err := client.GetTorrentByID(ctx, torrentID)
torrent, err := client.GetTorrentByID(ctx, torrentID, freeleechToken)
if err != nil {
s.log.Error().Stack().Err(err).Msgf("could not get torrent: %s from: %s", torrentID, indexer)
return nil, err

View file

@ -11,7 +11,7 @@ import (
)
type IndexerApiClient interface {
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
TestAPI(ctx context.Context) (bool, error)
}