Proactive repair

This commit is contained in:
Ben Sarmiento
2024-01-07 19:00:53 +01:00
parent cfb0f12fff
commit 80a1af378a
3 changed files with 60 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package realdebrid
import (
"errors"
"math"
"strings"
@@ -134,8 +135,11 @@ type User struct {
// key: torrent hash
type AvailabilityResponse map[string]HosterHash
// key: "rd"
type HosterHash map[string][]SelectionVariant
type HosterHash struct {
// key: "rd"
Variants map[string][]SelectionVariant
Strings []string
}
// key: file id
type SelectionVariant map[int]FileData
@@ -144,3 +148,21 @@ type FileData struct {
Filename string `json:"filename"`
Filesize int `json:"filesize"`
}
func (h *HosterHash) UnmarshalJSON(data []byte) error {
// First, try unmarshaling as map[string][]SelectionVariant
var variants map[string][]SelectionVariant
if err := json.Unmarshal(data, &variants); err == nil {
h.Variants = variants
return nil
}
// If that fails, try unmarshaling as []string
var strings []string
if err := json.Unmarshal(data, &strings); err == nil {
h.Strings = strings
return nil
}
return errors.New("availability json data did not match expected formats (map or array)")
}