Add basic validation for max/min file count and scan values
This commit is contained in:
parent
935021e464
commit
f7376e89b9
|
@ -16,9 +16,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
|
ErrInvalidFileCountRange = errors.New("maximum file count must be greater than or equal to minimum file count")
|
||||||
ErrInvalidScanCount = errors.New("scan count must be a positive integer")
|
ErrInvalidFileCountValue = errors.New("file count value must be an integer between 1 and 2147483647 inclusive")
|
||||||
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
|
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
|
||||||
|
ErrInvalidScanCount = errors.New("scan count must be a positive integer")
|
||||||
|
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
|
||||||
)
|
)
|
||||||
|
|
||||||
func newErrorPage(title, body string) string {
|
func newErrorPage(title, body string) string {
|
||||||
|
|
16
cmd/root.go
16
cmd/root.go
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReleaseVersion string = "0.93.1"
|
ReleaseVersion string = "0.93.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -55,6 +55,18 @@ var (
|
||||||
return ErrInvalidScanCount
|
return ErrInvalidScanCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if MaxFileCount > 1<<31-1 || MaxFileCount < 1 {
|
||||||
|
return ErrInvalidFileCountValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if MinFileCount > 1<<31-1 || MinFileCount < 1 {
|
||||||
|
return ErrInvalidFileCountValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if MinFileCount > MaxFileCount {
|
||||||
|
return ErrInvalidFileCountRange
|
||||||
|
}
|
||||||
|
|
||||||
if Port < 1 || Port > 65535 {
|
if Port < 1 || Port > 65535 {
|
||||||
return ErrInvalidPort
|
return ErrInvalidPort
|
||||||
}
|
}
|
||||||
|
@ -96,7 +108,7 @@ func init() {
|
||||||
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
|
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
|
||||||
rootCmd.Flags().IntVar(&MaxDirScans, "max-directory-scans", 32, "number of directories to scan at once")
|
rootCmd.Flags().IntVar(&MaxDirScans, "max-directory-scans", 32, "number of directories to scan at once")
|
||||||
rootCmd.Flags().IntVar(&MaxFileScans, "max-file-scans", 256, "number of files to scan at once")
|
rootCmd.Flags().IntVar(&MaxFileScans, "max-file-scans", 256, "number of files to scan at once")
|
||||||
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", 1<<32-1, "skip directories with file counts above this value")
|
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", 1<<31-1, "skip directories with file counts above this value")
|
||||||
rootCmd.Flags().IntVar(&MinFileCount, "min-file-count", 1, "skip directories with file counts below this value")
|
rootCmd.Flags().IntVar(&MinFileCount, "min-file-count", 1, "skip directories with file counts below this value")
|
||||||
rootCmd.Flags().IntVar(&PageLength, "page-length", 0, "pagination length for info pages")
|
rootCmd.Flags().IntVar(&PageLength, "page-length", 0, "pagination length for info pages")
|
||||||
rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on")
|
rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on")
|
||||||
|
|
Loading…
Reference in New Issue