Added retry to new file selection, with 10s timeout

This commit is contained in:
Seednode 2023-02-18 14:08:11 -06:00
parent e2356c180f
commit 966df032a6
4 changed files with 22 additions and 16 deletions

View File

@ -517,39 +517,33 @@ func prepareDirectory(directory []string) []string {
last = cleanFilename(last) last = cleanFilename(last)
if first == last { if first == last {
return append([]string{}, directory[0]) return []string{directory[0]}
} else { } else {
return directory return directory
} }
} }
func prepareDirectories(files *Files, sort string) []string { func prepareDirectories(files *Files, sort string) []string {
i, l := 0, 0 directories := []string{}
files.mutex.RLock()
keys := make([]string, len(files.list)) keys := make([]string, len(files.list))
i := 0
for k := range files.list { for k := range files.list {
keys[i] = k keys[i] = k
i++ i++
l += len(files.list[k])
} }
directories := make([]string, l)
if sort == "asc" || sort == "desc" { if sort == "asc" || sort == "desc" {
for i := 0; i < len(keys); i++ { for i := 0; i < len(keys); i++ {
copy(directories, prepareDirectory(files.list[keys[i]])) directories = append(directories, prepareDirectory(files.list[keys[i]])...)
} }
} else { } else {
for i := 0; i < len(keys); i++ { for i := 0; i < len(keys); i++ {
copy(directories, files.list[keys[i]]) directories = append(directories, files.list[keys[i]]...)
} }
} }
files.mutex.RUnlock()
return directories return directories
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.38.1" var Version = "0.38.2"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)

View File

@ -35,9 +35,10 @@ var (
) )
const ( const (
LogDate string = `2006-01-02T15:04:05.000-07:00` LogDate string = `2006-01-02T15:04:05.000-07:00`
Prefix string = `/src` Prefix string = `/src`
RedirectStatusCode int = http.StatusSeeOther RedirectStatusCode int = http.StatusSeeOther
Timeout time.Duration = 10 * time.Second
) )
type Regexes struct { type Regexes struct {
@ -682,7 +683,18 @@ func serveHtmlHandler(paths []string, Regexes *Regexes, index *Index) http.Handl
} }
} }
if filePath == "" { loop:
for timeout := time.After(Timeout); ; {
select {
case <-timeout:
break loop
default:
}
if filePath != "" {
break loop
}
filePath, err = newFile(paths, filters, sortOrder, Regexes, index) filePath, err = newFile(paths, filters, sortOrder, Regexes, index)
switch { switch {
case err != nil && err == ErrNoImagesFound: case err != nil && err == ErrNoImagesFound:

Binary file not shown.