Rework torrent manager handling of update
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user