Do not unrestrict files that are marked as broken until it is fixed
This commit is contained in:
@@ -81,7 +81,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
||||
}
|
||||
|
||||
// proxy
|
||||
func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
func (t *TorrentManager) UnrestrictLinkUntilOk(link string) *realdebrid.Download {
|
||||
// check if it's a valid link
|
||||
if !strings.HasPrefix(link, "http") {
|
||||
return nil
|
||||
@@ -103,6 +103,13 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (t *TorrentManager) UnrestrictFileUntilOk(file *File) *realdebrid.Download {
|
||||
if file.IsBroken || file.IsDeleted {
|
||||
return nil
|
||||
}
|
||||
return t.UnrestrictLinkUntilOk(file.Link)
|
||||
}
|
||||
|
||||
func (t *TorrentManager) GetKey(torrent *Torrent) string {
|
||||
if !t.Config.ShouldIgnoreRenames() && torrent.Rename != "" {
|
||||
return torrent.Rename
|
||||
|
||||
@@ -267,7 +267,7 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
||||
newUnassignedLinks := cmap.New[*realdebrid.Download]()
|
||||
torrent.UnassignedLinks.Each(func(link string) bool {
|
||||
// unrestrict each unassigned link that was filled out during torrent init
|
||||
unrestrict := t.UnrestrictUntilOk(link)
|
||||
unrestrict := t.UnrestrictLinkUntilOk(link)
|
||||
if unrestrict == nil {
|
||||
newUnassignedLinks.Set(link, nil)
|
||||
// return early, no point continuing
|
||||
@@ -532,7 +532,7 @@ func (t *TorrentManager) isStillBroken(info *realdebrid.TorrentInfo, brokenFiles
|
||||
for _, oldFile := range brokenFiles {
|
||||
for idx, newFile := range selectedFiles {
|
||||
if oldFile.Bytes == newFile.Bytes {
|
||||
unrestrict := t.UnrestrictUntilOk(selectedFiles[idx].Link)
|
||||
unrestrict := t.UnrestrictFileUntilOk(selectedFiles[idx])
|
||||
if unrestrict == nil || oldFile.Bytes != unrestrict.Filesize {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
|
||||
return
|
||||
}
|
||||
|
||||
unrestrict := torMgr.UnrestrictUntilOk(file.Link)
|
||||
unrestrict := torMgr.UnrestrictFileUntilOk(file)
|
||||
if unrestrict == nil {
|
||||
file.IsBroken = true
|
||||
if cfg.EnableRepair() {
|
||||
@@ -91,7 +91,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
|
||||
// DownloadLink handles a GET request for downloads
|
||||
func (dl *Downloader) DownloadLink(fileName, link string, resp http.ResponseWriter, req *http.Request, torMgr *intTor.TorrentManager, cfg config.ConfigInterface, log *logutil.Logger) {
|
||||
// log.Debugf("Opening file %s (%s)", fileName, link)
|
||||
unrestrict := torMgr.UnrestrictUntilOk(link)
|
||||
unrestrict := torMgr.UnrestrictLinkUntilOk(link)
|
||||
if unrestrict == nil {
|
||||
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
|
||||
http.Error(resp, "File is not available", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user