Preserve case of filter query params even without --case-sensitive, include filename in --verbose output for cache import/export
This commit is contained in:
parent
4d8b47a6e3
commit
0e8ac8cdc5
|
@ -109,9 +109,10 @@ func (cache *fileCache) Export(path string) error {
|
|||
cache.mutex.RUnlock()
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | CACHE: Exported %d entries in %s\n",
|
||||
fmt.Printf("%s | CACHE: Exported %d entries to %s in %s\n",
|
||||
time.Now().Format(logDate),
|
||||
length,
|
||||
path,
|
||||
time.Since(startTime),
|
||||
)
|
||||
}
|
||||
|
@ -146,9 +147,10 @@ func (cache *fileCache) Import(path string) error {
|
|||
}
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | CACHE: Imported %d entries in %s\n",
|
||||
fmt.Printf("%s | CACHE: Imported %d entries from %s in %s\n",
|
||||
time.Now().Format(logDate),
|
||||
length,
|
||||
path,
|
||||
time.Since(startTime),
|
||||
)
|
||||
}
|
||||
|
@ -174,7 +176,7 @@ func serveCacheClear(args []string, cache *fileCache, formats *types.Types, erro
|
|||
}
|
||||
|
||||
func registerCacheHandlers(mux *httprouter.Router, args []string, cache *fileCache, formats *types.Types, errorChannel chan<- error) error {
|
||||
register(mux, Prefix+"/clear_cache", serveCacheClear(args, cache, formats, errorChannel))
|
||||
registerHandler(mux, Prefix+"/clear_cache", serveCacheClear(args, cache, formats, errorChannel))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ Poll:
|
|||
}
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | INDEX: %d/%d files across %d/%d directories in %s\n",
|
||||
fmt.Printf("%s | INDEX: Selected %d/%d files across %d/%d directories in %s\n",
|
||||
time.Now().Format(logDate),
|
||||
stats.filesMatched,
|
||||
stats.filesMatched+stats.filesSkipped,
|
||||
|
|
16
cmd/info.go
16
cmd/info.go
|
@ -274,19 +274,19 @@ func serveEnabledMimeTypes(formats *types.Types) httprouter.Handle {
|
|||
|
||||
func registerInfoHandlers(mux *httprouter.Router, args []string, cache *fileCache, formats *types.Types, errorChannel chan<- error) {
|
||||
if Cache {
|
||||
register(mux, Prefix+"/html/", serveIndexHtml(args, cache, false))
|
||||
registerHandler(mux, Prefix+"/html", serveIndexHtml(args, cache, false))
|
||||
if PageLength != 0 {
|
||||
register(mux, Prefix+"/html/:page", serveIndexHtml(args, cache, true))
|
||||
registerHandler(mux, Prefix+"/html/:page", serveIndexHtml(args, cache, true))
|
||||
}
|
||||
|
||||
register(mux, Prefix+"/json", serveIndexJson(args, cache, errorChannel))
|
||||
registerHandler(mux, Prefix+"/json", serveIndexJson(args, cache, errorChannel))
|
||||
if PageLength != 0 {
|
||||
register(mux, Prefix+"/json/:page", serveIndexJson(args, cache, errorChannel))
|
||||
registerHandler(mux, Prefix+"/json/:page", serveIndexJson(args, cache, errorChannel))
|
||||
}
|
||||
}
|
||||
|
||||
register(mux, Prefix+"/available_extensions", serveAvailableExtensions())
|
||||
register(mux, Prefix+"/enabled_extensions", serveEnabledExtensions(formats))
|
||||
register(mux, Prefix+"/available_mime_types", serveAvailableMimeTypes())
|
||||
register(mux, Prefix+"/enabled_mime_types", serveEnabledMimeTypes(formats))
|
||||
registerHandler(mux, Prefix+"/available_extensions", serveAvailableExtensions())
|
||||
registerHandler(mux, Prefix+"/enabled_extensions", serveEnabledExtensions(formats))
|
||||
registerHandler(mux, Prefix+"/available_mime_types", serveAvailableMimeTypes())
|
||||
registerHandler(mux, Prefix+"/enabled_mime_types", serveEnabledMimeTypes(formats))
|
||||
}
|
||||
|
|
|
@ -5,15 +5,29 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func registerProfileHandlers(mux *httprouter.Router) {
|
||||
mux.HandlerFunc("GET", Prefix+"/debug/pprof/", pprof.Index)
|
||||
mux.HandlerFunc("GET", Prefix+"/debug/pprof/cmdline", pprof.Cmdline)
|
||||
mux.HandlerFunc("GET", Prefix+"/debug/pprof/profile", pprof.Profile)
|
||||
mux.HandlerFunc("GET", Prefix+"/debug/pprof/symbol", pprof.Symbol)
|
||||
mux.HandlerFunc("GET", Prefix+"/debug/pprof/trace", pprof.Trace)
|
||||
func registerProfileHandler(mux *httprouter.Router, verb, path string, handler http.HandlerFunc) {
|
||||
mux.HandlerFunc(verb, path, handler)
|
||||
|
||||
if Handlers {
|
||||
fmt.Printf("%s | SERVE: Registered handler for %s\n",
|
||||
time.Now().Format(logDate),
|
||||
path,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func registerProfileHandlers(mux *httprouter.Router) {
|
||||
registerProfileHandler(mux, "GET", Prefix+"/debug/pprof/", pprof.Index)
|
||||
registerProfileHandler(mux, "GET", Prefix+"/debug/pprof/cmdline", pprof.Cmdline)
|
||||
registerProfileHandler(mux, "GET", Prefix+"/debug/pprof/profile", pprof.Profile)
|
||||
registerProfileHandler(mux, "GET", Prefix+"/debug/pprof/symbol", pprof.Symbol)
|
||||
registerProfileHandler(mux, "GET", Prefix+"/debug/pprof/trace", pprof.Trace)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ReleaseVersion string = "1.0.1"
|
||||
ReleaseVersion string = "1.1.0"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -47,12 +47,7 @@ func splitQueryParams(query string, regexes *regexes) []string {
|
|||
params := strings.Split(query, ",")
|
||||
|
||||
for i := 0; i < len(params); i++ {
|
||||
switch {
|
||||
case regexes.alphanumeric.MatchString(params[i]) && CaseSensitive:
|
||||
results = append(results, params[i])
|
||||
case regexes.alphanumeric.MatchString(params[i]):
|
||||
results = append(results, strings.ToLower(params[i]))
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
|
|
64
cmd/web.go
64
cmd/web.go
|
@ -362,11 +362,14 @@ func serveVersion() httprouter.Handle {
|
|||
}
|
||||
}
|
||||
|
||||
func register(mux *httprouter.Router, path string, handle httprouter.Handle) {
|
||||
func registerHandler(mux *httprouter.Router, path string, handle httprouter.Handle) {
|
||||
mux.GET(path, handle)
|
||||
|
||||
if Handlers {
|
||||
fmt.Printf("Registered handler for path %s\n", path)
|
||||
fmt.Printf("%s | SERVE: Registered handler for %s\n",
|
||||
time.Now().Format(logDate),
|
||||
path,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -440,30 +443,22 @@ func ServePage(args []string) error {
|
|||
return ErrNoMediaFound
|
||||
}
|
||||
|
||||
listenHost := net.JoinHostPort(Bind, strconv.Itoa(Port))
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: Listening on %s\n",
|
||||
time.Now().Format(logDate),
|
||||
listenHost,
|
||||
)
|
||||
regexes := ®exes{
|
||||
filename: regexp.MustCompile(`(.+?)([0-9]*)(\..+)`),
|
||||
alphanumeric: regexp.MustCompile(`^[A-z0-9]*$`),
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(Prefix, "/") {
|
||||
Prefix = Prefix + "/"
|
||||
}
|
||||
|
||||
listenHost := net.JoinHostPort(Bind, strconv.Itoa(Port))
|
||||
|
||||
cache := &fileCache{
|
||||
mutex: sync.RWMutex{},
|
||||
list: []string{},
|
||||
}
|
||||
|
||||
err = importCache(paths, cache, formats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
regexes := ®exes{
|
||||
filename: regexp.MustCompile(`(.+?)([0-9]*)(\..+)`),
|
||||
alphanumeric: regexp.MustCompile(`^[A-z0-9]*$`),
|
||||
}
|
||||
|
||||
mux := httprouter.New()
|
||||
|
||||
srv := &http.Server{
|
||||
|
@ -476,29 +471,25 @@ func ServePage(args []string) error {
|
|||
|
||||
mux.PanicHandler = serverErrorHandler()
|
||||
|
||||
if !strings.HasSuffix(Prefix, "/") {
|
||||
Prefix = Prefix + "/"
|
||||
}
|
||||
|
||||
errorChannel := make(chan error)
|
||||
|
||||
register(mux, Prefix, serveRoot(paths, regexes, cache, formats, errorChannel))
|
||||
registerHandler(mux, Prefix, serveRoot(paths, regexes, cache, formats, errorChannel))
|
||||
|
||||
Prefix = strings.TrimSuffix(Prefix, "/")
|
||||
|
||||
if Prefix != "" {
|
||||
register(mux, "/", redirectRoot())
|
||||
registerHandler(mux, "/", redirectRoot())
|
||||
}
|
||||
|
||||
register(mux, Prefix+"/favicons/*favicon", serveFavicons())
|
||||
registerHandler(mux, Prefix+"/favicons/*favicon", serveFavicons())
|
||||
|
||||
register(mux, Prefix+"/favicon.ico", serveFavicons())
|
||||
registerHandler(mux, Prefix+"/favicon.ico", serveFavicons())
|
||||
|
||||
register(mux, Prefix+mediaPrefix+"/*media", serveMedia(paths, regexes, cache, formats, errorChannel))
|
||||
registerHandler(mux, Prefix+mediaPrefix+"/*media", serveMedia(paths, regexes, cache, formats, errorChannel))
|
||||
|
||||
register(mux, Prefix+sourcePrefix+"/*static", serveStaticFile(paths, cache, errorChannel))
|
||||
registerHandler(mux, Prefix+sourcePrefix+"/*static", serveStaticFile(paths, cache, errorChannel))
|
||||
|
||||
register(mux, Prefix+"/version", serveVersion())
|
||||
registerHandler(mux, Prefix+"/version", serveVersion())
|
||||
|
||||
if Cache {
|
||||
err = registerCacheHandlers(mux, args, cache, formats, errorChannel)
|
||||
|
@ -519,6 +510,11 @@ func ServePage(args []string) error {
|
|||
fmt.Printf("WARNING! Files *will* be deleted after serving!\n\n")
|
||||
}
|
||||
|
||||
err = importCache(paths, cache, formats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for err := range errorChannel {
|
||||
fmt.Printf("%s | ERROR: %v\n", time.Now().Format(logDate), err)
|
||||
|
@ -531,6 +527,14 @@ func ServePage(args []string) error {
|
|||
}
|
||||
}()
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: Listening on http://%s%s/\n",
|
||||
time.Now().Format(logDate),
|
||||
listenHost,
|
||||
Prefix,
|
||||
)
|
||||
}
|
||||
|
||||
err = srv.ListenAndServe()
|
||||
if !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue