Add caching
This commit is contained in:
@@ -39,6 +39,7 @@ func createMultiTorrentResponse(basePath string, torrents []torrent.Torrent) (*d
|
||||
// but it also handles the case where there are many torrents with the same name
|
||||
func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
|
||||
var responses []dav.Response
|
||||
|
||||
// initial response is the directory itself
|
||||
currentPath := filepath.Join(basePath, torrents[0].Name)
|
||||
responses = append(responses, dav.Directory(currentPath))
|
||||
@@ -47,26 +48,28 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t
|
||||
finalName := make(map[string]bool)
|
||||
|
||||
var torrentResponses []dav.Response
|
||||
|
||||
for _, torrent := range torrents {
|
||||
for _, file := range torrent.SelectedFiles {
|
||||
if file.Link == "" {
|
||||
log.Println("File has no link, skipping", file.Path)
|
||||
// TODO: trigger a re-add for the file
|
||||
// It is selected but no link is available
|
||||
// I think this is handled on the manager side so we just need to refresh
|
||||
// t.RefreshInfo(torrent.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
filename := filepath.Base(file.Path)
|
||||
if _, exists := nameAndLink[filename+file.Link]; exists {
|
||||
key := filename + file.Link
|
||||
|
||||
if nameAndLink[key] {
|
||||
continue
|
||||
}
|
||||
nameAndLink[filename+file.Link] = true
|
||||
if _, exists := finalName[filename]; exists {
|
||||
nameAndLink[key] = true
|
||||
|
||||
if finalName[filename] {
|
||||
fragment := davextra.GetLinkFragment(file.Link)
|
||||
filename = davextra.InsertLinkFragment(filename, fragment)
|
||||
}
|
||||
finalName[filename] = true
|
||||
|
||||
filePath := filepath.Join(currentPath, filename)
|
||||
torrentResponses = append(torrentResponses, dav.File(
|
||||
filePath,
|
||||
@@ -76,6 +79,7 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
responses = append(responses, torrentResponses...)
|
||||
|
||||
return &dav.MultiStatus{
|
||||
|
||||
Reference in New Issue
Block a user