Feature: Download client rules (#18)

* feat(web): add and update download client rules

* feat: add and update download client rules

* feat: add active downloads check

* chore: update pkg

* feat: deluge max active downloads

* feat: use basic rules for deluge

* feat: add as paused

* refactor: download file if needed

* feat: better errors qbit
This commit is contained in:
Ludvig Lundgren 2021-09-10 16:54:30 +02:00 committed by GitHub
parent 09eb0b1716
commit c02f16b64d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 628 additions and 228 deletions

View file

@ -3,6 +3,7 @@ package client
import (
"crypto/md5"
"encoding/hex"
"errors"
"fmt"
"io"
"net/http"
@ -40,8 +41,6 @@ func (c *HttpClient) DownloadFile(url string, opts map[string]string) (*Download
hashString := hex.EncodeToString(hash[:])
tmpFileName := fmt.Sprintf("/tmp/%v", hashString)
log.Debug().Msgf("tmpFileName: %v", tmpFileName)
// Create the file
out, err := os.Create(tmpFileName)
if err != nil {
@ -61,8 +60,6 @@ func (c *HttpClient) DownloadFile(url string, opts map[string]string) (*Download
// retry logic
log.Trace().Msgf("downloaded file response: %v - status: %v", resp.Status, resp.StatusCode)
if resp.StatusCode != 200 {
log.Error().Stack().Err(err).Msgf("error downloading file: %v - bad status: %d", tmpFileName, resp.StatusCode)
return nil, err
@ -82,7 +79,12 @@ func (c *HttpClient) DownloadFile(url string, opts map[string]string) (*Download
FileName: tmpFileName,
}
log.Trace().Msgf("successfully downloaded file: %v", tmpFileName)
if res.FileName == "" || res.Body == nil {
log.Error().Stack().Err(err).Msgf("tmp file error - empty body: %v", url)
return nil, errors.New("error downloading file, no tmp file")
}
log.Debug().Msgf("successfully downloaded file: %v", tmpFileName)
return &res, nil
}