aboutsummaryrefslogtreecommitdiff
path: root/internal/service/gallery_service.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 18:37:01 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 18:37:01 +0530
commitd754ce4c11af51e06515275b58a3f337a440ed9d (patch)
tree07845d209b67c7445803443e2ba158e91b672888 /internal/service/gallery_service.go
parenta06e00d332aff7ddc667331c8f83b7317f5ca933 (diff)
downloadgalleryd-d754ce4c11af51e06515275b58a3f337a440ed9d.tar.xz
galleryd-d754ce4c11af51e06515275b58a3f337a440ed9d.zip
feat(service): introduce service lifecycle & load gallery during initialization
Diffstat (limited to 'internal/service/gallery_service.go')
-rw-r--r--internal/service/gallery_service.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/internal/service/gallery_service.go b/internal/service/gallery_service.go
index 1145bb7..e500bec 100644
--- a/internal/service/gallery_service.go
+++ b/internal/service/gallery_service.go
@@ -2,32 +2,22 @@ package service
import (
"context"
+ "errors"
"github.com/RanXom/galleryd/internal/gallery"
)
// Gallery scans the configured roots and builds the gallery.
func (s *galleryService) Gallery(ctx context.Context) ([]gallery.Photo, error) {
- files, err := s.scanner.Scan(ctx)
- if err != nil {
- return nil, err
+ select {
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ default:
}
- photos, err := s.builder.Build(ctx, files)
- if err != nil {
- return nil, err
+ if s.index.byID == nil {
+ return nil, errors.New("gallery not loaded")
}
- index := galleryIndex{
- photos: photos,
- byID: make(map[string]gallery.Photo, len(photos)),
- }
-
- for _, photo := range photos {
- index.byID[photo.ID] = photo
- }
-
- s.index = index
-
return s.index.photos, nil
}