Use strings
This commit is contained in:
@@ -2,6 +2,7 @@ package torrent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
oldjson "encoding/json"
|
oldjson "encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@@ -39,17 +40,19 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
temp.SelectedFilesJson = selectedFilesJson
|
temp.SelectedFilesJson = selectedFilesJson
|
||||||
|
|
||||||
downloadedIDsJson, err := json.Marshal(t.DownloadedIDs.List())
|
if t.DownloadedIDs.IsEmpty() {
|
||||||
if err != nil {
|
temp.DownloadedIDsJson = []byte("\"\"")
|
||||||
return nil, err
|
} else {
|
||||||
|
downloadedIDsStr := "\"" + strings.Join(t.DownloadedIDs.List(), ",") + "\""
|
||||||
|
temp.DownloadedIDsJson = []byte(downloadedIDsStr)
|
||||||
}
|
}
|
||||||
temp.DownloadedIDsJson = downloadedIDsJson
|
|
||||||
|
|
||||||
inProgressIDsJson, err := json.Marshal(t.InProgressIDs.List())
|
if t.InProgressIDs.IsEmpty() {
|
||||||
if err != nil {
|
temp.InProgressIDsJson = []byte("\"\"")
|
||||||
return nil, err
|
} else {
|
||||||
|
inProgressIDsStr := "\"" + strings.Join(t.InProgressIDs.List(), ",") + "\""
|
||||||
|
temp.InProgressIDsJson = []byte(inProgressIDsStr)
|
||||||
}
|
}
|
||||||
temp.InProgressIDsJson = inProgressIDsJson
|
|
||||||
|
|
||||||
return json.Marshal(temp)
|
return json.Marshal(temp)
|
||||||
}
|
}
|
||||||
@@ -75,21 +78,15 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(temp.DownloadedIDsJson) > 0 {
|
if len(temp.DownloadedIDsJson) > 2 {
|
||||||
var downloadedIDs []string
|
downloadedIDs := strings.Split(string(temp.DownloadedIDsJson), ",")
|
||||||
if err := json.Unmarshal(temp.DownloadedIDsJson, &downloadedIDs); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.DownloadedIDs = strset.New(downloadedIDs...)
|
t.DownloadedIDs = strset.New(downloadedIDs...)
|
||||||
} else {
|
} else {
|
||||||
t.DownloadedIDs = strset.New()
|
t.DownloadedIDs = strset.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(temp.InProgressIDsJson) > 0 {
|
if len(temp.InProgressIDsJson) > 2 {
|
||||||
var inProgressIDs []string
|
inProgressIDs := strings.Split(string(temp.InProgressIDsJson), ",")
|
||||||
if err := json.Unmarshal(temp.InProgressIDsJson, &inProgressIDs); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.InProgressIDs = strset.New(inProgressIDs...)
|
t.InProgressIDs = strset.New(inProgressIDs...)
|
||||||
} else {
|
} else {
|
||||||
t.InProgressIDs = strset.New()
|
t.InProgressIDs = strset.New()
|
||||||
|
|||||||
Reference in New Issue
Block a user