Refactor for hotfix release

This commit is contained in:
Ben Sarmiento
2023-12-06 12:22:13 +01:00
parent d42dfd7224
commit 3a753f6f26
7 changed files with 574 additions and 575 deletions

View File

@@ -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)

View File

@@ -58,12 +58,6 @@ func getContentMimeType(filePath string) string {
return "audio/mpeg"
case ".rar":
return "application/x-rar-compressed"
case ".zip":
return "application/zip"
case ".7z":
return "application/x-7z-compressed"
case ".srt":
return "text/plain"
default:
return "application/octet-stream"
}