Add log when response is generated from scratch
This commit is contained in:
@@ -24,9 +24,9 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
||||
case len(filteredSegments) == 0:
|
||||
output, err = handleListDirectories(w, t)
|
||||
case len(filteredSegments) == 1:
|
||||
output, err = handleListTorrents(w, requestPath, t)
|
||||
output, err = handleListTorrents(w, requestPath, t, log)
|
||||
case len(filteredSegments) == 2:
|
||||
output, err = handleListFiles(w, requestPath, t)
|
||||
output, err = handleListFiles(w, requestPath, t, log)
|
||||
default:
|
||||
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
||||
http.Error(w, "Not Found", http.StatusNotFound)
|
||||
@@ -68,14 +68,15 @@ func handleListDirectories(w http.ResponseWriter, t *torrent.TorrentManager) (*s
|
||||
return &davDoc, nil
|
||||
}
|
||||
|
||||
func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) (*string, error) {
|
||||
basePath := path.Base(requestPath)
|
||||
_, ok := t.DirectoryMap.Get(basePath)
|
||||
func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
directory := path.Base(requestPath)
|
||||
_, ok := t.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", basePath)
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
}
|
||||
|
||||
if resp, ok := t.ResponseCache.Get(basePath + ".dav"); !ok {
|
||||
if resp, ok := t.ResponseCache.Get(directory + ".dav"); !ok {
|
||||
log.Debugf("Generating xml for directory %s", directory)
|
||||
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
|
||||
davDoc += dav.Directory("", "")
|
||||
directories := t.DirectoryMap.Keys()
|
||||
@@ -91,7 +92,7 @@ func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.To
|
||||
}
|
||||
}
|
||||
|
||||
func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) (*string, error) {
|
||||
func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
directory := path.Base(path.Dir(requestPath))
|
||||
torrents, ok := t.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
@@ -104,6 +105,7 @@ func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.Torre
|
||||
}
|
||||
|
||||
if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".dav"); !ok {
|
||||
log.Debugf("Generating xml for torrent %s", accessKey)
|
||||
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded)
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
sort.Strings(filenames)
|
||||
|
||||
Reference in New Issue
Block a user