Additional fixes on link checks

This commit is contained in:
Ben Sarmiento
2023-11-19 02:17:46 +01:00
parent 2923f3918d
commit ae635799f8
6 changed files with 10 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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