Clean up
This commit is contained in:
@@ -51,32 +51,32 @@ func handleRoot(w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
||||
|
||||
// handleListOfTorrents handles a PROPFIND request to the /torrents directory
|
||||
func handleListOfTorrents(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
||||
allTorrents := t.GetAll()
|
||||
allTorrentsResponse, err := createMultiTorrentResponse(allTorrents)
|
||||
torrents := t.GetAll()
|
||||
resp, err := createMultiTorrentResponse(torrents)
|
||||
if err != nil {
|
||||
log.Printf("Cannot read directory (/torrents): %v\n", err.Error())
|
||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||
return nil, nil
|
||||
}
|
||||
return xml.MarshalIndent(allTorrentsResponse, "", " ")
|
||||
return xml.MarshalIndent(resp, "", " ")
|
||||
}
|
||||
|
||||
// handleSingleTorrent handles a PROPFIND request to a single torrent directory
|
||||
func handleSingleTorrent(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
||||
requestPath := path.Clean(r.URL.Path)
|
||||
torrentName := path.Base(requestPath)
|
||||
foundTorrents := findAllTorrentsWithName(t, torrentName)
|
||||
if len(foundTorrents) == 0 {
|
||||
torrents := findAllTorrentsWithName(t, torrentName)
|
||||
if len(torrents) == 0 {
|
||||
log.Println("Cannot find directory", requestPath)
|
||||
http.Error(w, "Cannot find directory", http.StatusNotFound)
|
||||
return nil, nil
|
||||
}
|
||||
var torrentResponse *dav.MultiStatus
|
||||
torrentResponse, err := createCombinedTorrentResponse(foundTorrents, t)
|
||||
var resp *dav.MultiStatus
|
||||
resp, err := createCombinedTorrentResponse(torrents, t)
|
||||
if err != nil {
|
||||
log.Printf("Cannot read directory (%s): %v\n", requestPath, err.Error())
|
||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||
return nil, nil
|
||||
}
|
||||
return xml.MarshalIndent(torrentResponse, "", " ")
|
||||
return xml.MarshalIndent(resp, "", " ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user