Compare commits
4 Commits
e67752470d
...
5dc218c60e
Author | SHA1 | Date |
---|---|---|
Seednode | 5dc218c60e | |
Seednode | 97f5bddafa | |
Seednode | 7d1ae04849 | |
Seednode | 5a37bf3beb |
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidFileCountRange = errors.New("maximum file count limit must be greater than or equal to minimum file count limit")
|
ErrInvalidFileCountRange = errors.New("maximum file count limit must be greater than or equal to minimum file count limit")
|
||||||
ErrInvalidFileCountValue = errors.New("file count limits must be positive integers no greater than 2147483647")
|
ErrInvalidFileCountValue = errors.New("file count limits must be non-negative integers no greater than 2147483647")
|
||||||
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
|
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
|
||||||
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
|
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
|
||||||
)
|
)
|
||||||
|
|
85
cmd/files.go
85
cmd/files.go
|
@ -7,6 +7,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"math/big"
|
"math/big"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
@ -177,6 +178,8 @@ func pathIsValid(path string, paths []string) bool {
|
||||||
for i := 0; i < len(paths); i++ {
|
for i := 0; i < len(paths); i++ {
|
||||||
if strings.HasPrefix(path, paths[i]) {
|
if strings.HasPrefix(path, paths[i]) {
|
||||||
matchesPrefix = true
|
matchesPrefix = true
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +230,6 @@ func hasSupportedFiles(path string, formats *types.Types) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels, formats *types.Types) error {
|
func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels, formats *types.Types) error {
|
||||||
var wg sync.WaitGroup
|
|
||||||
|
|
||||||
errorChannel := make(chan error)
|
errorChannel := make(chan error)
|
||||||
done := make(chan bool, 1)
|
done := make(chan bool, 1)
|
||||||
|
|
||||||
|
@ -237,8 +238,7 @@ func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var directories = 0
|
var directories, files = 0, 0
|
||||||
var files = 0
|
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if node.IsDir() {
|
if node.IsDir() {
|
||||||
|
@ -259,53 +259,52 @@ func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels,
|
||||||
skipFiles = true
|
skipFiles = true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodes {
|
var wg sync.WaitGroup
|
||||||
fullPath := filepath.Join(path, node.Name())
|
|
||||||
|
|
||||||
switch {
|
wg.Add(1)
|
||||||
case node.IsDir() && Recursive:
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for _, node := range nodes {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func(node fs.DirEntry) {
|
||||||
defer func() {
|
defer wg.Done()
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
err := walkPath(fullPath, fileChannel, stats, formats)
|
|
||||||
if err != nil {
|
|
||||||
errorChannel <- err
|
|
||||||
|
|
||||||
return
|
fullPath := filepath.Join(path, node.Name())
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case node.IsDir() && Recursive:
|
||||||
|
err := walkPath(fullPath, fileChannel, stats, formats)
|
||||||
|
if err != nil {
|
||||||
|
errorChannel <- err
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case !node.IsDir() && !skipFiles:
|
||||||
|
path, err := normalizePath(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
errorChannel <- err
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if formats.Validate(path) || Fallback {
|
||||||
|
fileChannel <- path
|
||||||
|
|
||||||
|
stats.filesMatched <- 1
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.filesSkipped <- 1
|
||||||
}
|
}
|
||||||
}()
|
}(node)
|
||||||
case !node.IsDir() && !skipFiles:
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
path, err := normalizePath(fullPath)
|
|
||||||
if err != nil {
|
|
||||||
errorChannel <- err
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if formats.Validate(path) || Fallback {
|
|
||||||
fileChannel <- path
|
|
||||||
|
|
||||||
stats.filesMatched <- 1
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
stats.filesSkipped <- 1
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
done <- true
|
done <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -366,6 +365,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats *types.Typ
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
done <- true
|
done <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -391,6 +391,7 @@ Poll:
|
||||||
|
|
||||||
if stats.filesMatched < 1 {
|
if stats.filesMatched < 1 {
|
||||||
fmt.Println("No files matched")
|
fmt.Println("No files matched")
|
||||||
|
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReleaseVersion string = "2.3.0"
|
ReleaseVersion string = "2.4.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -52,7 +52,7 @@ var (
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
switch {
|
switch {
|
||||||
case MaxFileCount < 1 || MinFileCount < 1 || MaxFileCount > math.MaxInt32 || MinFileCount > math.MaxInt32:
|
case MaxFileCount < 0 || MinFileCount < 0 || MaxFileCount > math.MaxInt32 || MinFileCount > math.MaxInt32:
|
||||||
return ErrInvalidFileCountValue
|
return ErrInvalidFileCountValue
|
||||||
case MinFileCount > MaxFileCount:
|
case MinFileCount > MaxFileCount:
|
||||||
return ErrInvalidFileCountRange
|
return ErrInvalidFileCountRange
|
||||||
|
@ -97,7 +97,7 @@ func init() {
|
||||||
rootCmd.Flags().StringVar(&IndexFile, "index-file", "", "path to optional persistent index file")
|
rootCmd.Flags().StringVar(&IndexFile, "index-file", "", "path to optional persistent index file")
|
||||||
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
|
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
|
||||||
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", math.MaxInt32, "skip directories with file counts above this value")
|
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", math.MaxInt32, "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", 0, "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")
|
||||||
rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)")
|
rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)")
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -404,6 +405,8 @@ func redirectRoot() httprouter.Handle {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServePage(args []string) error {
|
func ServePage(args []string) error {
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
timeZone := os.Getenv("TZ")
|
timeZone := os.Getenv("TZ")
|
||||||
if timeZone != "" {
|
if timeZone != "" {
|
||||||
var err error
|
var err error
|
||||||
|
|
BIN
default.pgo
BIN
default.pgo
Binary file not shown.
|
@ -55,7 +55,7 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(`<a href="%s"><img src="%s" width="%d" height="%d" type="%s" alt="Roulette selected: %s"></a>`,
|
return fmt.Sprintf(`<a href="%s"><img style="color: transparent;" onload="this.style.color='inherit'" onerror="this.style.color='inherit'" src="%s" width="%d" height="%d" type="%s" alt="Roulette selected: %s"></a>`,
|
||||||
rootUrl,
|
rootUrl,
|
||||||
fileUri,
|
fileUri,
|
||||||
dimensions.width,
|
dimensions.width,
|
||||||
|
|
Loading…
Reference in New Issue