diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index bc5241e..2cea196 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -31,7 +31,10 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) { data := url.Values{} data.Set("link", link) - req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/check", bytes.NewBufferString(data.Encode())) + dataBytes := bytes.NewBufferString(data.Encode()) + requestBody := io.NopCloser(dataBytes) + + req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/check", requestBody) if err != nil { rd.log.Errorf("Error when creating a unrestrict check request: %v", err) return nil, err @@ -66,7 +69,10 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa data := url.Values{} data.Set("link", link) - req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/link", bytes.NewBufferString(data.Encode())) + dataBytes := bytes.NewBufferString(data.Encode()) + requestBody := io.NopCloser(dataBytes) + + req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/link", requestBody) if err != nil { rd.log.Errorf("Error when creating a unrestrict link request: %v", err) return nil, err @@ -214,8 +220,11 @@ func (rd *RealDebrid) SelectTorrentFiles(id string, files string) error { data := url.Values{} data.Set("files", files) + dataBytes := bytes.NewBufferString(data.Encode()) + requestBody := io.NopCloser(dataBytes) + reqURL := fmt.Sprintf("https://api.real-debrid.com/rest/1.0/torrents/selectFiles/%s", id) - req, err := http.NewRequest("POST", reqURL, bytes.NewBufferString(data.Encode())) + req, err := http.NewRequest("POST", reqURL, requestBody) if err != nil { rd.log.Errorf("Error when creating a select files request: %v", err) return err @@ -262,9 +271,12 @@ func (rd *RealDebrid) AddMagnetHash(magnet string) (*MagnetResponse, error) { data := url.Values{} data.Set("magnet", fmt.Sprintf("magnet:?xt=urn:btih:%s", magnet)) + dataBytes := bytes.NewBufferString(data.Encode()) + requestBody := io.NopCloser(dataBytes) + // Construct request URL reqURL := "https://api.real-debrid.com/rest/1.0/torrents/addMagnet" - req, err := http.NewRequest("POST", reqURL, bytes.NewBufferString(data.Encode())) + req, err := http.NewRequest("POST", reqURL, requestBody) if err != nil { rd.log.Errorf("Error when creating an add magnet request: %v", err) return nil, err