From 2f1cfe28d0409ab4b514a93958b792cb97c850e9 Mon Sep 17 00:00:00 2001 From: Seednode Date: Sun, 10 Sep 2023 21:05:35 -0500 Subject: [PATCH] Added support for toggling each of audio|image|video support --- README.md | 5 ++++- cmd/files.go | 4 ++-- cmd/root.go | 14 +++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3cf971e..b84b1ce 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,14 @@ Usage: roulette [path]... [flags] Flags: + --audio enable support for audio files -b, --bind string address to bind to (default "0.0.0.0") -c, --cache generate directory cache at startup --cache-file string path to optional persistent cache file -d, --debug expose debug endpoint -f, --filter enable filtering -h, --help help for roulette + --images enable support for audio files (default true) --maximum-files uint32 skip directories with file counts over this value (default 4294967295) --minimum-files uint32 skip directories with file counts under this value --page-length uint16 pagination length for statistics and debug pages @@ -121,12 +123,13 @@ Flags: --profile register net/http/pprof handlers -r, --recursive recurse into subdirectories --refresh-interval string force refresh interval equal to this duration (minimum 500ms) - --russian remove selected media after serving + --russian remove selected images after serving -s, --sort enable sorting --stats expose stats endpoint --stats-file string path to optional persistent stats file -v, --verbose log accessed files to stdout -V, --version display version and exit + --videos enable support for video files ``` ## Building the Docker container diff --git a/cmd/files.go b/cmd/files.go index 8bafb30..e5ce4c3 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -405,9 +405,9 @@ func fileType(path string) (bool, string, string, error) { switch { case filetype.IsAudio(head) && audio: return true, "audio", fileType.MIME.Value, nil - case filetype.IsImage(head): + case filetype.IsImage(head) && images: return true, "image", fileType.MIME.Value, nil - case filetype.IsVideo(head) && video: + case filetype.IsVideo(head) && videos: return true, "video", fileType.MIME.Value, nil default: return false, "", "", nil diff --git a/cmd/root.go b/cmd/root.go index 96afe5e..3bbd1e9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,7 @@ var ( ) const ( - Version string = "0.62.0" + Version string = "0.63.0" ) var ( @@ -27,6 +27,7 @@ var ( cacheFile string debug bool filtering bool + images bool maximumFileCount uint32 minimumFileCount uint32 pageLength uint16 @@ -40,11 +41,11 @@ var ( statisticsFile string verbose bool version bool - video bool + videos bool rootCmd = &cobra.Command{ Use: "roulette [path]...", - Short: "Serves random images from the specified directories.", + Short: "Serves random media from the specified directories.", Args: cobra.MinimumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { if debug { @@ -77,12 +78,13 @@ func Execute() { } func init() { - rootCmd.Flags().BoolVar(&audio, "audio", false, "additionally support audio files") + rootCmd.Flags().BoolVar(&audio, "audio", false, "enable support for audio files") rootCmd.Flags().StringVarP(&bind, "bind", "b", "0.0.0.0", "address to bind to") rootCmd.Flags().BoolVarP(&cache, "cache", "c", false, "generate directory cache at startup") rootCmd.Flags().StringVar(&cacheFile, "cache-file", "", "path to optional persistent cache file") rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "expose debug endpoint") rootCmd.Flags().BoolVarP(&filtering, "filter", "f", false, "enable filtering") + rootCmd.Flags().BoolVar(&images, "images", true, "enable support for audio files") rootCmd.Flags().Uint32Var(&maximumFileCount, "maximum-files", 1<<32-1, "skip directories with file counts over this value") rootCmd.Flags().Uint32Var(&minimumFileCount, "minimum-files", 0, "skip directories with file counts under this value") rootCmd.Flags().Uint16Var(&pageLength, "page-length", 0, "pagination length for statistics and debug pages") @@ -96,14 +98,12 @@ func init() { rootCmd.Flags().StringVar(&statisticsFile, "stats-file", "", "path to optional persistent stats file") rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "log accessed files to stdout") rootCmd.Flags().BoolVarP(&version, "version", "V", false, "display version and exit") - rootCmd.Flags().BoolVar(&video, "video", false, "additionally support video files") + rootCmd.Flags().BoolVar(&videos, "videos", false, "enable support for video files") rootCmd.Flags().SetInterspersed(true) rootCmd.CompletionOptions.HiddenDefaultCmd = true - // rootCmd.MarkFlagsMutuallyExclusive("cache", "russian") - rootCmd.SilenceErrors = true rootCmd.SetHelpCommand(&cobra.Command{ Hidden: true,