Support filtering by size

This commit is contained in:
Ben Sarmiento
2024-01-06 23:53:47 +01:00
parent 4b441ce2d8
commit 5d733b8be4
5 changed files with 26 additions and 5 deletions

View File

@@ -12,6 +12,8 @@ type Directory struct {
Group string `yaml:"group"` Group string `yaml:"group"`
Filters []*FilterConditionsV1 `yaml:"filters"` Filters []*FilterConditionsV1 `yaml:"filters"`
OnlyShowTheBiggestFile bool `yaml:"only_show_the_biggest_file"` OnlyShowTheBiggestFile bool `yaml:"only_show_the_biggest_file"`
OnlyShowFilesWithSizeLte int64 `yaml:"only_show_files_with_size_lte"`
OnlyShowFilesWithSizeGte int64 `yaml:"only_show_files_with_size_gte"`
} }
type FilterConditionsV1 struct { type FilterConditionsV1 struct {

View File

@@ -76,6 +76,12 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }
if dirCfg.OnlyShowFilesWithSizeLte > 0 && file.Bytes > dirCfg.OnlyShowFilesWithSizeLte {
continue
}
if dirCfg.OnlyShowFilesWithSizeGte > 0 && file.Bytes < dirCfg.OnlyShowFilesWithSizeGte {
continue
}
buf.WriteString(dav.File(filename, file.Bytes, file.Ended)) buf.WriteString(dav.File(filename, file.Bytes, file.Ended))
} }
buf.WriteString("</d:multistatus>") buf.WriteString("</d:multistatus>")

View File

@@ -80,6 +80,12 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }
if dirCfg.OnlyShowFilesWithSizeLte > 0 && file.Bytes > dirCfg.OnlyShowFilesWithSizeLte {
continue
}
if dirCfg.OnlyShowFilesWithSizeGte > 0 && file.Bytes < dirCfg.OnlyShowFilesWithSizeGte {
continue
}
buf.WriteString(dav.File(filename, file.Bytes, file.Ended)) buf.WriteString(dav.File(filename, file.Bytes, file.Ended))
} }
buf.WriteString("</d:multistatus>") buf.WriteString("</d:multistatus>")

View File

@@ -77,6 +77,12 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }
if dirCfg.OnlyShowFilesWithSizeLte > 0 && file.Bytes > dirCfg.OnlyShowFilesWithSizeLte {
continue
}
if dirCfg.OnlyShowFilesWithSizeGte > 0 && file.Bytes < dirCfg.OnlyShowFilesWithSizeGte {
continue
}
filePath := filepath.Join(directory, torrentName, url.PathEscape(filename)) filePath := filepath.Join(directory, torrentName, url.PathEscape(filename))
buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s\">%s</a></li>", filePath, filename)) buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s\">%s</a></li>", filePath, filename))
} }

View File

@@ -141,7 +141,8 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
if unplayable { if unplayable {
cb(config.UNPLAYABLE_TORRENTS) cb(config.UNPLAYABLE_TORRENTS)
break break
} else if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) { }
if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
cb(directory) cb(directory)
break break
} }