feat: blacklist api

This commit is contained in:
Simon Ding
2025-04-22 18:18:32 +08:00
parent 1a3807acc9
commit fdcf7f487c
16 changed files with 965 additions and 124 deletions

View File

@@ -7,7 +7,6 @@ import (
"polaris/ent/episode"
"polaris/ent/history"
"polaris/log"
"polaris/pkg/utils"
"strconv"
"github.com/gin-gonic/gin"
@@ -89,7 +88,7 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
}
if in.Add2Blacklist && his.Link != "" {
//should add to blacklist
if err := s.addTorrent2Blacklist(his.Link); err != nil {
if err := s.addTorrent2Blacklist(his); err != nil {
return nil, errors.Errorf("add to blacklist: %v", err)
} else {
log.Infof("success add magnet link to blacklist: %v", his.Link)
@@ -118,25 +117,23 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
return nil, nil
}
func (s *Server) addTorrent2Blacklist(link string) error {
if link == "" {
return nil
func (s *Server) addTorrent2Blacklist(h *ent.History) error {
var name string
task, ok := s.core.GetTask(h.ID)
if ok {
name, _ = task.Name()
}
if _, err := utils.MagnetHash(link); err != nil {
return err
} else {
// item := ent.Blacklist{
// Type: blacklist.TypeTorrent,
// Value: schema.BlacklistValue{
// TorrentHash: hash,
// },
// }
// err := s.db.AddBlacklistItem(&item)
// if err != nil {
// return errors.Wrap(err, "add to db")
// }
return s.db.AddTorrent2Blacklist(h.Hash, name, h.MediaID)
}
func (s *Server) GetAllBlacklistItems(c *gin.Context) (interface{}, error) {
list, err := s.db.GetTorrentBlacklist()
if err!= nil {
return nil, errors.Wrap(err, "db")
}
return nil
return list, nil
}
func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {

View File

@@ -86,6 +86,7 @@ func (s *Server) Serve() error {
activity.GET("/", HttpHandler(s.GetAllActivities))
activity.POST("/delete", HttpHandler(s.RemoveActivity))
activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory))
activity.GET("/blacklist", HttpHandler(s.GetAllBlacklistItems))
//activity.GET("/torrents", HttpHandler(s.GetAllTorrents))
}