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)
}
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)
}
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 {
file, _ := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") {
if file.State.Is("deleted_file") {
continue
}
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {

View File

@@ -77,7 +77,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
sort.Strings(filenames)
for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") {
if file.State.Is("deleted_file") {
continue
}
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)
}
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)
}

View File

@@ -31,7 +31,7 @@ func HandleRenameFile(directory, torrentName, fileName, newName string, torMgr *
return fmt.Errorf("cannot find torrent %s", torrentName)
}
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)
}
oldName := torMgr.GetPath(file)

View File

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

View File

@@ -193,10 +193,7 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
bwLimitReached := false
// check for other broken file
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if bwLimitReached {
return
}
if !file.State.Is("ok_file") {
if bwLimitReached || !file.State.Is("ok_file") {
return
}
_, 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)
return
}
contentType := getContentMimeType(fileName)
contentLength := fmt.Sprintf("%d", file.Bytes)
lastModified := file.Ended

View File

@@ -87,14 +87,9 @@ func (dl *Downloader) DownloadFile(
return
}
if !file.State.Is("ok_file") {
http.Error(resp, "File is not available", http.StatusNotFound)
return
}
unrestrict, err := torMgr.UnrestrictFile(file, cfg.ShouldServeFromRclone())
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)
return
}
@@ -138,7 +133,7 @@ func (dl *Downloader) DownloadLink(
// log.Debugf("Opening file %s (%s)", fileName, link)
unrestrict, err := torMgr.UnrestrictLink(link, cfg.ShouldServeFromRclone())
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)
return
}
@@ -183,7 +178,7 @@ func (dl *Downloader) streamFileToResponse(
// Perform the request
downloadResp, err := dl.client.Do(dlReq)
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)
return
}