Rework torrent manager handling of update

This commit is contained in:
Ben Sarmiento
2023-12-02 01:32:11 +01:00
parent 67f509248e
commit 2f7e3b0ca9
7 changed files with 228 additions and 232 deletions

View File

@@ -68,10 +68,7 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
if unrestrict == nil {
// log.Warnf("File %s is no longer available, link %s", filepath.Base(file.Path), link)
file.Link = "repair"
if cfg.EnableRepair() {
// log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
torMgr.ScheduleForRefresh() // force a recheck
}
torMgr.UpdateTorrentResponseCache(torrent)
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
@@ -92,7 +89,7 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
if cfg.ShouldServeFromRclone() {
redirect(resp, req, unrestrict.Download, cfg)
} else {
gf.streamFileToResponse(file, unrestrict.Download, resp, req, torMgr, cfg, log)
gf.streamFileToResponse(torrent, file, unrestrict.Download, resp, req, torMgr, cfg, log)
}
return
}
@@ -131,7 +128,7 @@ func (gf *GetFile) streamCachedLinkToResponse(url string, resp http.ResponseWrit
return nil
}
func (gf *GetFile) streamFileToResponse(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, url string, 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)
if err != nil {
@@ -152,10 +149,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, resp http
if file != nil {
log.Warnf("Cannot download file %s: %v", file.Path, err)
file.Link = "repair"
if cfg.EnableRepair() {
// log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
torMgr.ScheduleForRefresh() // force a recheck
}
torMgr.UpdateTorrentResponseCache(torrent)
}
http.Error(resp, "File is not available", http.StatusNotFound)
return
@@ -166,10 +160,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, resp http
if file != nil {
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
file.Link = "repair"
if cfg.EnableRepair() {
// log.Debugf("File %s is marked for repair", filepath.Base(file.Path))
torMgr.ScheduleForRefresh() // force a recheck
}
torMgr.UpdateTorrentResponseCache(torrent)
}
http.Error(resp, "File is not available", http.StatusNotFound)
return