lens @ 7a414da9a802d5eeee911b3536790a061e1d7503

 1package worker
 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)
10
11type (
12	EXIFScanner struct {
13		repository repository.MediaRepository
14	}
15)
16
17var _ BatchProcessor[*repository.Media] = &EXIFScanner{}
18
19func NewEXIFScanner(repository repository.MediaRepository) *EXIFScanner {
20	return &EXIFScanner{
21		repository: repository,
22	}
23}
24
25func (e *EXIFScanner) Query(ctx context.Context) ([]*repository.Media, error) {
26	medias, err := e.repository.GetEmptyEXIF(ctx, &repository.Pagination{
27		Page: 0,
28		Size: 100,
29	})
30	if err != nil {
31		return nil, err
32	}
33
34	return medias, nil
35}
36
37func (e *EXIFScanner) Process(ctx context.Context, m *repository.Media) error {
38	exif, err := coroutine.WrapProcess(ctx, func() (*repository.MediaEXIF, error) { return fileop.ReadExif(m.Path) })
39	if err != nil {
40		return err
41	}
42
43	return e.repository.CreateEXIF(ctx, m.ID, exif)
44}