Fix filenames on webdav issue
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -79,12 +78,9 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) ([]byte
|
|||||||
}
|
}
|
||||||
var responses []dav.Response
|
var responses []dav.Response
|
||||||
// initial response is the directory itself
|
// initial response is the directory itself
|
||||||
responses = append(responses, dav.Directory(basePath))
|
responses = append(responses, dav.Directory(basePath+"/"))
|
||||||
|
|
||||||
var accessKeys []string
|
accessKeys := torrents.Keys()
|
||||||
torrents.IterCb(func(accessKey string, _ *torrent.Torrent) {
|
|
||||||
accessKeys = append(accessKeys, accessKey)
|
|
||||||
})
|
|
||||||
sort.Strings(accessKeys)
|
sort.Strings(accessKeys)
|
||||||
for _, accessKey := range accessKeys {
|
for _, accessKey := range accessKeys {
|
||||||
responses = append(responses, dav.Directory(filepath.Join(basePath, accessKey)))
|
responses = append(responses, dav.Directory(filepath.Join(basePath, accessKey)))
|
||||||
@@ -111,23 +107,18 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) ([]byte,
|
|||||||
|
|
||||||
var responses []dav.Response
|
var responses []dav.Response
|
||||||
// initial response is the directory itself
|
// initial response is the directory itself
|
||||||
responses = append(responses, dav.Directory(requestPath))
|
responses = append(responses, dav.Directory(requestPath+"/"))
|
||||||
|
filenames := tor.SelectedFiles.Keys()
|
||||||
tor.SelectedFiles.IterCb(func(filename string, file *torrent.File) {
|
sort.Strings(filenames)
|
||||||
if file.Link == "" {
|
for _, filename := range filenames {
|
||||||
// will be caught by torrent manager's repairAll
|
file, _ := tor.SelectedFiles.Get(filename)
|
||||||
// just skip it for now
|
|
||||||
return
|
|
||||||
}
|
|
||||||
filePath := filepath.Join(requestPath, url.PathEscape(filename))
|
|
||||||
responses = append(responses, dav.File(
|
responses = append(responses, dav.File(
|
||||||
filePath,
|
filepath.Join(requestPath, filename),
|
||||||
file.Bytes,
|
file.Bytes,
|
||||||
convertRFC3339toRFC1123(tor.LatestAdded),
|
convertRFC3339toRFC1123(tor.LatestAdded),
|
||||||
file.Link,
|
file.Link,
|
||||||
))
|
))
|
||||||
})
|
}
|
||||||
|
|
||||||
resp := &dav.MultiStatus{
|
resp := &dav.MultiStatus{
|
||||||
XMLNS: "DAV:",
|
XMLNS: "DAV:",
|
||||||
Response: responses,
|
Response: responses,
|
||||||
|
|||||||
@@ -71,16 +71,11 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
htmlDoc := "<ol>"
|
htmlDoc := "<ol>"
|
||||||
|
accessKeys := torrents.Keys()
|
||||||
var accessKeys []string
|
|
||||||
torrents.IterCb(func(accessKey string, _ *torrent.Torrent) {
|
|
||||||
accessKeys = append(accessKeys, accessKey)
|
|
||||||
})
|
|
||||||
sort.Strings(accessKeys)
|
sort.Strings(accessKeys)
|
||||||
for _, accessKey := range accessKeys {
|
for _, accessKey := range accessKeys {
|
||||||
htmlDoc = htmlDoc + fmt.Sprintf("<li><a href=\"%s/\">%s</a></li>", filepath.Join(requestPath, url.PathEscape(accessKey)), accessKey)
|
htmlDoc = htmlDoc + fmt.Sprintf("<li><a href=\"%s/\">%s</a></li>", filepath.Join(requestPath, url.PathEscape(accessKey)), accessKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &htmlDoc, nil
|
return &htmlDoc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,16 +92,17 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string
|
|||||||
}
|
}
|
||||||
|
|
||||||
htmlDoc := "<ol>"
|
htmlDoc := "<ol>"
|
||||||
|
filenames := tor.SelectedFiles.Keys()
|
||||||
tor.SelectedFiles.IterCb(func(filename string, file *torrent.File) {
|
sort.Strings(filenames)
|
||||||
|
for _, filename := range filenames {
|
||||||
|
file, _ := tor.SelectedFiles.Get(filename)
|
||||||
if file.Link == "" {
|
if file.Link == "" {
|
||||||
// will be caught by torrent manager's repairAll
|
// will be caught by torrent manager's repairAll
|
||||||
// just skip it for now
|
// just skip it for now
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
filePath := filepath.Join(requestPath, url.PathEscape(filename))
|
filePath := filepath.Join(requestPath, url.PathEscape(filename))
|
||||||
htmlDoc += fmt.Sprintf("<li><a href=\"%s\">%s</a></li>", filePath, filename)
|
htmlDoc += fmt.Sprintf("<li><a href=\"%s\">%s</a></li>", filePath, filename)
|
||||||
})
|
}
|
||||||
|
|
||||||
return &htmlDoc, nil
|
return &htmlDoc, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ type TorrentManager struct {
|
|||||||
checksum string
|
checksum string
|
||||||
api *realdebrid.RealDebrid
|
api *realdebrid.RealDebrid
|
||||||
workerPool chan bool
|
workerPool chan bool
|
||||||
mu *sync.Mutex
|
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid) *
|
|||||||
requiredVersion: "10.11.2023",
|
requiredVersion: "10.11.2023",
|
||||||
api: api,
|
api: api,
|
||||||
workerPool: make(chan bool, cfg.GetNumOfWorkers()),
|
workerPool: make(chan bool, cfg.GetNumOfWorkers()),
|
||||||
mu: &sync.Mutex{},
|
|
||||||
log: logutil.NewLogger().Named("manager"),
|
log: logutil.NewLogger().Named("manager"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,11 +97,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get filenames
|
// get filenames
|
||||||
var filenames []string
|
filenames := torrent.SelectedFiles.Keys()
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
|
||||||
filenames = append(filenames, file.Path)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Map torrents to directories
|
// Map torrents to directories
|
||||||
switch t.cfg.GetVersion() {
|
switch t.cfg.GetVersion() {
|
||||||
case "v1":
|
case "v1":
|
||||||
|
|||||||
Reference in New Issue
Block a user