Reimplement deletes and marking files as broken

This commit is contained in:
Ben Sarmiento
2024-01-29 22:28:27 +01:00
parent 1615c9e121
commit b505400f60
12 changed files with 64 additions and 112 deletions

View File

@@ -27,17 +27,11 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
}
file, ok := torrent.SelectedFiles.Get(fileName)
if !ok {
if !ok || file.IsDeleted {
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(w, "Cannot find file", http.StatusNotFound)
return
}
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)
return
}
contentType := getContentMimeType(fileName)
contentLength := fmt.Sprintf("%d", file.Bytes)
lastModified := file.Ended
@@ -48,12 +42,6 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
}
func CheckDownloadLink(download *realdebrid.Download, w http.ResponseWriter, req *http.Request, torMgr *torrent.TorrentManager, log *logutil.Logger) {
if !strings.HasPrefix(download.Link, "http") {
// This is a dead file, serve an alternate file
log.Warnf("File %s is no longer available", download.Filename)
http.Error(w, "Cannot find file", http.StatusNotFound)
return
}
contentType := getContentMimeType(download.Filename)
contentLength := fmt.Sprintf("%d", download.Filesize)
lastModified := download.Generated