Add log when response is generated from scratch

This commit is contained in:
Ben Sarmiento
2023-11-30 03:38:57 +01:00
parent 5914af80fd
commit c6e4a304bf
3 changed files with 20 additions and 14 deletions

View File

@@ -24,9 +24,9 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T
case len(filteredSegments) == 1:
output, err = handleRoot(t)
case len(filteredSegments) == 2:
output, err = handleListOfTorrents(requestPath, t)
output, err = handleListOfTorrents(requestPath, t, log)
case len(filteredSegments) == 3:
output, err = handleSingleTorrent(requestPath, t)
output, err = handleSingleTorrent(requestPath, t, log)
default:
log.Warnf("Request %s %s not found", r.Method, requestPath)
http.Error(w, "Not Found", http.StatusNotFound)
@@ -64,7 +64,7 @@ func handleRoot(t *torrent.TorrentManager) (*string, error) {
return &htmlDoc, nil
}
func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*string, error) {
func handleListOfTorrents(requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
directory := path.Base(requestPath)
torrents, ok := t.DirectoryMap.Get(directory)
if !ok {
@@ -72,6 +72,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
}
if resp, ok := t.ResponseCache.Get(directory + ".html"); !ok {
log.Debugf("Generating html for directory %s", directory)
htmlDoc := "<ol>"
var allTorrents []*torrent.Torrent
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
@@ -93,7 +94,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
}
}
func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string, error) {
func handleSingleTorrent(requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
directory := path.Base(path.Dir(requestPath))
torrents, ok := t.DirectoryMap.Get(directory)
if !ok {
@@ -106,6 +107,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string
}
if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".html"); !ok {
log.Debugf("Generating html for torrent %s", accessKey)
htmlDoc := "<ol>"
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)