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

0
doc/quick_start.md Normal file
View File

View File

@@ -41,9 +41,9 @@ func SetLogLevel(l string) {
case "info": case "info":
atom.SetLevel(zap.InfoLevel) atom.SetLevel(zap.InfoLevel)
Info("set log level to info") Info("set log level to info")
case "warn", "warnning": case "warn", "warning":
atom.SetLevel(zap.WarnLevel) atom.SetLevel(zap.WarnLevel)
Warn("set log level to warnning") Warn("set log level to warning")
case "error": case "error":
atom.SetLevel(zap.ErrorLevel) atom.SetLevel(zap.ErrorLevel)
Error("set log level to error") Error("set log level to error")

View File

@@ -45,6 +45,22 @@ type Client struct {
cfg Config cfg Config
} }
func (c *Client) GetAll() ([]*Torrent, error) {
all, err := c.c.TorrentGetAll(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "get all")
}
var torrents []*Torrent
for _, t := range all {
torrents = append(torrents, &Torrent{
ID: *t.ID,
c: c.c,
Config: c.cfg,
})
}
return torrents, nil
}
func (c *Client) Download(link, dir string) (*Torrent, error) { func (c *Client) Download(link, dir string) (*Torrent, error) {
if strings.HasPrefix(link, "http") { if strings.HasPrefix(link, "http") {
client := &http.Client{ client := &http.Client{

View File

@@ -93,3 +93,33 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
} }
return his, nil 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 if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
continue continue
} }
if utils.ContainsIgnoreCase(r.Name, "soundtrack") {
//ignore soundtracks
continue
}
filtered = append(filtered, r) filtered = append(filtered, r)

View File

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

View File

@@ -30,9 +30,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
var tmdbSetting = settings.when( var tmdbSetting = settings.when(
data: (v) { data: (v) {
return Container( return FormBuilder(
padding: const EdgeInsets.fromLTRB(40, 10, 40, 0),
child: FormBuilder(
key: _formKey, //设置globalKey用于后面获取FormState key: _formKey, //设置globalKey用于后面获取FormState
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
initialValue: { initialValue: {
@@ -107,7 +105,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
) )
], ],
), ),
)); );
}, },
error: (err, trace) => Text("$err"), error: (err, trace) => Text("$err"),
loading: () => const MyProgressIndicator()); loading: () => const MyProgressIndicator());