Refactor torrent manager
This commit is contained in:
@@ -11,22 +11,14 @@ import (
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
)
|
||||
|
||||
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
|
||||
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) {
|
||||
log := logutil.NewLogger().Named("dav")
|
||||
|
||||
requestPath := path.Clean(r.URL.Path)
|
||||
requestPath = strings.Trim(requestPath, "/")
|
||||
|
||||
if data, exists := cache.Get(requestPath); exists {
|
||||
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
fmt.Fprint(w, data)
|
||||
return
|
||||
}
|
||||
|
||||
var output []byte
|
||||
var err error
|
||||
|
||||
@@ -53,8 +45,6 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
||||
|
||||
if output != nil {
|
||||
respBody := fmt.Sprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n%s\n", output)
|
||||
cache.Add(requestPath, respBody)
|
||||
|
||||
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
fmt.Fprint(w, respBody)
|
||||
|
||||
@@ -15,7 +15,7 @@ func createMultiTorrentResponse(basePath string, torrents []torrent.Torrent) (*d
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, item := range torrents {
|
||||
if item.Progress != 100 {
|
||||
if item.InProgress {
|
||||
continue
|
||||
}
|
||||
if _, exists := seen[item.AccessKey]; exists {
|
||||
@@ -64,7 +64,7 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent) (*
|
||||
torrentResponses = append(torrentResponses, dav.File(
|
||||
filePath,
|
||||
file.Bytes,
|
||||
convertRFC3339toRFC1123(torrent.Added),
|
||||
convertRFC3339toRFC1123(torrent.LatestAdded),
|
||||
file.Link,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user