Remove --handlers, remove all logging unless --verbose is passed

This commit is contained in:
Seednode 2024-01-15 09:28:59 -06:00
parent 61060f7895
commit 76456f586d
5 changed files with 48 additions and 62 deletions

View File

@ -63,7 +63,7 @@ Both filtering parameters ignore the file extension and full path; they only com
If the `--ignore` flag is passed, any directory containing a file named `.roulette-ignore` (configurable with `--ignore-file`) will be skipped during the scanning stage.
## Indexing
If the `-i|--indexing` flag is passed, all specified paths will be indexed on start.
If the `-i|--index` flag is passed, all specified paths will be indexed on start.
This will slightly increase the delay before the application begins responding to requests, but should significantly speed up subsequent requests.
@ -80,11 +80,9 @@ Supported formats are `none`, `zlib`, and `zstd`.
Optionally, `--compression-fast` can be used to use the fastest instead of the best compression mode.
## Info
If the `-i|--info` flag is passed, six additional endpoints are registered.
If the `-i|--info` flag is passed, five additional endpoints are registered.
The first of these—`/index/html` and `/index/json`—return the contents of the index, in HTML and JSON formats respectively.
If `--page-length` is also set, these can be viewed in paginated form by appending a page number, e.g. `/index/html/5` for the fifth page.
The first of these—`/index/`—returns the contents of the index, in JSON format.
This can prove useful when confirming whether the index is generated successfully, or whether a given file is in the index.
@ -165,7 +163,6 @@ Flags:
-f, --filter enable filtering
--flash enable support for shockwave flash files (via ruffle.rs)
--fun add a bit of excitement to your day
--handlers display registered handlers (for debugging)
-h, --help help for roulette
--ignore skip all directories containing a specified filename
--ignore-file string filename used to indicate directory to be skipped (default ".roulette-ignore")

View File

@ -539,26 +539,33 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
switch {
case pathMatches && hasSupportedFiles:
if Verbose {
fmt.Printf("%s | PATHS: Added %s\n",
time.Now().Format(logDate),
args[i],
)
}
paths = append(paths, path)
case !pathMatches && hasSupportedFiles:
if Verbose {
fmt.Printf("%s | PATHS: Added %s [resolved to %s]\n",
time.Now().Format(logDate),
args[i],
path,
)
}
paths = append(paths, path)
case pathMatches && !hasSupportedFiles:
if Verbose {
fmt.Printf("%s | PATHS: Skipped %s (No supported files found)\n",
time.Now().Format(logDate),
args[i],
)
}
case !pathMatches && !hasSupportedFiles:
if Verbose {
fmt.Printf("%s | PATHS: Skipped %s [resolved to %s] (No supported files found)\n",
time.Now().Format(logDate),
args[i],
@ -566,6 +573,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
)
}
}
}
return paths, nil
}

View File

@ -117,11 +117,11 @@ func serveMediaTypes(formats types.Types, available bool, errorChannel chan<- er
func registerInfoHandlers(mux *httprouter.Router, args []string, index *fileIndex, formats types.Types, errorChannel chan<- error) {
if Index {
registerHandler(mux, Prefix+AdminPrefix+"/index", serveIndex(args, index, errorChannel))
mux.GET(Prefix+AdminPrefix+"/index", serveIndex(args, index, errorChannel))
}
registerHandler(mux, Prefix+AdminPrefix+"/extensions/available", serveExtensions(formats, true, errorChannel))
registerHandler(mux, Prefix+AdminPrefix+"/extensions/enabled", serveExtensions(formats, false, errorChannel))
registerHandler(mux, Prefix+AdminPrefix+"/types/available", serveMediaTypes(formats, true, errorChannel))
registerHandler(mux, Prefix+AdminPrefix+"/types/enabled", serveMediaTypes(formats, false, errorChannel))
mux.GET(Prefix+AdminPrefix+"/extensions/available", serveExtensions(formats, true, errorChannel))
mux.GET(Prefix+AdminPrefix+"/extensions/enabled", serveExtensions(formats, false, errorChannel))
mux.GET(Prefix+AdminPrefix+"/types/available", serveMediaTypes(formats, true, errorChannel))
mux.GET(Prefix+AdminPrefix+"/types/enabled", serveMediaTypes(formats, false, errorChannel))
}

View File

@ -17,7 +17,7 @@ import (
const (
AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "6.0.0"
ReleaseVersion string = "6.1.0"
)
var (
@ -38,7 +38,6 @@ var (
Filtering bool
Flash bool
Fun bool
Handlers bool
Ignore bool
IgnoreFile string
Images bool
@ -51,7 +50,6 @@ var (
Prefix string
Profile bool
Recursive bool
Redact bool
Refresh bool
Russian bool
Sorting bool
@ -133,9 +131,8 @@ func init() {
rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering")
rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
rootCmd.Flags().BoolVar(&Fun, "fun", false, "add a bit of excitement to your day")
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")
rootCmd.Flags().BoolVar(&Ignore, "ignore", false, "skip all directories containing a specified filename")
rootCmd.Flags().StringVar(&IgnoreFile, "ignore-file", ".roulette-ignore", "filename used to indicate directory to be skipped")
rootCmd.Flags().StringVar(&IgnoreFile, "ignore-file", ".roulette-ignore", "filename used to indicate directory should be skipped")
rootCmd.Flags().BoolVar(&Images, "images", false, "enable support for image files")
rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup")
rootCmd.Flags().StringVar(&IndexFile, "index-file", "", "path to optional persistent index file")
@ -146,7 +143,6 @@ func init() {
rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)")
rootCmd.Flags().BoolVar(&Profile, "profile", false, "register net/http/pprof handlers")
rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories")
rootCmd.Flags().BoolVar(&Redact, "redact", false, "redact admin prefix in log output")
rootCmd.Flags().BoolVar(&Refresh, "refresh", false, "enable automatic page refresh via query parameter")
rootCmd.Flags().BoolVar(&Russian, "russian", false, "remove selected images after serving")
rootCmd.Flags().BoolVarP(&Sorting, "sort", "s", false, "enable sorting")

View File

@ -450,21 +450,6 @@ func serveVersion(errorChannel chan<- error) httprouter.Handle {
}
}
func registerHandler(mux *httprouter.Router, path string, handle httprouter.Handle) {
mux.GET(path, handle)
if Redact && AdminPrefix != "" {
path = strings.ReplaceAll(path, AdminPrefix, "/<admin_prefix>")
}
if Handlers {
fmt.Printf("%s | SERVE: Registered handler for %s\n",
time.Now().Format(logDate),
path,
)
}
}
func redirectRoot() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
newUrl := fmt.Sprintf("http://%s%s",
@ -538,10 +523,6 @@ func ServePage(args []string) error {
return ErrNoMediaFound
}
if !strings.HasSuffix(Prefix, "/") {
Prefix = Prefix + "/"
}
listenHost := net.JoinHostPort(Bind, strconv.Itoa(Port))
index := &fileIndex{
@ -585,26 +566,30 @@ func ServePage(args []string) error {
filename := regexp.MustCompile(`(.+?)([0-9]*)(\..+)`)
registerHandler(mux, Prefix, serveRoot(paths, index, filename, formats, encoder, errorChannel))
if !strings.HasSuffix(Prefix, "/") {
Prefix = Prefix + "/"
}
mux.GET(Prefix, serveRoot(paths, index, filename, formats, encoder, errorChannel))
Prefix = strings.TrimSuffix(Prefix, "/")
if Prefix != "" {
registerHandler(mux, "/", redirectRoot())
mux.GET("/", redirectRoot())
}
registerHandler(mux, Prefix+"/favicons/*favicon", serveFavicons(errorChannel))
mux.GET(Prefix+"/favicons/*favicon", serveFavicons(errorChannel))
registerHandler(mux, Prefix+"/favicon.ico", serveFavicons(errorChannel))
mux.GET(Prefix+"/favicon.ico", serveFavicons(errorChannel))
registerHandler(mux, Prefix+mediaPrefix+"/*media", serveMedia(paths, index, filename, formats, errorChannel))
mux.GET(Prefix+mediaPrefix+"/*media", serveMedia(paths, index, filename, formats, errorChannel))
registerHandler(mux, Prefix+sourcePrefix+"/*static", serveStaticFile(paths, index, errorChannel))
mux.GET(Prefix+sourcePrefix+"/*static", serveStaticFile(paths, index, errorChannel))
registerHandler(mux, Prefix+"/version", serveVersion(errorChannel))
mux.GET(Prefix+"/version", serveVersion(errorChannel))
if Index {
registerHandler(mux, Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(args, index, formats, encoder, errorChannel))
mux.GET(Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(args, index, formats, encoder, errorChannel))
importIndex(paths, index, formats, encoder, errorChannel)
}