aboutsummaryrefslogtreecommitdiff
path: root/internal/service/gallery_service.go
blob: 1145bb79c7b0de4ce1ad1d124549d793f5a120ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package service

import (
	"context"

	"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
	}

	photos, err := s.builder.Build(ctx, files)
	if err != nil {
		return nil, err
	}

	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
}