List broken files but dont serve them

This commit is contained in:
Ben Adrian Sarmiento
2024-06-26 10:44:16 +02:00
parent e4650a0f0f
commit d5e3665a53
8 changed files with 12 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ func HandleDeleteFile(directory, torrentName, fileName string, torMgr *torrent.T
return fmt.Errorf("cannot find torrent %s", torrentName) return fmt.Errorf("cannot find torrent %s", torrentName)
} }
file, ok := torrent.SelectedFiles.Get(fileName) file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") { if !ok || file.State.Is("deleted_file") {
return fmt.Errorf("cannot find file %s", fileName) return fmt.Errorf("cannot find file %s", fileName)
} }
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory) dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)

View File

@@ -85,7 +85,7 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
for _, filename := range filenames { for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename) file, _ := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") { if file.State.Is("deleted_file") {
continue continue
} }
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {

View File

@@ -77,7 +77,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
sort.Strings(filenames) sort.Strings(filenames)
for _, filename := range filenames { for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename) file, _ := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") { if file.State.Is("deleted_file") {
continue continue
} }
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
@@ -105,7 +105,7 @@ func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.T
return nil, fmt.Errorf("cannot find torrent %s", torrentName) return nil, fmt.Errorf("cannot find torrent %s", torrentName)
} }
file, ok := tor.SelectedFiles.Get(fileName) file, ok := tor.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") { if !ok || file.State.Is("deleted_file") {
return nil, fmt.Errorf("cannot find file %s", fileName) return nil, fmt.Errorf("cannot find file %s", fileName)
} }

View File

@@ -31,7 +31,7 @@ func HandleRenameFile(directory, torrentName, fileName, newName string, torMgr *
return fmt.Errorf("cannot find torrent %s", torrentName) return fmt.Errorf("cannot find torrent %s", torrentName)
} }
file, ok := torrent.SelectedFiles.Get(fileName) file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") { if !ok || file.State.Is("deleted_file") {
return fmt.Errorf("cannot find file %s", fileName) return fmt.Errorf("cannot find file %s", fileName)
} }
oldName := torMgr.GetPath(file) oldName := torMgr.GetPath(file)

View File

@@ -72,8 +72,8 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
filenames := tor.SelectedFiles.Keys() filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames) sort.Strings(filenames)
for _, filename := range filenames { for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename) file, ok := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") { if !ok || file.State.Is("deleted_file") {
continue continue
} }
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {

View File

@@ -193,10 +193,7 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
bwLimitReached := false bwLimitReached := false
// check for other broken file // check for other broken file
torrent.SelectedFiles.IterCb(func(_ string, file *File) { torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if bwLimitReached { if bwLimitReached || !file.State.Is("ok_file") {
return
}
if !file.State.Is("ok_file") {
return return
} }
_, err := t.UnrestrictFile(file, true) _, err := t.UnrestrictFile(file, true)

View File

@@ -32,6 +32,7 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
http.Error(w, "File not found", http.StatusNotFound) http.Error(w, "File not found", http.StatusNotFound)
return return
} }
contentType := getContentMimeType(fileName) contentType := getContentMimeType(fileName)
contentLength := fmt.Sprintf("%d", file.Bytes) contentLength := fmt.Sprintf("%d", file.Bytes)
lastModified := file.Ended lastModified := file.Ended

View File

@@ -87,14 +87,9 @@ func (dl *Downloader) DownloadFile(
return return
} }
if !file.State.Is("ok_file") {
http.Error(resp, "File is not available", http.StatusNotFound)
return
}
unrestrict, err := torMgr.UnrestrictFile(file, cfg.ShouldServeFromRclone()) unrestrict, err := torMgr.UnrestrictFile(file, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" { if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET") // log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked) http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return return
} }
@@ -138,7 +133,7 @@ func (dl *Downloader) DownloadLink(
// log.Debugf("Opening file %s (%s)", fileName, link) // log.Debugf("Opening file %s (%s)", fileName, link)
unrestrict, err := torMgr.UnrestrictLink(link, cfg.ShouldServeFromRclone()) unrestrict, err := torMgr.UnrestrictLink(link, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" { if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET") // log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "Link is not available (bandwidth limit reached)", http.StatusLocked) http.Error(resp, "Link is not available (bandwidth limit reached)", http.StatusLocked)
return return
} }
@@ -183,7 +178,7 @@ func (dl *Downloader) streamFileToResponse(
// Perform the request // Perform the request
downloadResp, err := dl.client.Do(dlReq) downloadResp, err := dl.client.Do(dlReq)
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" { if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET") // log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked) http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return return
} }