From 16d1428a52f9ed51d7058b24a0fc20a98641f8f4 Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 15 Sep 2023 15:30:52 -0500 Subject: [PATCH] Display bytes written to response instead of size of files being served in logs --- cmd/root.go | 2 +- cmd/web.go | 10 ++++------ types/code/code.go | 2 +- types/text/text.go | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index fe6fcd3..7344731 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,7 +11,7 @@ import ( ) const ( - ReleaseVersion string = "0.90.1" + ReleaseVersion string = "0.90.3" ) var ( diff --git a/cmd/web.go b/cmd/web.go index 60ec0b4..5d80f64 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -96,9 +96,7 @@ func serveStaticFile(paths []string, cache *fileCache, errorChannel chan<- error return } - w.Write(buf) - - fileSize := humanReadableSize(len(buf)) + written, _ := w.Write(buf) refererUri, err := stripQueryParams(refererToUri(r.Referer())) if err != nil { @@ -124,7 +122,7 @@ func serveStaticFile(paths []string, cache *fileCache, errorChannel chan<- error fmt.Printf("%s | Serve: %s (%s) to %s in %s\n", startTime.Format(logDate), filePath, - fileSize, + humanReadableSize(written), realIP(r), time.Since(startTime).Round(time.Microsecond), ) @@ -296,7 +294,7 @@ func serveMedia(paths []string, regexes *regexes, cache *fileCache, formats *typ formattedPage := gohtml.Format(htmlBody.String()) - _, err = io.WriteString(w, formattedPage) + written, err := io.WriteString(w, formattedPage) if err != nil { errorChannel <- err @@ -310,7 +308,7 @@ func serveMedia(paths []string, regexes *regexes, cache *fileCache, formats *typ fmt.Printf("%s | Serve: %s (%s) to %s in %s\n", startTime.Format(logDate), path, - humanReadableSize(len(formattedPage)), + humanReadableSize(written), realIP(r), time.Since(startTime).Round(time.Microsecond), ) diff --git a/types/code/code.go b/types/code/code.go index dba0412..e40e58c 100644 --- a/types/code/code.go +++ b/types/code/code.go @@ -222,7 +222,7 @@ func (t Format) Validate(filePath string) bool { } func (t Format) Type() string { - return "html" + return "inline" } func New(theme string) Format { diff --git a/types/text/text.go b/types/text/text.go index 0e76c45..24020ad 100644 --- a/types/text/text.go +++ b/types/text/text.go @@ -77,7 +77,7 @@ func (t Format) Validate(filePath string) bool { } func (t Format) Type() string { - return "html" + return "inline" } func New() Format {