mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49: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
|
@ -356,8 +356,6 @@ func (r *Release) ParseString(title string) {
|
|||
r.ParseReleaseTagsString(r.ReleaseTags)
|
||||
}
|
||||
|
||||
var ErrUnrecoverableError = errors.New("unrecoverable error")
|
||||
|
||||
func (r *Release) ParseReleaseTagsString(tags string) {
|
||||
cleanTags := CleanReleaseTags(tags)
|
||||
t := ParseReleaseTagString(cleanTags)
|
||||
|
@ -432,10 +430,6 @@ func (r *Release) DownloadTorrentFileCtx(ctx context.Context) error {
|
|||
return r.downloadTorrentFile(ctx)
|
||||
}
|
||||
|
||||
func (r *Release) DownloadTorrentFile() error {
|
||||
return r.downloadTorrentFile(context.Background())
|
||||
}
|
||||
|
||||
func (r *Release) downloadTorrentFile(ctx context.Context) error {
|
||||
if r.HasMagnetUri() {
|
||||
return errors.New("downloading magnet links is not supported: %s", r.MagnetURI)
|
||||
|
@ -592,7 +586,7 @@ func (r *Release) downloadTorrentFile(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (r *Release) CleanupTemporaryFiles() {
|
||||
if len(r.TorrentTmpFile) == 0 {
|
||||
if r.TorrentTmpFile == "" {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -600,54 +594,15 @@ func (r *Release) CleanupTemporaryFiles() {
|
|||
r.TorrentTmpFile = ""
|
||||
}
|
||||
|
||||
// HasMagnetUri check uf MagnetURI is set or empty
|
||||
// HasMagnetUri check uf MagnetURI is set and valid or empty
|
||||
func (r *Release) HasMagnetUri() bool {
|
||||
return r.MagnetURI != ""
|
||||
if r.MagnetURI != "" && strings.HasPrefix(r.MagnetURI, MagnetURIPrefix) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Release) ResolveMagnetUri(ctx context.Context) error {
|
||||
if r.MagnetURI == "" {
|
||||
return nil
|
||||
} else if strings.HasPrefix(r.MagnetURI, "magnet:?") {
|
||||
return nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, r.MagnetURI, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not build request to resolve magnet uri")
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("User-Agent", "autobrr")
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 45,
|
||||
Transport: sharedhttp.MagnetTransport,
|
||||
}
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not make request to resolve magnet uri")
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return errors.New("unexpected status code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read response body")
|
||||
}
|
||||
|
||||
magnet := string(body)
|
||||
if magnet != "" {
|
||||
r.MagnetURI = magnet
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
const MagnetURIPrefix = "magnet:?"
|
||||
|
||||
func (r *Release) addRejection(reason string) {
|
||||
r.Rejections = append(r.Rejections, reason)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue