Refactor for hotfix release
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
intTor "github.com/debridmediamanager/zurg/internal/torrent"
|
||||
zurghttp "github.com/debridmediamanager/zurg/pkg/http"
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -89,7 +90,7 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
|
||||
if cfg.ShouldServeFromRclone() {
|
||||
redirect(resp, req, unrestrict.Download, cfg)
|
||||
} else {
|
||||
gf.streamFileToResponse(torrent, file, unrestrict.Download, resp, req, torMgr, cfg, log)
|
||||
gf.streamFileToResponse(torrent, file, unrestrict, resp, req, torMgr, cfg, log)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -128,9 +129,9 @@ func (gf *GetFile) streamCachedLinkToResponse(url string, resp http.ResponseWrit
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.File, url string, resp http.ResponseWriter, req *http.Request, torMgr *intTor.TorrentManager, cfg config.ConfigInterface, log *zap.SugaredLogger) {
|
||||
func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.File, unrestrict *realdebrid.Download, resp http.ResponseWriter, req *http.Request, torMgr *intTor.TorrentManager, cfg config.ConfigInterface, log *zap.SugaredLogger) {
|
||||
// Create a new request for the file download.
|
||||
dlReq, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
dlReq, err := http.NewRequest(http.MethodGet, unrestrict.Download, nil)
|
||||
if err != nil {
|
||||
if file != nil {
|
||||
log.Errorf("Error creating new request for file %s: %v", file.Path, err)
|
||||
@@ -146,7 +147,7 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
||||
|
||||
download, err := gf.client.Do(dlReq)
|
||||
if err != nil {
|
||||
if file != nil {
|
||||
if file != nil && unrestrict.Streamable == 1 {
|
||||
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
||||
file.Link = "repairing"
|
||||
torMgr.Repair(torrent)
|
||||
@@ -157,7 +158,7 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
||||
defer download.Body.Close()
|
||||
|
||||
if download.StatusCode != http.StatusOK && download.StatusCode != http.StatusPartialContent {
|
||||
if file != nil {
|
||||
if file != nil && unrestrict.Streamable == 1 {
|
||||
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
||||
file.Link = "repairing"
|
||||
torMgr.Repair(torrent)
|
||||
|
||||
Reference in New Issue
Block a user