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

View File

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

View File

@ -35,9 +35,10 @@ var (
)
const (
LogDate string = `2006-01-02T15:04:05.000-07:00`
Prefix string = `/src`
RedirectStatusCode int = http.StatusSeeOther
LogDate string = `2006-01-02T15:04:05.000-07:00`
Prefix string = `/src`
RedirectStatusCode int = http.StatusSeeOther
Timeout time.Duration = 10 * time.Second
)
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)
switch {
case err != nil && err == ErrNoImagesFound:

Binary file not shown.