Skip to content

Commit fdcf7f4

Browse files
committed
feat: blacklist api
1 parent 1a3807a commit fdcf7f4

File tree

16 files changed

+965
-124
lines changed

16 files changed

+965
-124
lines changed

db/db.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"polaris/ent"
9+
"polaris/ent/blacklist"
910
"polaris/ent/downloadclients"
1011
"polaris/ent/episode"
1112
"polaris/ent/history"
@@ -742,3 +743,17 @@ func (c *client) GetTmdbApiKey() string {
742743
}
743744
return k
744745
}
746+
747+
748+
func (c *client) AddTorrent2Blacklist(hash, name string, mediaId int) error {
749+
count := c.ent.Blacklist.Query().Where(blacklist.TorrentHash(hash), blacklist.MediaID(mediaId)).CountX(context.TODO())
750+
if count > 0 { //already exist
751+
log.Infof("torrent %s already in blacklist", hash)
752+
return nil
753+
}
754+
return c.ent.Blacklist.Create().SetType(blacklist.TypeTorrent).SetTorrentHash(hash).SetTorrentName(name).SetMediaID(mediaId).Exec(context.Background())
755+
}
756+
757+
func (c *client) GetTorrentBlacklist() (ent.Blacklists, error) {
758+
return c.ent.Blacklist.Query().Where(blacklist.TypeEQ(blacklist.TypeTorrent)).All(context.Background())
759+
}

db/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type Database interface {
3939
AddNotificationClient(name, service string, setting string, enabled bool) error
4040
DeleteNotificationClient(id int) error
4141
GetNotificationClient(id int) (*NotificationClient, error)
42+
43+
AddTorrent2Blacklist(hash, name string, mediaId int) error
44+
GetTorrentBlacklist() (ent.Blacklists, error)
4245
}
4346

4447
type Settings interface {

engine/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func (c *Engine) Init() {
5151
go c.checkW500PosterOnStartup()
5252
}
5353

54+
55+
func (c *Engine) GetTask(id int) (*Task, bool) {
56+
return c.tasks.Load(id)
57+
}
5458
func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error{
5559
cl, err := buildin.NewDownloader(c.db.GetDownloadDir())
5660
if err != nil {

ent/blacklist.go

Lines changed: 49 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/blacklist/blacklist.go

Lines changed: 38 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)