fix propfind cache
This commit is contained in:
@@ -36,11 +36,11 @@ func (c *Cache) RefreshListings(refreshRclone bool) {
|
||||
return
|
||||
}
|
||||
// Copy the torrents to a string|time map
|
||||
torrentsTime := make(map[string]time.Time, c.torrents.Size())
|
||||
torrents := make([]string, 0, c.torrents.Size())
|
||||
c.torrentsNames.Range(func(key string, value *CachedTorrent) bool {
|
||||
torrentsTime[key] = value.AddedOn
|
||||
torrents = append(torrents, key)
|
||||
torrentsTime := make(map[string]time.Time, c.torrentsNames.Size())
|
||||
torrents := make([]string, 0, c.torrentsNames.Size())
|
||||
c.torrentsNames.Range(func(name string, value *CachedTorrent) bool {
|
||||
torrentsTime[name] = value.AddedOn
|
||||
torrents = append(torrents, name)
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -59,7 +59,7 @@ func (c *Cache) RefreshListings(refreshRclone bool) {
|
||||
}
|
||||
// Atomic store of the complete ready-to-use slice
|
||||
c.listings.Store(files)
|
||||
if err := c.RefreshParentXml(); err != nil {
|
||||
if err := c.refreshParentXml(); err != nil {
|
||||
c.logger.Debug().Err(err).Msg("Failed to refresh XML")
|
||||
}
|
||||
|
||||
|
||||
@@ -201,9 +201,10 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
||||
AddedOn: addedOn,
|
||||
IsComplete: len(newTorrent.Files) > 0,
|
||||
}
|
||||
// We can safely delete the old torrent here
|
||||
c.setTorrent(ct)
|
||||
c.RefreshListings(true)
|
||||
|
||||
// We can safely delete the old torrent here
|
||||
if oldID != "" {
|
||||
if err := c.DeleteTorrent(oldID); err != nil {
|
||||
return ct, fmt.Errorf("failed to delete old torrent: %w", err)
|
||||
|
||||
@@ -2,14 +2,12 @@ package debrid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
"github.com/sirrobot01/decypharr/internal/request"
|
||||
"net/http"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// resetPropfindResponse resets the propfind response cache for the specified parent directories.
|
||||
@@ -38,19 +36,19 @@ func (c *Cache) resetPropfindResponse() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) RefreshParentXml() error {
|
||||
func (c *Cache) refreshParentXml() error {
|
||||
parents := []string{"__all__", "torrents"}
|
||||
torrents := c.GetListing()
|
||||
clientName := c.client.GetName()
|
||||
for _, parent := range parents {
|
||||
if err := c.refreshParentXml(torrents, clientName, parent); err != nil {
|
||||
if err := c.refreshFolderXml(torrents, clientName, parent); err != nil {
|
||||
return fmt.Errorf("failed to refresh XML for %s: %v", parent, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) refreshParentXml(torrents []os.FileInfo, clientName, parent string) error {
|
||||
func (c *Cache) refreshFolderXml(torrents []os.FileInfo, clientName, parent string) error {
|
||||
// Define the WebDAV namespace
|
||||
davNS := "DAV:"
|
||||
|
||||
@@ -65,15 +63,15 @@ func (c *Cache) refreshParentXml(torrents []os.FileInfo, clientName, parent stri
|
||||
currentTime := time.Now().UTC().Format(http.TimeFormat)
|
||||
|
||||
// Add the parent directory
|
||||
baseUrl := path.Clean(path.Join("webdav", clientName, parent))
|
||||
parentPath := path.Join(baseUrl)
|
||||
baseUrl := path.Clean(fmt.Sprintf("/webdav/%s/%s", clientName, parent))
|
||||
parentPath := fmt.Sprintf("%s/", baseUrl)
|
||||
addDirectoryResponse(multistatus, parentPath, parent, currentTime)
|
||||
|
||||
// Add torrents to the XML
|
||||
for _, torrent := range torrents {
|
||||
name := torrent.Name()
|
||||
// Note the path structure change - parent first, then torrent name
|
||||
torrentPath := filepath.Join("webdav",
|
||||
torrentPath := fmt.Sprintf("/webdav/%s/%s/%s/",
|
||||
clientName,
|
||||
parent,
|
||||
name,
|
||||
|
||||
@@ -115,12 +115,12 @@ func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
|
||||
q.MarkAsFailed(torrent)
|
||||
return
|
||||
}
|
||||
timer := time.Now()
|
||||
|
||||
rclonePath := filepath.Join(debridTorrent.MountPath, cache.GetTorrentFolder(debridTorrent)) // /mnt/remote/realdebrid/MyTVShow
|
||||
torrentFolderNoExt := utils.RemoveExtension(debridTorrent.Name)
|
||||
|
||||
timer := time.Now()
|
||||
torrentSymlinkPath, err = q.createSymlinksWebdav(debridTorrent, rclonePath, torrentFolderNoExt) // /mnt/symlinks/{category}/MyTVShow/
|
||||
q.logger.Debug().Msgf("Torrent adding process completed in %s", time.Since(timer))
|
||||
q.logger.Debug().Msgf("Adding %s took %s", debridTorrent.Name, time.Since(timer))
|
||||
|
||||
} else {
|
||||
// User is using either zurg or debrid webdav
|
||||
|
||||
@@ -267,7 +267,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
ttl := 1 * time.Minute
|
||||
if h.isParentPath(r.URL.Path) {
|
||||
// __all__ or torrents folder
|
||||
// Manually build the xml
|
||||
ttl = 30 * time.Second
|
||||
}
|
||||
|
||||
@@ -345,7 +344,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if file, ok := fRaw.(*File); ok {
|
||||
link, err := file.getDownloadLink()
|
||||
if err != nil {
|
||||
h.logger.Error().
|
||||
h.logger.Trace().
|
||||
Err(err).
|
||||
Str("path", r.URL.Path).
|
||||
Msg("Could not fetch download link")
|
||||
|
||||
Reference in New Issue
Block a user