Remove download cache
This commit is contained in:
@@ -25,7 +25,6 @@ type TorrentManager struct {
|
|||||||
Config config.ConfigInterface
|
Config config.ConfigInterface
|
||||||
Api *realdebrid.RealDebrid
|
Api *realdebrid.RealDebrid
|
||||||
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
||||||
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
|
|
||||||
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||||
fixers cmap.ConcurrentMap[string, string] // trigger -> [command, id]
|
fixers cmap.ConcurrentMap[string, string] // trigger -> [command, id]
|
||||||
allAccessKeys mapset.Set[string]
|
allAccessKeys mapset.Set[string]
|
||||||
@@ -51,7 +50,6 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
|||||||
Config: cfg,
|
Config: cfg,
|
||||||
Api: api,
|
Api: api,
|
||||||
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
|
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
|
||||||
DownloadCache: cmap.New[*realdebrid.Download](),
|
|
||||||
RefreshKillSwitch: make(chan struct{}, 1),
|
RefreshKillSwitch: make(chan struct{}, 1),
|
||||||
RepairKillSwitch: make(chan struct{}, 1),
|
RepairKillSwitch: make(chan struct{}, 1),
|
||||||
RemountTrigger: make(chan struct{}, 1),
|
RemountTrigger: make(chan struct{}, 1),
|
||||||
@@ -82,20 +80,12 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
|||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
func (t *TorrentManager) UnrestrictLinkUntilOk(link string) *realdebrid.Download {
|
func (t *TorrentManager) UnrestrictLinkUntilOk(link string) *realdebrid.Download {
|
||||||
// check if it's a valid link
|
|
||||||
if !strings.HasPrefix(link, "http") {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if download, exists := t.DownloadCache.Get(link); exists {
|
|
||||||
return download
|
|
||||||
}
|
|
||||||
ret, err := t.Api.UnrestrictLink(link, t.Config.ShouldServeFromRclone())
|
ret, err := t.Api.UnrestrictLink(link, t.Config.ShouldServeFromRclone())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.log.Warnf("Cannot unrestrict link %s: %v", link, err)
|
t.log.Warnf("Cannot unrestrict link %s: %v", link, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ret != nil && ret.Link != "" && ret.Filename != "" {
|
if ret != nil && ret.Link != "" && ret.Filename != "" {
|
||||||
t.DownloadCache.Set(ret.Link, ret)
|
|
||||||
if t.Config.EnableDownloadMount() {
|
if t.Config.EnableDownloadMount() {
|
||||||
t.DownloadMap.Set(ret.Filename, ret)
|
t.DownloadMap.Set(ret.Filename, ret)
|
||||||
}
|
}
|
||||||
@@ -199,7 +189,7 @@ func (t *TorrentManager) mountDownloads() {
|
|||||||
if !t.Config.EnableDownloadMount() {
|
if !t.Config.EnableDownloadMount() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
t.DownloadMap.Clear()
|
||||||
_ = t.workerPool.Submit(func() {
|
_ = t.workerPool.Submit(func() {
|
||||||
page := 1
|
page := 1
|
||||||
offset := 0
|
offset := 0
|
||||||
|
|||||||
@@ -92,11 +92,6 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
rd.log.Errorf("Unrestrict link request returned status code %d for link %s", resp.StatusCode, link)
|
|
||||||
// return nil, fmt.Errorf("unrestrict link request returned status code %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// rd.log.Errorf("Error when reading the body of unrestrict link response: %v", err)
|
// rd.log.Errorf("Error when reading the body of unrestrict link response: %v", err)
|
||||||
@@ -433,10 +428,6 @@ func (rd *RealDebrid) AvailabilityCheck(hashes []string) (AvailabilityResponse,
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return nil, fmt.Errorf("error, got response status code %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
var response AvailabilityResponse
|
var response AvailabilityResponse
|
||||||
err = json.NewDecoder(resp.Body).Decode(&response)
|
err = json.NewDecoder(resp.Body).Decode(&response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user