diff options
Diffstat (limited to 'pkg/worker/scanner/exif_scanner.go')
-rw-r--r-- | pkg/worker/scanner/exif_scanner.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/worker/scanner/exif_scanner.go b/pkg/worker/scanner/exif_scanner.go new file mode 100644 index 0000000..47d717f --- /dev/null +++ b/pkg/worker/scanner/exif_scanner.go @@ -0,0 +1,40 @@ +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.BatchProcessor[*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 (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) +} |