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 return e.repository.ListEmptyEXIF(ctx, &repository.Pagination{
27 Page: 0,
28 Size: 100,
29 })
30}
31
32func (e *EXIFScanner) Process(ctx context.Context, m *repository.Media) error {
33 exif, err := coroutine.WrapProcess(ctx, func() (*repository.MediaEXIF, error) { return fileop.ReadExif(m.Path) })
34 if err != nil {
35 return err
36 }
37
38 return e.repository.CreateEXIF(ctx, m.ID, exif)
39}