Updated transitive dependencies

This commit is contained in:
Seednode 2024-01-31 11:30:37 -06:00
parent 34cc53338f
commit cd9443a64b
5 changed files with 29 additions and 31 deletions

View File

@ -26,9 +26,16 @@ var (
) )
func notFound(w http.ResponseWriter, r *http.Request, path string) error { 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.WriteHeader(http.StatusNotFound)
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
nonce := types.GetNonce() nonce := types.GetNonce()
@ -40,19 +47,16 @@ func notFound(w http.ResponseWriter, r *http.Request, path string) error {
return err return err
} }
if Verbose {
fmt.Printf("%s | ERROR: Unavailable file %s requested by %s\n",
startTime.Format(logDate),
path,
r.RemoteAddr,
)
}
return nil return nil
} }
func serverError(w http.ResponseWriter, r *http.Request, i interface{}) { 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") 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))) 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{}) { func serverErrorHandler() func(http.ResponseWriter, *http.Request, interface{}) {

View File

@ -522,7 +522,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
return nil, err return nil, err
} }
pathMatches := (args[i] == path) pathMatches := args[i] == path
hasSupportedFiles, err := hasSupportedFiles(path, formats) hasSupportedFiles, err := hasSupportedFiles(path, formats)
if err != nil { if err != nil {

View File

@ -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() 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 != "" { if IndexFile != "" {
index.Import(IndexFile, errorChannel) 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) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
startTime := time.Now() 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) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
if Verbose { if Verbose {
fmt.Printf("%s | SERVE: Index rebuild requested by %s\n", 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") 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")) _, err := w.Write([]byte("Ok\n"))
if err != nil { 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) interval, err := time.ParseDuration(IndexInterval)
if err != nil { if err != nil {
errorChannel <- err 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)) 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: case <-quit:
ticker.Stop() ticker.Stop()

View File

@ -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 { if Index {
mux.GET(Prefix+AdminPrefix+"/index", serveIndex(args, index, errorChannel)) mux.GET(Prefix+AdminPrefix+"/index", serveIndex(index, errorChannel))
mux.POST(Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(args, index, formats, encoder, errorChannel)) mux.POST(Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(paths, index, formats, encoder, errorChannel))
} }
mux.GET(Prefix+AdminPrefix+"/extensions/available", serveExtensions(formats, true, errorChannel)) mux.GET(Prefix+AdminPrefix+"/extensions/available", serveExtensions(formats, true, errorChannel))

View File

@ -594,14 +594,14 @@ func ServePage(args []string) error {
defer close(quit) defer close(quit)
if API { if API {
registerAPIHandlers(mux, args, index, formats, encoder, errorChannel) registerAPIHandlers(mux, paths, index, formats, encoder, errorChannel)
} }
if Index { if Index {
importIndex(paths, index, formats, encoder, errorChannel) importIndex(paths, index, formats, encoder, errorChannel)
if IndexInterval != "" { if IndexInterval != "" {
registerIndexInterval(args, index, formats, encoder, quit, errorChannel) registerIndexInterval(paths, index, formats, encoder, quit, errorChannel)
} }
} }