Fix filenames on webdav issue
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -79,12 +78,9 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) ([]byte
|
||||
}
|
||||
var responses []dav.Response
|
||||
// initial response is the directory itself
|
||||
responses = append(responses, dav.Directory(basePath))
|
||||
responses = append(responses, dav.Directory(basePath+"/"))
|
||||
|
||||
var accessKeys []string
|
||||
torrents.IterCb(func(accessKey string, _ *torrent.Torrent) {
|
||||
accessKeys = append(accessKeys, accessKey)
|
||||
})
|
||||
accessKeys := torrents.Keys()
|
||||
sort.Strings(accessKeys)
|
||||
for _, accessKey := range accessKeys {
|
||||
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
|
||||
// initial response is the directory itself
|
||||
responses = append(responses, dav.Directory(requestPath))
|
||||
|
||||
tor.SelectedFiles.IterCb(func(filename string, file *torrent.File) {
|
||||
if file.Link == "" {
|
||||
// will be caught by torrent manager's repairAll
|
||||
// just skip it for now
|
||||
return
|
||||
}
|
||||
filePath := filepath.Join(requestPath, url.PathEscape(filename))
|
||||
responses = append(responses, dav.Directory(requestPath+"/"))
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
sort.Strings(filenames)
|
||||
for _, filename := range filenames {
|
||||
file, _ := tor.SelectedFiles.Get(filename)
|
||||
responses = append(responses, dav.File(
|
||||
filePath,
|
||||
filepath.Join(requestPath, filename),
|
||||
file.Bytes,
|
||||
convertRFC3339toRFC1123(tor.LatestAdded),
|
||||
file.Link,
|
||||
))
|
||||
})
|
||||
|
||||
}
|
||||
resp := &dav.MultiStatus{
|
||||
XMLNS: "DAV:",
|
||||
Response: responses,
|
||||
|
||||
Reference in New Issue
Block a user