lens @ d6cf67b3d7747b6274d92e394d75d348060fa5f5

 1package worker
 2
 3import (
 4	"context"
 5
 6	"git.sr.ht/~gabrielgio/img/pkg/components/media"
 7	"git.sr.ht/~gabrielgio/img/pkg/coroutine"
 8	"git.sr.ht/~gabrielgio/img/pkg/fileop"
 9)
10
11type (
12	EXIFScanner struct {
13		repository media.Repository
14	}
15)
16
17var _ BatchProcessor[*media.Media] = &EXIFScanner{}
18
19func NewEXIFScanner(repository media.Repository) *EXIFScanner {
20	return &EXIFScanner{
21		repository: repository,
22	}
23}
24
25func (e *EXIFScanner) Query(ctx context.Context) ([]*media.Media, error) {
26	medias, err := e.repository.GetEmptyEXIF(ctx, &media.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 *media.Media) error {
38	exif, err := coroutine.WrapProcess(ctx, func() (*media.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}