Compare commits

..

No commits in common. "6b70741a689123064b56df01a7a0f97cc141fef4" and "a94b7e208dc9bf73b9d10cc45cb6f9970627ee4a" have entirely different histories.

4 changed files with 55 additions and 50 deletions

View File

@ -58,7 +58,7 @@ The remaining four endpoints—`/available_extensions`, `/enabled_extensions`, `
## Refresh ## Refresh
If the `--refresh` flag is passed and a positive-value `refresh=<integer><unit>` query parameter is provided, the page will reload after that interval. If a positive-value `refresh=<integer><unit>` query parameter is provided, the page will reload after that interval.
This can be used to generate a sort of slideshow of files. This can be used to generate a sort of slideshow of files.
@ -107,31 +107,31 @@ Usage:
roulette <path> [path]... [flags] roulette <path> [path]... [flags]
Flags: Flags:
-a, --all enable all supported file types -a, --all enable all supported file types
--audio enable support for audio files --audio enable support for audio files
-b, --bind string address to bind to (default "0.0.0.0") -b, --bind string address to bind to (default "0.0.0.0")
-c, --cache generate directory cache at startup -c, --cache generate directory cache at startup
--cache-file string path to optional persistent cache file --cache-file string path to optional persistent cache file
-f, --filter enable filtering -f, --filter enable filtering
--flash enable support for shockwave flash files (via ruffle.rs) --flash enable support for shockwave flash files (via ruffle.rs)
--handlers display registered handlers (for debugging) --handlers display registered handlers (for debugging)
-h, --help help for roulette -h, --help help for roulette
--images enable support for image files --images enable support for image files
-i, --info expose informational endpoints -i, --info expose informational endpoints
--maximum-files uint32 skip directories with file counts above this value (default 4294967295) --maximum-files uint32 skip directories with file counts above this value (default 4294967295)
--minimum-files uint32 skip directories with file counts below this value (default 1) --minimum-files uint32 skip directories with file counts below this value (default 1)
--page-length uint32 pagination length for statistics and debug pages --page-length uint32 pagination length for statistics and debug pages
-p, --port uint16 port to listen on (default 8080) -p, --port uint16 port to listen on (default 8080)
--prefix string root path for http handlers (for reverse proxying) (default "/") --prefix string path with which to prefix all listeners (for reverse proxying)
--profile register net/http/pprof handlers --profile register net/http/pprof handlers
-r, --recursive recurse into subdirectories -r, --recursive recurse into subdirectories
--refresh enable automatic page refresh via query parameter --refresh-interval string force refresh interval equal to this duration (minimum 500ms)
--russian remove selected images after serving --russian remove selected images after serving
-s, --sort enable sorting -s, --sort enable sorting
--text enable support for text files --text enable support for text files
-v, --verbose log accessed files and other information to stdout -v, --verbose log accessed files and other information to stdout
-V, --version display version and exit -V, --version display version and exit
--video enable support for video files --video enable support for video files
``` ```
## Building the Docker container ## Building the Docker container

View File

@ -6,12 +6,13 @@ package cmd
import ( import (
"log" "log"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const ( const (
ReleaseVersion string = "0.83.0" ReleaseVersion string = "0.82.0"
) )
var ( var (
@ -32,7 +33,7 @@ var (
Prefix string Prefix string
Profile bool Profile bool
Recursive bool Recursive bool
Refresh bool RefreshInterval string
Russian bool Russian bool
Sorting bool Sorting bool
Text bool Text bool
@ -44,6 +45,16 @@ var (
Use: "roulette <path> [path]...", Use: "roulette <path> [path]...",
Short: "Serves random media from the specified directories.", Short: "Serves random media from the specified directories.",
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
if RefreshInterval != "" {
interval, err := time.ParseDuration(RefreshInterval)
if err != nil || interval < 500*time.Millisecond {
return ErrIncorrectRefreshInterval
}
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
err := ServePage(args) err := ServePage(args)
if err != nil { if err != nil {
@ -77,10 +88,10 @@ func init() {
rootCmd.Flags().Uint32Var(&MinimumFileCount, "minimum-files", 1, "skip directories with file counts below this value") rootCmd.Flags().Uint32Var(&MinimumFileCount, "minimum-files", 1, "skip directories with file counts below this value")
rootCmd.Flags().Uint32Var(&PageLength, "page-length", 0, "pagination length for statistics and debug pages") rootCmd.Flags().Uint32Var(&PageLength, "page-length", 0, "pagination length for statistics and debug pages")
rootCmd.Flags().Uint16VarP(&Port, "port", "p", 8080, "port to listen on") rootCmd.Flags().Uint16VarP(&Port, "port", "p", 8080, "port to listen on")
rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)") rootCmd.Flags().StringVar(&Prefix, "prefix", "", "path with which to prefix all listeners (for reverse proxying)")
rootCmd.Flags().BoolVar(&Profile, "profile", false, "register net/http/pprof handlers") rootCmd.Flags().BoolVar(&Profile, "profile", false, "register net/http/pprof handlers")
rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories") rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories")
rootCmd.Flags().BoolVar(&Refresh, "refresh", false, "enable automatic page refresh via query parameter") rootCmd.Flags().StringVar(&RefreshInterval, "refresh-interval", "", "force refresh interval equal to this duration (minimum 500ms)")
rootCmd.Flags().BoolVar(&Russian, "russian", false, "remove selected images after serving") rootCmd.Flags().BoolVar(&Russian, "russian", false, "remove selected images after serving")
rootCmd.Flags().BoolVarP(&Sorting, "sort", "s", false, "enable sorting") rootCmd.Flags().BoolVarP(&Sorting, "sort", "s", false, "enable sorting")
rootCmd.Flags().BoolVar(&Text, "text", false, "enable support for text files") rootCmd.Flags().BoolVar(&Text, "text", false, "enable support for text files")

View File

@ -14,12 +14,18 @@ import (
) )
func refreshInterval(r *http.Request) (int64, string) { func refreshInterval(r *http.Request) (int64, string) {
interval := r.URL.Query().Get("refresh") var interval string
if RefreshInterval == "" {
interval = r.URL.Query().Get("refresh")
} else {
interval = RefreshInterval
}
duration, err := time.ParseDuration(interval) duration, err := time.ParseDuration(interval)
switch { switch {
case err != nil || duration == 0 || !Refresh: case err != nil || duration == 0:
return 0, "0ms" return 0, "0ms"
case duration < 500*time.Millisecond: case duration < 500*time.Millisecond:
return 500, "500ms" return 500, "500ms"
@ -86,20 +92,12 @@ func generateQueryParams(filters *filters, sortOrder, refreshInterval string) st
hasParams = true hasParams = true
} }
if Refresh {
if hasParams {
queryParams.WriteString("&")
}
queryParams.WriteString(fmt.Sprintf("refresh=%s", refreshInterval))
hasParams = true
}
if hasParams { if hasParams {
return queryParams.String() queryParams.WriteString("&")
} }
queryParams.WriteString(fmt.Sprintf("refresh=%s", refreshInterval))
return "" return queryParams.String()
} }
func stripQueryParams(request string) (string, error) { func stripQueryParams(request string) (string, error) {

View File

@ -243,7 +243,7 @@ func serveMedia(paths []string, regexes *regexes, formats *types.Types) httprout
return return
} }
fileUri := Prefix + generateFileUri(path) fileUri := Prefix + "/" + generateFileUri(path)
fileName := filepath.Base(path) fileName := filepath.Base(path)
@ -385,14 +385,10 @@ func ServePage(args []string) error {
mux.PanicHandler = serverErrorHandler() mux.PanicHandler = serverErrorHandler()
if !strings.HasSuffix(Prefix, "/") {
Prefix = Prefix + "/"
}
register(mux, Prefix, serveRoot(paths, regexes, cache, formats))
Prefix = strings.TrimSuffix(Prefix, "/") Prefix = strings.TrimSuffix(Prefix, "/")
register(mux, Prefix+"/", serveRoot(paths, regexes, cache, formats))
if Prefix != "" { if Prefix != "" {
register(mux, "/", redirectRoot()) register(mux, "/", redirectRoot())
} }