diff --git a/internal/dav/listing.go b/internal/dav/listing.go
index 156856d..9713c26 100644
--- a/internal/dav/listing.go
+++ b/internal/dav/listing.go
@@ -13,18 +13,19 @@ import (
)
func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
- davDoc := ""
- davDoc += dav.BaseDirectory("", "")
+ var buf bytes.Buffer
+ buf.WriteString("")
+ buf.WriteString(dav.BaseDirectory("", ""))
directories := torMgr.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
if strings.HasPrefix(directory, "int__") {
continue
}
- davDoc += dav.Directory(directory, "")
+ buf.WriteString(dav.Directory(directory, ""))
}
- davDoc += ""
- return []byte(davDoc), nil
+ buf.WriteString("")
+ return buf.Bytes(), nil
}
func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
diff --git a/internal/http/listing.go b/internal/http/listing.go
index ed671c8..df21f04 100644
--- a/internal/http/listing.go
+++ b/internal/http/listing.go
@@ -1,6 +1,7 @@
package http
import (
+ "bytes"
"fmt"
"net/url"
"path/filepath"
@@ -12,8 +13,9 @@ import (
"github.com/debridmediamanager/zurg/pkg/logutil"
)
-func HandleListDirectories(torMgr *torrent.TorrentManager) (*string, error) {
- htmlDoc := "
"
+func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
+ var buf bytes.Buffer
+ buf.WriteString("")
directories := torMgr.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
@@ -21,19 +23,20 @@ func HandleListDirectories(torMgr *torrent.TorrentManager) (*string, error) {
continue
}
directoryPath := url.PathEscape(directory)
- htmlDoc += fmt.Sprintf("- %s
", directoryPath, directory)
+ buf.WriteString(fmt.Sprintf("- %s
", directoryPath, directory))
}
- return &htmlDoc, nil
+ return buf.Bytes(), nil
}
-func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) (*string, error) {
+func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory)
}
- htmlDoc := ""
+ var buf bytes.Buffer
+ buf.WriteString("")
var allTorrents []*torrent.Torrent
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
if tor.AllInProgress() {
@@ -45,12 +48,12 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
return allTorrents[i].AccessKey < allTorrents[j].AccessKey
})
for _, tor := range allTorrents {
- htmlDoc = htmlDoc + fmt.Sprintf("- %s
", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey)
+ buf.WriteString(fmt.Sprintf("- %s
", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey))
}
- return &htmlDoc, nil
+ return buf.Bytes(), nil
}
-func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) (*string, error) {
+func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory)
@@ -66,7 +69,8 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
biggestFileSize = tor.ComputeBiggestFileSize()
}
- htmlDoc := ""
+ var buf bytes.Buffer
+ buf.WriteString("")
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)
for _, filename := range filenames {
@@ -78,7 +82,7 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
continue
}
filePath := filepath.Join(directory, torrentName, url.PathEscape(filename))
- htmlDoc += fmt.Sprintf("- %s
", filePath, filename)
+ buf.WriteString(fmt.Sprintf("- %s
", filePath, filename))
}
- return &htmlDoc, nil
+ return buf.Bytes(), nil
}
diff --git a/internal/router/router.go b/internal/router/router.go
index c030645..478848c 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -89,7 +89,7 @@ func (zr *ZurgRouter) httpTorrentDirectoryHandler(resp http.ResponseWriter, req
}
resp.Header().Set("Content-Type", "text/html; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
- fmt.Fprint(resp, *out)
+ resp.Write(out)
}
func (zr *ZurgRouter) httpDirectoryHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
@@ -101,7 +101,7 @@ func (zr *ZurgRouter) httpDirectoryHandler(resp http.ResponseWriter, req *http.R
}
resp.Header().Set("Content-Type", "text/html; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
- fmt.Fprint(resp, *out)
+ resp.Write(out)
}
func (zr *ZurgRouter) httpRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
@@ -112,7 +112,7 @@ func (zr *ZurgRouter) httpRootHandler(resp http.ResponseWriter, req *http.Reques
}
resp.Header().Set("Content-Type", "text/html; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
- fmt.Fprint(resp, *out)
+ resp.Write(out)
}
func (zr *ZurgRouter) propfindFileHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {