diff --git a/db/db.go b/db/db.go index 1119f73..0b9ee4c 100644 --- a/db/db.go +++ b/db/db.go @@ -268,9 +268,9 @@ func (c *client) SaveIndexer(in *ent.Indexers) error { count := c.ent.Indexers.Query().Where(indexers.Name(in.Name)).CountX(context.TODO()) - if count > 0 || in.ID != 0 { + if count > 0 { //update setting - return c.ent.Indexers.Update().Where(indexers.ID(in.ID)).SetName(in.Name).SetImplementation(in.Implementation). + return c.ent.Indexers.Update().Where(indexers.Name(in.Name)).SetName(in.Name).SetImplementation(in.Implementation). SetPriority(in.Priority).SetSeedRatio(in.SeedRatio).SetDisabled(in.Disabled). SetTvSearch(in.TvSearch).SetMovieSearch(in.MovieSearch).SetSettings("").SetSynced(in.Synced). SetAPIKey(in.APIKey).SetURL(in.URL). diff --git a/engine/client.go b/engine/client.go index 5bf7bbd..9883075 100644 --- a/engine/client.go +++ b/engine/client.go @@ -57,7 +57,7 @@ func (c *Engine) GetTask(id int) (*Task, bool) { } func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error { - cl, err := buildin.NewDownloader(c.db.GetDownloadDir()) + cl, err := c.buildInDownloader() if err != nil { log.Warnf("buildin downloader error: %v", err) } diff --git a/pkg/buildin/torrent.go b/pkg/buildin/torrent.go index 02b5123..e74a22a 100644 --- a/pkg/buildin/torrent.go +++ b/pkg/buildin/torrent.go @@ -6,7 +6,6 @@ import ( "net/http" "os" "path/filepath" - "polaris/log" "polaris/pkg" "strings" @@ -92,25 +91,25 @@ func (d *Downloader) Download(link, hash, dir string) (pkg.Torrent, error) { }, nil } -func NewTorrentFromHash(hash string, downloadDir string) (*Torrent, error) { - cl, err := NewDownloader(downloadDir) - if err != nil { - return nil, errors.Wrap(err, "create downloader") - } - ttt := cl.cl.Torrents() - log.Infof("all torrents: %+v", ttt) - t, _ := cl.cl.AddTorrentInfoHash(metainfo.NewHashFromHex(hash)) - // if new { - // return nil, fmt.Errorf("torrent not found") - // } - <-t.GotInfo() - return &Torrent{ - t: t, - cl: cl.cl, - hash: hash, - dir: downloadDir, - }, nil -} +// func NewTorrentFromHash(hash string, downloadDir string) (*Torrent, error) { +// cl, err := NewDownloader(downloadDir) +// if err != nil { +// return nil, errors.Wrap(err, "create downloader") +// } +// ttt := cl.cl.Torrents() +// log.Infof("all torrents: %+v", ttt) +// t, _ := cl.cl.AddTorrentInfoHash(metainfo.NewHashFromHex(hash)) +// // if new { +// // return nil, fmt.Errorf("torrent not found") +// // } +// <-t.GotInfo() +// return &Torrent{ +// t: t, +// cl: cl.cl, +// hash: hash, +// dir: downloadDir, +// }, nil +// } type Torrent struct { t *torrent.Torrent