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