mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat: add support for proxies to use with IRC and Indexers (#1421)
* feat: add support for proxies * fix(http): release handler * fix(migrations): define proxy early * fix(migrations): pg proxy * fix(proxy): list update delete * fix(proxy): remove log and imports * feat(irc): use proxy * feat(irc): tests * fix(web): update imports for ProxyForms.tsx * fix(database): migration * feat(proxy): test * feat(proxy): validate proxy type * feat(proxy): validate and test * feat(proxy): improve validate and test * feat(proxy): fix db schema * feat(proxy): add db tests * feat(proxy): handle http errors * fix(http): imports * feat(proxy): use proxy for indexer downloads * feat(proxy): indexerforms select proxy * feat(proxy): handle torrent download * feat(proxy): skip if disabled * feat(proxy): imports * feat(proxy): implement in Feeds * feat(proxy): update helper text indexer proxy * feat(proxy): add internal cache
This commit is contained in:
parent
472d327308
commit
bc0f4cc055
59 changed files with 2533 additions and 371 deletions
|
@ -5,6 +5,7 @@ package feed
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/autobrr/autobrr/internal/proxy"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -224,6 +225,18 @@ func mapFreeleechToBonus(percentage int) string {
|
|||
}
|
||||
|
||||
func (j *TorznabJob) getFeed(ctx context.Context) ([]torznab.FeedItem, error) {
|
||||
// add proxy if enabled and exists
|
||||
if j.Feed.UseProxy && j.Feed.Proxy != nil {
|
||||
proxyClient, err := proxy.GetProxiedHTTPClient(j.Feed.Proxy)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get proxy client")
|
||||
}
|
||||
|
||||
j.Client.WithHTTPClient(proxyClient)
|
||||
|
||||
j.Log.Debug().Msgf("using proxy %s for feed %s", j.Feed.Proxy.Name, j.Feed.Name)
|
||||
}
|
||||
|
||||
// get feed
|
||||
feed, err := j.Client.FetchFeed(ctx)
|
||||
if err != nil {
|
||||
|
@ -251,35 +264,33 @@ func (j *TorznabJob) getFeed(ctx context.Context) ([]torznab.FeedItem, error) {
|
|||
// set ttl to 1 month
|
||||
ttl := time.Now().AddDate(0, 1, 0)
|
||||
|
||||
for _, i := range feed.Channel.Items {
|
||||
i := i
|
||||
|
||||
if i.GUID == "" {
|
||||
for _, item := range feed.Channel.Items {
|
||||
if item.GUID == "" {
|
||||
j.Log.Error().Msgf("missing GUID from feed: %s", j.Feed.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
exists, err := j.CacheRepo.Exists(j.Feed.ID, i.GUID)
|
||||
exists, err := j.CacheRepo.Exists(j.Feed.ID, item.GUID)
|
||||
if err != nil {
|
||||
j.Log.Error().Err(err).Msg("could not check if item exists")
|
||||
continue
|
||||
}
|
||||
if exists {
|
||||
j.Log.Trace().Msgf("cache item exists, skipping release: %s", i.Title)
|
||||
j.Log.Trace().Msgf("cache item exists, skipping release: %s", item.Title)
|
||||
continue
|
||||
}
|
||||
|
||||
j.Log.Debug().Msgf("found new release: %s", i.Title)
|
||||
j.Log.Debug().Msgf("found new release: %s", item.Title)
|
||||
|
||||
toCache = append(toCache, domain.FeedCacheItem{
|
||||
FeedId: strconv.Itoa(j.Feed.ID),
|
||||
Key: i.GUID,
|
||||
Value: []byte(i.Title),
|
||||
Key: item.GUID,
|
||||
Value: []byte(item.Title),
|
||||
TTL: ttl,
|
||||
})
|
||||
|
||||
// only append if we successfully added to cache
|
||||
items = append(items, *i)
|
||||
items = append(items, *item)
|
||||
}
|
||||
|
||||
if len(toCache) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue