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
78
internal/domain/proxy.go
Normal file
78
internal/domain/proxy.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
)
|
||||
|
||||
type ProxyRepo interface {
|
||||
Store(ctx context.Context, p *Proxy) error
|
||||
Update(ctx context.Context, p *Proxy) error
|
||||
List(ctx context.Context) ([]Proxy, error)
|
||||
Delete(ctx context.Context, id int64) error
|
||||
FindByID(ctx context.Context, id int64) (*Proxy, error)
|
||||
ToggleEnabled(ctx context.Context, id int64, enabled bool) error
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Type ProxyType `json:"type"`
|
||||
Addr string `json:"addr"`
|
||||
User string `json:"user"`
|
||||
Pass string `json:"pass"`
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
|
||||
type ProxyType string
|
||||
|
||||
const (
|
||||
ProxyTypeSocks5 = "SOCKS5"
|
||||
)
|
||||
|
||||
func (p Proxy) ValidProxyType() bool {
|
||||
if p.Type == ProxyTypeSocks5 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (p Proxy) Validate() error {
|
||||
if !p.ValidProxyType() {
|
||||
return errors.New("invalid proxy type: %s", p.Type)
|
||||
}
|
||||
|
||||
if err := ValidateProxyAddr(p.Addr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.Name == "" {
|
||||
return errors.New("name is required")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateProxyAddr(addr string) error {
|
||||
if addr == "" {
|
||||
return errors.New("addr is required")
|
||||
}
|
||||
|
||||
proxyUrl, err := url.Parse(addr)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse proxy url: %s", addr)
|
||||
}
|
||||
|
||||
if proxyUrl.Scheme != "socks5" && proxyUrl.Scheme != "socks5h" {
|
||||
return errors.New("proxy url scheme must be socks5 or socks5h")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue