Proper caching
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/davextra"
|
||||
)
|
||||
|
||||
// createMultiTorrentResponse creates a WebDAV response for a list of torrents
|
||||
@@ -33,7 +34,8 @@ func createMultiTorrentResponse(torrents []torrent.Torrent) (*dav.MultiStatus, e
|
||||
}, nil
|
||||
}
|
||||
|
||||
// createTorrentResponse creates a WebDAV response for torrents with the same name
|
||||
// createTorrentResponse creates a WebDAV response for a single torrent
|
||||
// but it also handles the case where there are many torrents with the same name
|
||||
func createCombinedTorrentResponse(torrents []torrent.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
|
||||
var responses []dav.Response
|
||||
// initial response is the directory itself
|
||||
@@ -41,16 +43,13 @@ func createCombinedTorrentResponse(torrents []torrent.Torrent, t *torrent.Torren
|
||||
responses = append(responses, dav.Directory(currentPath))
|
||||
|
||||
seen := make(map[string]bool)
|
||||
idx := 0
|
||||
|
||||
var torrentResponses []dav.Response
|
||||
for _, torrent := range torrents {
|
||||
info := t.GetInfo(torrent.ID)
|
||||
if info == nil {
|
||||
continue
|
||||
}
|
||||
for _, file := range info.SelectedFiles {
|
||||
for _, file := range torrent.SelectedFiles {
|
||||
filename := filepath.Base(file.Path)
|
||||
fragment := davextra.GetLinkFragment(file.Link)
|
||||
filename = davextra.InsertLinkFragment(filename, fragment)
|
||||
if _, exists := seen[filename]; exists {
|
||||
continue
|
||||
}
|
||||
@@ -59,10 +58,9 @@ func createCombinedTorrentResponse(torrents []torrent.Torrent, t *torrent.Torren
|
||||
torrentResponses = append(torrentResponses, dav.File(
|
||||
filePath,
|
||||
file.Bytes,
|
||||
convertDate(info.Added),
|
||||
info.Links[idx],
|
||||
convertDate(torrent.Added),
|
||||
file.Link,
|
||||
))
|
||||
idx++
|
||||
}
|
||||
}
|
||||
responses = append(responses, torrentResponses...)
|
||||
|
||||
Reference in New Issue
Block a user