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