diff --git a/internal/dav/delete.go b/internal/dav/delete.go index 91ddda6..28cf33f 100644 --- a/internal/dav/delete.go +++ b/internal/dav/delete.go @@ -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) diff --git a/internal/dav/infuse.go b/internal/dav/infuse.go index 3539bfe..8bcad6e 100644 --- a/internal/dav/infuse.go +++ b/internal/dav/infuse.go @@ -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 { diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 0c448d9..cc0ff31 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -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) } diff --git a/internal/dav/rename.go b/internal/dav/rename.go index 89bb2b8..b8cd752 100644 --- a/internal/dav/rename.go +++ b/internal/dav/rename.go @@ -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) diff --git a/internal/http/listing.go b/internal/http/listing.go index 98d6b00..9b2b79c 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -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 { diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index de8fd25..9f0253d 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -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) diff --git a/internal/universal/check.go b/internal/universal/check.go index 2f87a2c..9177f88 100644 --- a/internal/universal/check.go +++ b/internal/universal/check.go @@ -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 diff --git a/internal/universal/downloader.go b/internal/universal/downloader.go index 4af324a..aea9bc6 100644 --- a/internal/universal/downloader.go +++ b/internal/universal/downloader.go @@ -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 }