fieat(gallery): recursive image search
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
package gallery
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
type fileWithPath struct {
|
||||||
|
os.FileInfo
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f fileWithPath) Name() string {
|
||||||
|
return path.Join(f.path, f.FileInfo.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) readDirRecursive(path string) (files []os.FileInfo, err error) {
|
||||||
|
return s.readDirRecursiveTo([]os.FileInfo{}, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) readDirRecursiveTo(files []os.FileInfo, p ...string) ([]os.FileInfo, error) {
|
||||||
|
localFiles, err := s.fs.ReadDir(path.Join(p...))
|
||||||
|
if err != nil {
|
||||||
|
return files, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range localFiles {
|
||||||
|
if file.IsDir() {
|
||||||
|
newP := append(p, file.Name())
|
||||||
|
files, err = s.readDirRecursiveTo(files, newP...)
|
||||||
|
if err != nil {
|
||||||
|
return files, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
files = append(files, fileWithPath{file, path.Join(p[1:]...)})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
@@ -41,10 +41,11 @@ func (s *Service) autoRefresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) assembleImageList(ctx context.Context) error {
|
func (s *Service) assembleImageList(ctx context.Context) error {
|
||||||
files, err := s.fs.ReadDir(s.cfg.Path)
|
files, err := s.readDirRecursive(s.cfg.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read contents of %s: %w", s.cfg.Path, err)
|
return fmt.Errorf("could not read contents of %s: %w", s.cfg.Path, err)
|
||||||
}
|
}
|
||||||
|
slog.Debug("loaded files", "files", files)
|
||||||
|
|
||||||
savedHash, _ := s.cache.Do(ctx, s.cache.B().Get().Key(hashKey).Build()).AsBytes()
|
savedHash, _ := s.cache.Do(ctx, s.cache.B().Get().Key(hashKey).Build()).AsBytes()
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ func (s *Service) assembleImageList(ctx context.Context) error {
|
|||||||
imagePath := path.Join(s.cfg.Path, file.Name())
|
imagePath := path.Join(s.cfg.Path, file.Name())
|
||||||
img, err := s.img.GetImage(imagePath)
|
img, err := s.img.GetImage(imagePath)
|
||||||
if err != nil || img.Image == nil {
|
if err != nil || img.Image == nil {
|
||||||
|
slog.Warn("could not get image for gallery", "err", err, "img", img)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user