List broken files but dont serve them
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user