/
routes_qbittorrents.go
156 lines (128 loc) · 3.3 KB
/
routes_qbittorrents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package app
import (
"encoding/base64"
"net/http"
"strings"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
)
func (a *Application) QbittorrentsAdd(c echo.Context, URL string) error {
b, err := base64.StdEncoding.DecodeString(URL)
if err != nil {
return err
}
u := string(b)
infohash, err := app.Qbt.Add(u, nil)
if err != nil {
return err
}
a.Log.Infof("added: %s", infohash)
return c.JSON(http.StatusOK, H{"error": false, "infohash": infohash})
}
func (a *Application) QbittorrentsRemove(c echo.Context, infohash string, del bool) error {
if infohash == "" {
return errors.New("infohash is required")
}
err := app.Qbt.Delete(infohash, del)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsIndex(c echo.Context) error {
// read the json string from cache
// read the json string from cache
res := ""
ok, err := a.Cache.Get("flame-qbittorrents", &res)
if err != nil {
return err
}
if !ok {
return err
}
return c.String(http.StatusOK, res)
}
func (a *Application) QbittorrentsLabel(c echo.Context, infohash, label string) error {
err := app.Qbt.SetLabel([]string{infohash}, label)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsPause(c echo.Context, infohash string) error {
if infohash == "" {
a.QbittorrentsPauseAll(c)
return nil
}
err := app.Qbt.Pause(infohash)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsPauseAll(c echo.Context) error {
err := app.Qbt.PauseAll()
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsResume(c echo.Context, infohash string) error {
if infohash == "" {
a.QbittorrentsResumeAll(c)
return nil
}
err := app.Qbt.Resume(infohash)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsResumeAll(c echo.Context) error {
err := app.Qbt.ResumeAll()
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
//func (a *Application) QbittorrentsStart(c echo.Context, infohash string) error {
// err := app.Qbt.Start(infohash)
// if err != nil {
// return err
// }
// return c.JSON(http.StatusOK, H{"error": false})
//}
//
//func (a *Application) QbittorrentsStop(c echo.Context, infohash string) error {
// err := App().Utorrent.Stop(infohash)
// if err != nil {
// return err
// }
// return c.JSON(http.StatusOK, H{"error": false})
//}
func (a *Application) QbittorrentsWant(c echo.Context, infohash, files string) error {
if files == "none" {
a.QbittorrentsWantNone(c, infohash)
return nil
}
ids := strings.Split(files, ",")
err := app.Qbt.Want(infohash, ids)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsWantNone(c echo.Context, infohash string) error {
err := app.Qbt.WantNone(infohash)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false})
}
func (a *Application) QbittorrentsWanted(c echo.Context, infohash string) error {
want, err := app.Qbt.WantedCount(infohash)
if err != nil {
return err
}
return c.JSON(http.StatusOK, H{"error": false, "wanted": want > 0, "count": want})
}