Fix deletes again

This commit is contained in:
Ben Sarmiento
2023-12-06 03:16:34 +01:00
parent 6ef54a9891
commit dd2a9d23f1
2 changed files with 16 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
Api: api,
accessKeySet: set.NewStringSet(),
latestState: &initialSate,
requiredVersion: "03.12.2023",
requiredVersion: "06.12.2023",
workerPool: p,
log: log,
}
@@ -111,7 +111,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
}
func (t *TorrentManager) RefreshTorrents() {
instances, _, err := t.Api.GetTorrents(0)
instances, _, err := t.Api.GetTorrents(10)
if err != nil {
t.log.Warnf("Cannot get torrents: %v\n", err)
return
@@ -244,11 +244,11 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
torrent.InProgressIDs.Add(info.ID)
}
infoCache.Set(rdTorrent.ID, &torrent)
err = t.writeTorrentToFile(rdTorrent.ID, &torrent)
if err != nil {
t.log.Warnf("Cannot write torrent to file: %v", err)
}
infoCache.Set(rdTorrent.ID, &torrent)
return &torrent
}

View File

@@ -1,7 +1,7 @@
package torrent
import (
oldjson "encoding/json"
stdjson "encoding/json"
"strings"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
@@ -26,9 +26,9 @@ type Torrent struct {
func (t *Torrent) MarshalJSON() ([]byte, error) {
type Alias Torrent
temp := &struct {
SelectedFilesJson oldjson.RawMessage `json:"SelectedFiles"`
DownloadedIDsJson oldjson.RawMessage `json:"DownloadedIDs"`
InProgressIDsJson oldjson.RawMessage `json:"InProgressIDs"`
SelectedFilesJson stdjson.RawMessage `json:"SelectedFiles"`
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
*Alias
}{
Alias: (*Alias)(t),
@@ -41,16 +41,16 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
temp.SelectedFilesJson = selectedFilesJson
if t.DownloadedIDs.IsEmpty() {
temp.DownloadedIDsJson = []byte("\"\"")
temp.DownloadedIDsJson = []byte(`""`)
} else {
downloadedIDsStr := "\"" + strings.Join(t.DownloadedIDs.List(), ",") + "\""
downloadedIDsStr := `"` + strings.Join(t.DownloadedIDs.List(), ",") + `"`
temp.DownloadedIDsJson = []byte(downloadedIDsStr)
}
if t.InProgressIDs.IsEmpty() {
temp.InProgressIDsJson = []byte("\"\"")
temp.InProgressIDsJson = []byte(`""`)
} else {
inProgressIDsStr := "\"" + strings.Join(t.InProgressIDs.List(), ",") + "\""
inProgressIDsStr := `"` + strings.Join(t.InProgressIDs.List(), ",") + `"`
temp.InProgressIDsJson = []byte(inProgressIDsStr)
}
@@ -60,9 +60,9 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
func (t *Torrent) UnmarshalJSON(data []byte) error {
type Alias Torrent
temp := &struct {
SelectedFilesJson oldjson.RawMessage `json:"SelectedFiles"`
DownloadedIDsJson oldjson.RawMessage `json:"DownloadedIDs"`
InProgressIDsJson oldjson.RawMessage `json:"InProgressIDs"`
SelectedFilesJson stdjson.RawMessage `json:"SelectedFiles"`
DownloadedIDsJson stdjson.RawMessage `json:"DownloadedIDs"`
InProgressIDsJson stdjson.RawMessage `json:"InProgressIDs"`
*Alias
}{
Alias: (*Alias)(t),
@@ -79,14 +79,14 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
}
if len(temp.DownloadedIDsJson) > 2 {
downloadedIDs := strings.Split(string(temp.DownloadedIDsJson), ",")
downloadedIDs := strings.Split(strings.ReplaceAll(string(temp.DownloadedIDsJson), `"`, ""), ",")
t.DownloadedIDs = strset.New(downloadedIDs...)
} else {
t.DownloadedIDs = strset.New()
}
if len(temp.InProgressIDsJson) > 2 {
inProgressIDs := strings.Split(string(temp.InProgressIDsJson), ",")
inProgressIDs := strings.Split(strings.ReplaceAll(string(temp.InProgressIDsJson), `"`, ""), ",")
t.InProgressIDs = strset.New(inProgressIDs...)
} else {
t.InProgressIDs = strset.New()