lens @ 3b9d27649a31e5af3fb137ff5b3378e7b8f7b9ae

 1package scanner
 2
 3import (
 4	"context"
 5
 6	"git.sr.ht/~gabrielgio/img/pkg/coroutine"
 7	"git.sr.ht/~gabrielgio/img/pkg/database/repository"
 8	"git.sr.ht/~gabrielgio/img/pkg/fileop"
 9	"git.sr.ht/~gabrielgio/img/pkg/worker"
10)
11
12type (
13	EXIFScanner struct {
14		repository repository.MediaRepository
15	}
16)
17
18var _ worker.BatchProcessor[*repository.Media] = &EXIFScanner{}
19
20func NewEXIFScanner(repository repository.MediaRepository) *EXIFScanner {
21	return &EXIFScanner{
22		repository: repository,
23	}
24}
25
26func (e *EXIFScanner) Query(ctx context.Context) ([]*repository.Media, error) {
27	return e.repository.ListEmptyEXIF(ctx, &repository.Pagination{
28		Page: 0,
29		Size: 100,
30	})
31}
32
33func (e *EXIFScanner) Process(ctx context.Context, m *repository.Media) error {
34	exif, err := coroutine.WrapProcess(ctx, func() (*repository.MediaEXIF, error) { return fileop.ReadExif(m.Path) })
35	if err != nil {
36		return err
37	}
38
39	return e.repository.CreateEXIF(ctx, m.ID, exif)
40}