From ae635799f80a1aa1dc1ced23d69b8ca0caa4fc8c Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 19 Nov 2023 02:17:46 +0100 Subject: [PATCH] Additional fixes on link checks --- internal/dav/listing.go | 2 +- internal/http/listing.go | 2 +- internal/torrent/manager.go | 10 +++++----- internal/universal/get.go | 2 +- internal/universal/head.go | 2 +- pkg/realdebrid/unrestrict.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/dav/listing.go b/internal/dav/listing.go index c6ee254..2cacc5d 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -112,7 +112,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) ([]byte, sort.Strings(filenames) for _, filename := range filenames { file, _ := tor.SelectedFiles.Get(filename) - if file == nil || file.Link == "" { + if file == nil || !strings.HasPrefix(file.Link, "http") { continue } responses = append(responses, dav.File( diff --git a/internal/http/listing.go b/internal/http/listing.go index 3904bfb..8015396 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -96,7 +96,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string sort.Strings(filenames) for _, filename := range filenames { file, _ := tor.SelectedFiles.Get(filename) - if file == nil || file.Link == "" { + if file == nil || !strings.HasPrefix(file.Link, "http") { // will be caught by torrent manager's repairAll // just skip it for now continue diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index c4fca9f..6e0f44a 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -141,10 +141,10 @@ func (t *TorrentManager) mergeToMain(mainTorrent, torrentToMerge *Torrent) *Torr mainTorrent.SelectedFiles.Set(filepath, fileToMerge) } else { // if it exists, compare the LatestAdded property and the link - if mainTorrent.LatestAdded < torrentToMerge.LatestAdded && fileToMerge.Link != "" { + if mainTorrent.LatestAdded < torrentToMerge.LatestAdded && strings.HasPrefix(fileToMerge.Link, "http") { // if torrentToMerge is more recent and its file has a link, update the main torrent's file mainTorrent.SelectedFiles.Set(filepath, fileToMerge) - } else if mainFile.Link == "" && fileToMerge.Link != "" { + } else if !strings.HasPrefix(mainFile.Link, "http") && strings.HasPrefix(fileToMerge.Link, "http") { // if the main torrent's file link is empty and t2's file has a link, even if it's older, update it mainTorrent.SelectedFiles.Set(filepath, fileToMerge) } @@ -590,7 +590,7 @@ func (t *TorrentManager) Repair(accessKey string) { ZurgFS: file.ZurgFS, } selectedFiles = append(selectedFiles, fileCopy) - if fileCopy.Link != "" { + if strings.HasPrefix(fileCopy.Link, "http") { links = append(links, fileCopy.Link) } fileCopy.Link = "" // empty the links = chaos! @@ -619,7 +619,7 @@ func (t *TorrentManager) Repair(accessKey string) { // if all the selected files are missing but there are other streamable files var missingFiles []File torrent.SelectedFiles.IterCb(func(_ string, file *File) { - if file.Link == "" { + if !strings.HasPrefix(file.Link, "http") { missingFiles = append(missingFiles, *file) } }) @@ -643,7 +643,7 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string) if missingFiles == "" { tmpSelection := "" torrent.SelectedFiles.IterCb(func(_ string, file *File) { - if file.Link == "" { + if !strings.HasPrefix(file.Link, "http") { tmpSelection += fmt.Sprintf("%d,", file.ID) } }) diff --git a/internal/universal/get.go b/internal/universal/get.go index 3e3b4b2..d234b0e 100644 --- a/internal/universal/get.go +++ b/internal/universal/get.go @@ -70,7 +70,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *intTor.TorrentM return } - if file.Link == "" { + if !strings.HasPrefix(file.Link, "http") { // This is a dead file, serve an alternate file log.Warnf("File %s is not yet available, zurg is repairing the torrent", filename) streamErrorVideo("https://www.youtube.com/watch?v=bGTqwt6vdcY", w, r, t, c, log) diff --git a/internal/universal/head.go b/internal/universal/head.go index 1e4bd55..f44068a 100644 --- a/internal/universal/head.go +++ b/internal/universal/head.go @@ -62,7 +62,7 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren http.Error(w, "Cannot find file", http.StatusNotFound) return } - if file.Link == "" { + if !strings.HasPrefix(file.Link, "http") { // This is a dead file, serve an alternate file log.Warnf("File %s is no longer available", filename) http.Error(w, "Cannot find file", http.StatusNotFound) diff --git a/pkg/realdebrid/unrestrict.go b/pkg/realdebrid/unrestrict.go index 26b3ba7..dddf7fc 100644 --- a/pkg/realdebrid/unrestrict.go +++ b/pkg/realdebrid/unrestrict.go @@ -7,7 +7,7 @@ import ( ) func (rd *RealDebrid) UnrestrictUntilOk(link string) *UnrestrictResponse { - if link == "" { + if !strings.HasPrefix(link, "http") { return nil } unrestrictFn := func(link string) (*UnrestrictResponse, error) {