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,
|
||||
|
||||
Reference in New Issue
Block a user