Remove download mount config, it is now always enabled

This commit is contained in:
Ben Sarmiento
2024-05-25 15:11:11 +02:00
parent 2f777f63e9
commit 264d62d0dc
8 changed files with 39 additions and 82 deletions

View File

@@ -30,9 +30,8 @@ type TorrentManager struct {
log *logutil.Logger
repairLog *logutil.Logger
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
RootNode *fs.FileNode
@@ -64,9 +63,8 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
log: log,
repairLog: repairLog,
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
DownloadMap: cmap.New[*realdebrid.Download](),
DownloadCache: cmap.New[*realdebrid.Download](),
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
DownloadMap: cmap.New[*realdebrid.Download](),
RootNode: fs.NewFileNode("root", true),
@@ -96,19 +94,17 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
// proxy function
func (t *TorrentManager) UnrestrictLinkUntilOk(link string) *realdebrid.Download {
if strings.HasPrefix(link, "https://real-debrid.com/d/") && t.DownloadCache.Has(link[0:39]) {
ret, _ := t.DownloadCache.Get(link[0:39])
if strings.HasPrefix(link, "https://real-debrid.com/d/") && t.DownloadMap.Has(link[0:39]) {
ret, _ := t.DownloadMap.Get(link[0:39])
return ret
}
ret, err := t.api.UnrestrictLink(link, t.Config.ShouldServeFromRclone())
t.DownloadCache.Set(ret.Link[0:39], ret)
t.DownloadMap.Set(ret.Link[0:39], ret)
if err != nil {
t.log.Warnf("Cannot unrestrict link %s: %v", link, err)
return nil
}
if t.Config.EnableDownloadMount() {
t.DownloadMap.Set(ret.Filename, ret)
}
t.DownloadMap.Set(ret.Filename, ret)
return ret
}
@@ -273,22 +269,11 @@ func (t *TorrentManager) deleteInfoFile(torrentID string) {
/// end info functions
func (t *TorrentManager) mountDownloads() {
if !t.Config.EnableDownloadMount() {
return
}
t.DownloadMap.Clear()
t.DownloadCache.Clear()
_ = t.workerPool.Submit(func() {
downloads, totalDownloads, err := t.api.GetDownloads()
if err != nil {
t.log.Errorf("Cannot get downloads: %v", err)
}
t.log.Debugf("Got %d downloads", totalDownloads)
downloads := t.api.GetDownloads()
for i := range downloads {
idx := i
if strings.HasPrefix(downloads[idx].Link, "https://real-debrid.com/d/") {
t.DownloadCache.Set(downloads[idx].Link[0:39], &downloads[idx])
}
t.DownloadMap.Set(downloads[idx].Filename, &downloads[idx])
}
})