Add log when response is generated from scratch
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user