aboutsummaryrefslogtreecommitdiff
path: root/pkg/worker/exif_scanner.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-24 00:34:57 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-25 15:18:12 +0200
commit57b41ad766b3c4505672c12f058f10c7a132dd5b (patch)
tree80aea95babc8f740e86dadc7469236bdffc78c26 /pkg/worker/exif_scanner.go
parentd5261d7f121985f13f9d19e9efd5c2ae3d4b5609 (diff)
downloadlens-57b41ad766b3c4505672c12f058f10c7a132dd5b.tar.gz
lens-57b41ad766b3c4505672c12f058f10c7a132dd5b.tar.bz2
lens-57b41ad766b3c4505672c12f058f10c7a132dd5b.zip
feat: Remove unnecessary function
Diffstat (limited to 'pkg/worker/exif_scanner.go')
-rw-r--r--pkg/worker/exif_scanner.go30
1 files changed, 3 insertions, 27 deletions
diff --git a/pkg/worker/exif_scanner.go b/pkg/worker/exif_scanner.go
index 4aa247d..91eed12 100644
--- a/pkg/worker/exif_scanner.go
+++ b/pkg/worker/exif_scanner.go
@@ -4,6 +4,7 @@ import (
"context"
"git.sr.ht/~gabrielgio/img/pkg/components/media"
+ "git.sr.ht/~gabrielgio/img/pkg/coroutine"
"git.sr.ht/~gabrielgio/img/pkg/fileop"
)
@@ -33,36 +34,11 @@ func (e *EXIFScanner) Query(ctx context.Context) ([]*media.Media, error) {
return medias, nil
}
-func wrapReadExif(ctx context.Context, path string) (*media.MediaEXIF, error) {
- c := make(chan *media.MediaEXIF)
- e := make(chan error)
- go func() {
- defer close(c)
- defer close(e)
-
- newExif, err := fileop.ReadExif(path)
- if err != nil {
- e <- err
- } else {
- c <- newExif
- }
- }()
-
- select {
- case <-ctx.Done():
- return nil, ctx.Err()
- case m := <-c:
- return m, nil
- case err := <-e:
- return nil, err
- }
-}
-
func (e *EXIFScanner) Process(ctx context.Context, m *media.Media) error {
- newExif, err := wrapReadExif(ctx, m.Path)
+ exif, err := coroutine.WrapProcess(ctx, func() (*media.MediaEXIF, error) { return fileop.ReadExif(m.Path) })
if err != nil {
return err
}
- return e.repository.CreateEXIF(ctx, m.ID, newExif)
+ return e.repository.CreateEXIF(ctx, m.ID, exif)
}