Return an error for 503

This commit is contained in:
Ben Adrian Sarmiento
2024-06-23 22:08:54 +02:00
parent 8bf39d58de
commit 3abf48514d
10 changed files with 87 additions and 65 deletions

View File

@@ -43,7 +43,7 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) {
data.Set("link", link)
requestBody := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/check", requestBody)
req, err := http.NewRequest(http.MethodPost, "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
@@ -74,7 +74,7 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) {
return &response, nil
}
func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Download, error) {
func (rd *RealDebrid) UnrestrictLink(link string, verifyDownloadURL bool) (*Download, error) {
data := url.Values{}
if strings.HasPrefix(link, "https://real-debrid.com/d/") {
// set link to max 39 chars
@@ -83,7 +83,7 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
data.Set("link", link)
requestBody := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "https://api.real-debrid.com/rest/1.0/unrestrict/link", requestBody)
req, err := http.NewRequest(http.MethodPost, "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
@@ -113,8 +113,8 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
}
// will only check for first byte if serving from rclone
if checkFirstByte && !rd.downloadClient.CanFetchFirstByte(response.Download) {
return nil, fmt.Errorf("can't fetch first byte")
if verifyDownloadURL && !rd.downloadClient.VerifyURL(response.Download) {
return nil, fmt.Errorf("download URL verification failed: %s", response.Download)
}
// rd.log.Debugf("Unrestricted link %s into %s", link, response.Download)
@@ -124,7 +124,7 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
func (rd *RealDebrid) GetTorrentInfo(id string) (*TorrentInfo, error) {
url := "https://api.real-debrid.com/rest/1.0/torrents/info/" + id
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
rd.log.Errorf("Error when creating a get info request: %v", err)
return nil, err
@@ -161,7 +161,7 @@ func (rd *RealDebrid) SelectTorrentFiles(id string, files string) error {
requestBody := strings.NewReader(data.Encode())
reqURL := fmt.Sprintf("https://api.real-debrid.com/rest/1.0/torrents/selectFiles/%s", id)
req, err := http.NewRequest("POST", reqURL, requestBody)
req, err := http.NewRequest(http.MethodPost, reqURL, requestBody)
if err != nil {
rd.log.Errorf("Error when creating a select files request: %v", err)
return err
@@ -184,7 +184,7 @@ func (rd *RealDebrid) SelectTorrentFiles(id string, files string) error {
func (rd *RealDebrid) DeleteTorrent(id string) error {
// Construct request URL
reqURL := fmt.Sprintf("https://api.real-debrid.com/rest/1.0/torrents/delete/%s", id)
req, err := http.NewRequest("DELETE", reqURL, nil)
req, err := http.NewRequest(http.MethodDelete, reqURL, nil)
if err != nil {
rd.log.Errorf("Error when creating a delete torrent request: %v", err)
return err
@@ -211,7 +211,7 @@ func (rd *RealDebrid) AddMagnetHash(magnet string) (*MagnetResponse, error) {
// Construct request URL
reqURL := "https://api.real-debrid.com/rest/1.0/torrents/addMagnet"
req, err := http.NewRequest("POST", reqURL, requestBody)
req, err := http.NewRequest(http.MethodPost, reqURL, requestBody)
if err != nil {
rd.log.Errorf("Error when creating an add magnet request: %v", err)
return nil, err
@@ -242,7 +242,7 @@ func (rd *RealDebrid) AddMagnetHash(magnet string) (*MagnetResponse, error) {
func (rd *RealDebrid) GetActiveTorrentCount() (*ActiveTorrentCountResponse, error) {
// Construct request URL
reqURL := "https://api.real-debrid.com/rest/1.0/torrents/activeCount"
req, err := http.NewRequest("GET", reqURL, nil)
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
if err != nil {
rd.log.Errorf("Error when creating a active torrents request: %v", err)
return nil, err
@@ -269,7 +269,7 @@ func (rd *RealDebrid) GetActiveTorrentCount() (*ActiveTorrentCountResponse, erro
func (rd *RealDebrid) GetUserInformation() (*User, error) {
// Construct request URL
reqURL := "https://api.real-debrid.com/rest/1.0/user"
req, err := http.NewRequest("GET", reqURL, nil)
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
if err != nil {
rd.log.Errorf("Error when creating a user information request: %v", err)
return nil, err
@@ -302,7 +302,7 @@ func (rd *RealDebrid) AvailabilityCheck(hashes []string) (AvailabilityResponse,
baseURL := "https://api.real-debrid.com/rest/1.0"
url := fmt.Sprintf("%s/torrents/instantAvailability/%s", baseURL, strings.Join(hashes, "/"))
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}

View File

@@ -80,7 +80,7 @@ func (rd *RealDebrid) fetchPageOfDownloads(page, limit int) fetchDownloadsResult
reqURL := baseURL + "?" + params.Encode()
req, err := http.NewRequest("GET", reqURL, nil)
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
if err != nil {
rd.log.Errorf("Error when creating a get downloads request: %v", err)
return fetchDownloadsResult{

View File

@@ -118,7 +118,7 @@ func (rd *RealDebrid) fetchPageOfTorrents(page, limit int) fetchTorrentsResult {
params.Set("limit", fmt.Sprintf("%d", limit))
reqURL := baseURL + "?" + params.Encode()
req, err := http.NewRequest("GET", reqURL, nil)
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
if err != nil {
rd.log.Errorf("Error when creating a get torrents request: %v", err)
return fetchTorrentsResult{