Readd downloads mount
This commit is contained in:
@@ -29,7 +29,7 @@ type ConfigInterface interface {
|
||||
ShouldForceIPv6() bool
|
||||
GetRealDebridTimeout() int
|
||||
GetRetriesUntilFailed() int
|
||||
EnableDownloadCache() bool
|
||||
EnableDownloadMount() bool
|
||||
GetRateLimitSleepSeconds() int
|
||||
ShouldDeleteRarFiles() bool
|
||||
}
|
||||
@@ -54,7 +54,7 @@ type ZurgConfig struct {
|
||||
DeleteRarFiles bool `yaml:"auto_delete_rar_torrents" json:"auto_delete_rar_torrents"`
|
||||
|
||||
RealDebridTimeout int `yaml:"realdebrid_timeout_secs" json:"realdebrid_timeout_secs"`
|
||||
UseDownloadCache bool `yaml:"use_download_cache" json:"use_download_cache"`
|
||||
DownloadMount bool `yaml:"enable_download_mount" json:"enable_download_mount"`
|
||||
RateLimitSleepSeconds int `yaml:"rate_limit_sleep_secs" json:"rate_limit_sleep_secs"`
|
||||
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
|
||||
PreferredHosts []string `yaml:"preferred_hosts" json:"preferred_hosts"`
|
||||
@@ -168,8 +168,8 @@ func (z *ZurgConfig) GetRetriesUntilFailed() int {
|
||||
return z.RetriesUntilFailed
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) EnableDownloadCache() bool {
|
||||
return z.UseDownloadCache
|
||||
func (z *ZurgConfig) EnableDownloadMount() bool {
|
||||
return z.DownloadMount
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) GetRealDebridTimeout() int {
|
||||
|
||||
@@ -23,7 +23,7 @@ func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
}
|
||||
buf.WriteString(dav.BaseDirectory(directory, ""))
|
||||
}
|
||||
if torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if torMgr.Config.EnableDownloadMount() {
|
||||
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
|
||||
}
|
||||
_, size := version.GetFile()
|
||||
@@ -95,7 +95,7 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
|
||||
|
||||
func ServeDownloadsListForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if !torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if !torMgr.Config.EnableDownloadMount() {
|
||||
buf.WriteString("Enable download cache in config to use this feature")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
}
|
||||
buf.WriteString(dav.Directory(directory, ""))
|
||||
}
|
||||
if torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if torMgr.Config.EnableDownloadMount() {
|
||||
buf.WriteString(dav.Directory(config.DOWNLOADS, ""))
|
||||
}
|
||||
_, size := version.GetFile()
|
||||
@@ -121,7 +121,7 @@ func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.T
|
||||
|
||||
func ServeDownloadsList(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if !torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if !torMgr.Config.EnableDownloadMount() {
|
||||
buf.WriteString("Enable download cache in config to use this feature")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
response.Config.EnableRepair(),
|
||||
response.Config.ShouldDeleteRarFiles(),
|
||||
response.Config.GetRealDebridTimeout(),
|
||||
response.Config.EnableDownloadCache(),
|
||||
response.Config.EnableDownloadMount(),
|
||||
response.Config.GetRateLimitSleepSeconds(),
|
||||
response.Config.GetRetriesUntilFailed(),
|
||||
strings.Join(response.Config.PreferredHosts, ", "),
|
||||
|
||||
@@ -17,7 +17,7 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<ol>")
|
||||
directories := torMgr.DirectoryMap.Keys()
|
||||
if torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if torMgr.Config.EnableDownloadMount() {
|
||||
directories = append(directories, config.DOWNLOADS)
|
||||
}
|
||||
sort.Strings(directories)
|
||||
@@ -95,7 +95,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
||||
|
||||
func ServeDownloadsList(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if !torMgr.Config.GetConfig().UseDownloadCache {
|
||||
if !torMgr.Config.EnableDownloadMount() {
|
||||
buf.WriteString("Enable download cache in config to use this feature")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package torrent
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -68,7 +67,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
||||
}
|
||||
|
||||
// Fetch downloads
|
||||
if t.Config.EnableDownloadCache() {
|
||||
if t.Config.EnableDownloadMount() {
|
||||
_ = t.workerPool.Submit(func() {
|
||||
page := 1
|
||||
offset := 0
|
||||
@@ -78,7 +77,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
||||
t.log.Fatalf("Cannot get downloads: %v", err)
|
||||
}
|
||||
for i := range downloads {
|
||||
t.cacheDownload(&downloads[i])
|
||||
t.DownloadMap.Set(downloads[i].Filename, &downloads[i])
|
||||
}
|
||||
offset += len(downloads)
|
||||
page++
|
||||
@@ -122,7 +121,8 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
return nil
|
||||
}
|
||||
if ret != nil && ret.Link != "" && ret.Filename != "" {
|
||||
t.cacheDownload(ret)
|
||||
t.DownloadCache.Set(ret.Link, ret)
|
||||
t.DownloadMap.Set(ret.Filename, ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -242,17 +242,3 @@ func (t *TorrentManager) deleteTorrentFile(torrentID string) {
|
||||
t.log.Warnf("Cannot delete file %s: %v", filePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
func replaceHostInURL(inputURL string, newHost string) string {
|
||||
u, err := url.Parse(inputURL)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
u.Host = newHost
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func (t *TorrentManager) cacheDownload(ret *realdebrid.Download) {
|
||||
t.DownloadCache.Set(ret.Link, ret)
|
||||
t.DownloadMap.Set(ret.Filename, ret)
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
|
||||
|
||||
defer download.Body.Close()
|
||||
|
||||
if download.StatusCode != http.StatusOK && download.StatusCode != http.StatusPartialContent {
|
||||
if download.StatusCode/100 != 2 {
|
||||
if file != nil && unrestrict.Streamable == 1 {
|
||||
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
||||
torrent.BrokenLinks.Add(file.Link)
|
||||
|
||||
Reference in New Issue
Block a user