Add setting for hiding broken torrents
This commit is contained in:
@@ -39,6 +39,7 @@ type ConfigInterface interface {
|
||||
ShouldIgnoreRenames() bool
|
||||
ShouldLogRequests() bool
|
||||
ShouldServeFromRclone() bool
|
||||
ShouldHideBrokenTorrents() bool
|
||||
}
|
||||
|
||||
type ZurgConfig struct {
|
||||
@@ -71,6 +72,7 @@ type ZurgConfig struct {
|
||||
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"`
|
||||
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
|
||||
ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"`
|
||||
HideBrokenTorrents bool `yaml:"show_broken_torrents" json:"show_broken_torrents"`
|
||||
Username string `yaml:"username" json:"username"`
|
||||
}
|
||||
|
||||
@@ -232,3 +234,7 @@ func (z *ZurgConfig) ShouldLogRequests() bool {
|
||||
func (z *ZurgConfig) GetDownloadTokens() []string {
|
||||
return z.DownloadTokens
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) ShouldHideBrokenTorrents() bool {
|
||||
return z.HideBrokenTorrents
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -88,6 +88,9 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
|
||||
if file.State.Is("deleted_file") {
|
||||
continue
|
||||
}
|
||||
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
|
||||
continue
|
||||
}
|
||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -80,6 +80,9 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
||||
if file.State.Is("deleted_file") {
|
||||
continue
|
||||
}
|
||||
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
|
||||
continue
|
||||
}
|
||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (hs *Handlers) handleInfuseTorrentsList(resp http.ResponseWriter, req *http
|
||||
|
||||
// handle files list request
|
||||
|
||||
func (hs *Handlers) innerFilesListHandler(resp http.ResponseWriter, req *http.Request, handleFunc func(string, string, *torrent.TorrentManager) ([]byte, error), contentType string) {
|
||||
func (hs *Handlers) innerFilesListHandler(resp http.ResponseWriter, req *http.Request, handleFunc func(string, string, *torrent.TorrentManager, bool) ([]byte, error), contentType string) {
|
||||
directory, err := url.PathUnescape(chi.URLParam(req, "directory"))
|
||||
if err != nil {
|
||||
directory = chi.URLParam(req, "directory")
|
||||
@@ -229,7 +229,7 @@ func (hs *Handlers) innerFilesListHandler(resp http.ResponseWriter, req *http.Re
|
||||
if err != nil {
|
||||
torrentName = chi.URLParam(req, "torrent")
|
||||
}
|
||||
out, err := handleFunc(directory, torrentName, hs.torMgr)
|
||||
out, err := handleFunc(directory, torrentName, hs.torMgr, hs.cfg.ShouldHideBrokenTorrents())
|
||||
if err != nil && strings.Contains(contentType, "xml") {
|
||||
hs.log.Debugf("Not implemented: %s %s", req.Method, req.URL)
|
||||
resp.WriteHeader(http.StatusNotImplemented)
|
||||
|
||||
@@ -51,7 +51,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -76,6 +76,9 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
||||
if !ok || file.State.Is("deleted_file") {
|
||||
continue
|
||||
}
|
||||
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
|
||||
continue
|
||||
}
|
||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user