From cd9443a64b523f0b598f7562410ed1232b0f23be Mon Sep 17 00:00:00 2001 From: Seednode Date: Wed, 31 Jan 2024 11:30:37 -0600 Subject: [PATCH] Updated transitive dependencies --- cmd/errors.go | 30 ++++++++++++++---------------- cmd/files.go | 2 +- cmd/index.go | 18 +++++++++--------- cmd/info.go | 6 +++--- cmd/web.go | 4 ++-- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/cmd/errors.go b/cmd/errors.go index 336bdcf..acebfc5 100644 --- a/cmd/errors.go +++ b/cmd/errors.go @@ -26,9 +26,16 @@ var ( ) func notFound(w http.ResponseWriter, r *http.Request, path string) error { - startTime := time.Now() + if Verbose { + fmt.Printf("%s | ERROR: Unavailable file %s requested by %s\n", + time.Now().Format(logDate), + path, + r.RemoteAddr, + ) + } w.WriteHeader(http.StatusNotFound) + w.Header().Add("Content-Type", "text/html") nonce := types.GetNonce() @@ -40,19 +47,16 @@ func notFound(w http.ResponseWriter, r *http.Request, path string) error { return err } - if Verbose { - fmt.Printf("%s | ERROR: Unavailable file %s requested by %s\n", - startTime.Format(logDate), - path, - r.RemoteAddr, - ) - } - return nil } func serverError(w http.ResponseWriter, r *http.Request, i interface{}) { - startTime := time.Now() + if Verbose { + fmt.Printf("%s | ERROR: Invalid request for %s from %s\n", + time.Now().Format(logDate), + r.URL.Path, + r.RemoteAddr) + } w.Header().Add("Content-Type", "text/html") @@ -62,12 +66,6 @@ func serverError(w http.ResponseWriter, r *http.Request, i interface{}) { io.WriteString(w, gohtml.Format(newPage("Server Error", "An error has occurred. Please try again.", nonce))) - if Verbose { - fmt.Printf("%s | ERROR: Invalid request for %s from %s\n", - startTime.Format(logDate), - r.URL.Path, - r.RemoteAddr) - } } func serverErrorHandler() func(http.ResponseWriter, *http.Request, interface{}) { diff --git a/cmd/files.go b/cmd/files.go index 3181609..d8e30a4 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -522,7 +522,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) { return nil, err } - pathMatches := (args[i] == path) + pathMatches := args[i] == path hasSupportedFiles, err := hasSupportedFiles(path, formats) if err != nil { diff --git a/cmd/index.go b/cmd/index.go index e7083fa..412d4d5 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -191,21 +191,21 @@ func (index *fileIndex) Import(path string, errorChannel chan<- error) { } } -func rebuildIndex(args []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { +func rebuildIndex(paths []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { index.clear() - fileList(args, &filters{}, "", index, formats, encoder, errorChannel) + fileList(paths, &filters{}, "", index, formats, encoder, errorChannel) } -func importIndex(args []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { +func importIndex(paths []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { if IndexFile != "" { index.Import(IndexFile, errorChannel) } - fileList(args, &filters{}, "", index, formats, encoder, errorChannel) + fileList(paths, &filters{}, "", index, formats, encoder, errorChannel) } -func serveIndex(args []string, index *fileIndex, errorChannel chan<- error) httprouter.Handle { +func serveIndex(index *fileIndex, errorChannel chan<- error) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { startTime := time.Now() @@ -246,7 +246,7 @@ func serveIndex(args []string, index *fileIndex, errorChannel chan<- error) http } } -func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) httprouter.Handle { +func serveIndexRebuild(paths []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { if Verbose { fmt.Printf("%s | SERVE: Index rebuild requested by %s\n", @@ -258,7 +258,7 @@ func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, enc w.Header().Set("Content-Type", "text/plain;charset=UTF-8") - rebuildIndex(args, index, formats, encoder, errorChannel) + rebuildIndex(paths, index, formats, encoder, errorChannel) _, err := w.Write([]byte("Ok\n")) if err != nil { @@ -269,7 +269,7 @@ func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, enc } } -func registerIndexInterval(args []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, quit <-chan struct{}, errorChannel chan<- error) { +func registerIndexInterval(paths []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, quit <-chan struct{}, errorChannel chan<- error) { interval, err := time.ParseDuration(IndexInterval) if err != nil { errorChannel <- err @@ -287,7 +287,7 @@ func registerIndexInterval(args []string, index *fileIndex, formats types.Types, fmt.Printf("%s | INDEX: Started scheduled index rebuild\n", time.Now().Format(logDate)) } - rebuildIndex(args, index, formats, encoder, errorChannel) + rebuildIndex(paths, index, formats, encoder, errorChannel) case <-quit: ticker.Stop() diff --git a/cmd/info.go b/cmd/info.go index 14bb75d..426f295 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -76,10 +76,10 @@ func serveMediaTypes(formats types.Types, available bool, errorChannel chan<- er } } -func registerAPIHandlers(mux *httprouter.Router, args []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { +func registerAPIHandlers(mux *httprouter.Router, paths []string, index *fileIndex, formats types.Types, encoder *zstd.Encoder, errorChannel chan<- error) { if Index { - mux.GET(Prefix+AdminPrefix+"/index", serveIndex(args, index, errorChannel)) - mux.POST(Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(args, index, formats, encoder, errorChannel)) + mux.GET(Prefix+AdminPrefix+"/index", serveIndex(index, errorChannel)) + mux.POST(Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(paths, index, formats, encoder, errorChannel)) } mux.GET(Prefix+AdminPrefix+"/extensions/available", serveExtensions(formats, true, errorChannel)) diff --git a/cmd/web.go b/cmd/web.go index 8fd16e3..706e85f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -594,14 +594,14 @@ func ServePage(args []string) error { defer close(quit) if API { - registerAPIHandlers(mux, args, index, formats, encoder, errorChannel) + registerAPIHandlers(mux, paths, index, formats, encoder, errorChannel) } if Index { importIndex(paths, index, formats, encoder, errorChannel) if IndexInterval != "" { - registerIndexInterval(args, index, formats, encoder, quit, errorChannel) + registerIndexInterval(paths, index, formats, encoder, quit, errorChannel) } }