Refactor torrent manager
This commit is contained in:
@@ -135,7 +135,7 @@ func (rd *RealDebrid) GetTorrents(customLimit int) ([]Torrent, int, error) {
|
||||
return allTorrents, totalCount, nil
|
||||
}
|
||||
|
||||
func (rd *RealDebrid) GetTorrentInfo(id string) (*Torrent, error) {
|
||||
func (rd *RealDebrid) GetTorrentInfo(id string) (*TorrentInfo, error) {
|
||||
url := "https://api.real-debrid.com/rest/1.0/torrents/info/" + id
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
@@ -162,7 +162,7 @@ func (rd *RealDebrid) GetTorrentInfo(id string) (*Torrent, error) {
|
||||
return nil, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||
}
|
||||
|
||||
var response Torrent
|
||||
var response TorrentInfo
|
||||
err = json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
rd.log.Errorf("Error when : %v", err)
|
||||
@@ -314,8 +314,7 @@ func (rd *RealDebrid) UnrestrictLink(link string) (*UnrestrictResponse, error) {
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
resp, err := rd.client.Do(req)
|
||||
if err != nil {
|
||||
rd.log.Errorf("Error when executing the unrestrict link request: %v", err)
|
||||
return nil, err
|
||||
|
||||
@@ -20,16 +20,28 @@ type UnrestrictResponse struct {
|
||||
}
|
||||
|
||||
type Torrent struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"filename"`
|
||||
Hash string `json:"hash"`
|
||||
Progress int `json:"-"`
|
||||
Added string `json:"added"`
|
||||
Bytes int64 `json:"bytes"`
|
||||
Links []string `json:"links"`
|
||||
}
|
||||
|
||||
type TorrentInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"filename"`
|
||||
OriginalName string `json:"original_filename"`
|
||||
Hash string `json:"hash"`
|
||||
Progress int `json:"-"`
|
||||
Added string `json:"added"`
|
||||
Bytes int64 `json:"bytes"`
|
||||
OriginalBytes int64 `json:"original_bytes"`
|
||||
Links []string `json:"links"`
|
||||
Files []File `json:"files,omitempty"`
|
||||
OriginalName string `json:"original_filename"` // from info
|
||||
OriginalBytes int64 `json:"original_bytes"` // from info
|
||||
Files []File `json:"files"` // from info
|
||||
ForRepair bool `json:"-"`
|
||||
Version string `json:"-"`
|
||||
}
|
||||
|
||||
func (t *Torrent) UnmarshalJSON(data []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user