feat: support reload qbit tasks

This commit is contained in:
Simon Ding
2024-10-04 10:45:31 +08:00
parent 579b010d13
commit 7dfa4eafc4
4 changed files with 50 additions and 25 deletions

View File

@@ -10,6 +10,7 @@ type Torrent interface {
Exists() bool
SeedRatio() (float64, error)
GetHash() string
Reload() error
}
type Downloader interface {
@@ -17,5 +18,3 @@ type Downloader interface {
Download(link, dir string) (Torrent, error)
}
type Storage interface {
}

View File

@@ -174,3 +174,15 @@ func (t *Torrent) SeedRatio() (float64, error) {
}
return qb.Ratio, nil
}
func (t *Torrent) Reload() error {
c, err := NewClient(t.URL, t.User, t.Password)
if err != nil {
return err
}
t.c = c.c
if !t.Exists() {
return errors.Errorf("torrent not exists: %v", t.Hash)
}
return nil
}

View File

@@ -105,12 +105,15 @@ type Torrent struct {
Config
}
func (t *Torrent) reloadClient() error {
func (t *Torrent) Reload() error {
c, err := NewClient(t.Config)
if err != nil {
return err
}
t.c = c.c
if !t.Exists() {
return errors.Errorf("torrent not exists: %v", t.Hash)
}
return nil
}
@@ -211,18 +214,3 @@ func (t *Torrent) Save() string {
func (t *Torrent) GetHash() string {
return t.Hash
}
func ReloadTorrent(s string) (*Torrent, error) {
var torrent = Torrent{}
err := json.Unmarshal([]byte(s), &torrent)
if err != nil {
return nil, err
}
err = torrent.reloadClient()
if err != nil {
return nil, errors.Wrap(err, "reload client")
}
return &torrent, nil
}