Support filtering by size
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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>")
|
||||||
|
|||||||
@@ -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>")
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user