package scanner import ( "context" "git.sr.ht/~gabrielgio/img/pkg/coroutine" "git.sr.ht/~gabrielgio/img/pkg/database/repository" "git.sr.ht/~gabrielgio/img/pkg/fileop" "git.sr.ht/~gabrielgio/img/pkg/worker" ) type ( EXIFScanner struct { repository repository.MediaRepository } ) var _ worker.ListProcessor[*repository.Media] = &EXIFScanner{} func NewEXIFScanner(repository repository.MediaRepository) *EXIFScanner { return &EXIFScanner{ repository: repository, } } func (e *EXIFScanner) Query(ctx context.Context) ([]*repository.Media, error) { return e.repository.ListEmptyEXIF(ctx, &repository.Pagination{ Page: 0, Size: 100, }) } func (t *EXIFScanner) OnFail(ctx context.Context, media *repository.Media, _ error) { _ = t.repository.CreateEXIF(ctx, media.ID, &repository.MediaEXIF{}) } func (e *EXIFScanner) Process(ctx context.Context, m *repository.Media) error { exif, err := coroutine.WrapProcess(ctx, func() (*repository.MediaEXIF, error) { return fileop.ReadExif(m.Path) }) if err != nil { return err } return e.repository.CreateEXIF(ctx, m.ID, exif) }