Add setting for hiding broken torrents

This commit is contained in:
Ben Adrian Sarmiento
2024-07-06 23:56:12 +02:00
parent acd18aca9a
commit 1373bbb975
5 changed files with 20 additions and 5 deletions

View File

@@ -39,6 +39,7 @@ type ConfigInterface interface {
ShouldIgnoreRenames() bool ShouldIgnoreRenames() bool
ShouldLogRequests() bool ShouldLogRequests() bool
ShouldServeFromRclone() bool ShouldServeFromRclone() bool
ShouldHideBrokenTorrents() bool
} }
type ZurgConfig struct { type ZurgConfig struct {
@@ -71,6 +72,7 @@ type ZurgConfig struct {
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"` RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"`
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"` RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"` 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"` Username string `yaml:"username" json:"username"`
} }
@@ -232,3 +234,7 @@ func (z *ZurgConfig) ShouldLogRequests() bool {
func (z *ZurgConfig) GetDownloadTokens() []string { func (z *ZurgConfig) GetDownloadTokens() []string {
return z.DownloadTokens return z.DownloadTokens
} }
func (z *ZurgConfig) ShouldHideBrokenTorrents() bool {
return z.HideBrokenTorrents
}

View File

@@ -59,7 +59,7 @@ func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager
return buf.Bytes(), nil 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) torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok { if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory) 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") { if file.State.Is("deleted_file") {
continue continue
} }
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
continue
}
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }

View File

@@ -54,7 +54,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte
return buf.Bytes(), nil 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) torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok { if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory) 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") { if file.State.Is("deleted_file") {
continue continue
} }
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
continue
}
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }

View File

@@ -220,7 +220,7 @@ func (hs *Handlers) handleInfuseTorrentsList(resp http.ResponseWriter, req *http
// handle files list request // 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")) directory, err := url.PathUnescape(chi.URLParam(req, "directory"))
if err != nil { if err != nil {
directory = chi.URLParam(req, "directory") directory = chi.URLParam(req, "directory")
@@ -229,7 +229,7 @@ func (hs *Handlers) innerFilesListHandler(resp http.ResponseWriter, req *http.Re
if err != nil { if err != nil {
torrentName = chi.URLParam(req, "torrent") 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") { if err != nil && strings.Contains(contentType, "xml") {
hs.log.Debugf("Not implemented: %s %s", req.Method, req.URL) hs.log.Debugf("Not implemented: %s %s", req.Method, req.URL)
resp.WriteHeader(http.StatusNotImplemented) resp.WriteHeader(http.StatusNotImplemented)

View File

@@ -51,7 +51,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte
return buf.Bytes(), nil 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) torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok { if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory) 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") { if !ok || file.State.Is("deleted_file") {
continue continue
} }
if file.State.Is("broken_file") && shouldHideBrokenTorrents {
continue
}
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize { if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
continue continue
} }