Biggest file filter

This commit is contained in:
Ben Sarmiento
2023-12-07 22:34:25 +01:00
parent 7d5e5caf6e
commit 045c31a9f9
5 changed files with 33 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"sort"
"strings"
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/internal/torrent"
"github.com/debridmediamanager/zurg/pkg/logutil"
)
@@ -59,6 +60,12 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
}
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
biggestFileSize := int64(0)
if dirCfg.OnlyShowTheBiggestFile {
biggestFileSize = tor.ComputeBiggestFileSize()
}
htmlDoc := "<ol>"
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)
@@ -67,6 +74,9 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
if !ok || !strings.HasPrefix(file.Link, "http") {
continue
}
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue
}
filePath := filepath.Join(directory, torrentName, url.PathEscape(filename))
htmlDoc += fmt.Sprintf("<li><a href=\"/http/%s\">%s</a></li>", filePath, filename)
}