feat: add get all torrents api

This commit is contained in:
Simon Ding
2024-07-27 09:26:51 +08:00
parent 51fc5c3c74
commit b2a092c64e
7 changed files with 124 additions and 83 deletions

View File

@@ -93,3 +93,33 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
}
return his, nil
}
type TorrentInfo struct {
Name string `json:"name"`
ID int64 `json:"id"`
SeedRatio float32 `json:"seed_ratio"`
Progress int `json:"progress"`
}
func (s *Server) GetAllTorrents(c *gin.Context) (interface{}, error) {
trc, err := s.getDownloadClient()
if err != nil {
return nil, errors.Wrap(err, "connect transmission")
}
all, err := trc.GetAll()
if err != nil {
return nil, errors.Wrap(err, "get all")
}
var infos []TorrentInfo
for _, t := range all {
if !t.Exists() {
continue
}
infos = append(infos, TorrentInfo{
Name: t.Name(),
ID: t.ID,
Progress: t.Progress(),
})
}
return infos, nil
}

View File

@@ -110,10 +110,6 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
continue
}
if utils.ContainsIgnoreCase(r.Name, "soundtrack") {
//ignore soundtracks
continue
}
filtered = append(filtered, r)

View File

@@ -73,6 +73,7 @@ func (s *Server) Serve() error {
activity.GET("/", HttpHandler(s.GetAllActivities))
activity.DELETE("/:id", HttpHandler(s.RemoveActivity))
activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory))
activity.GET("/torrents", HttpHandler(s.GetAllTorrents))
}
tv := api.Group("/media")