Fix the float64 conversion

This commit is contained in:
Ben Sarmiento
2023-10-26 21:50:13 +02:00
parent 0fd2fa691e
commit c713a696c6
2 changed files with 27 additions and 5 deletions

View File

@@ -1,5 +1,10 @@
package realdebrid
import (
"encoding/json"
"math"
)
type FileJSON struct {
FileSize int `json:"filesize"`
Link string `json:"link"`
@@ -17,13 +22,30 @@ type Torrent struct {
ID string `json:"id"`
Name string `json:"filename"`
Hash string `json:"hash"`
Progress int `json:"progress"`
Progress int `json:"-"`
Added string `json:"added"`
Bytes int64 `json:"bytes"`
Links []string `json:"links"`
Files []File `json:"files,omitempty"`
}
func (t *Torrent) UnmarshalJSON(data []byte) error {
type Alias Torrent
aux := &struct {
Progress float64 `json:"progress"`
*Alias
}{
Alias: (*Alias)(t),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
t.Progress = int(math.Round(aux.Progress))
return nil
}
type File struct {
ID int `json:"id"`
Path string `json:"path"`