diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-01 17:55:50 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-01 17:55:50 +0200 |
commit | 6e84441dab0a2b89869e33d7e89d14189d9b67c0 (patch) | |
tree | e015839d495bcfc7619f4efd08f97a1ba603fd82 /pkg/worker/file_scanner.go | |
parent | 3f0dc691e2248cc21edd2e74a62b8f28ce95559e (diff) | |
download | lens-6e84441dab0a2b89869e33d7e89d14189d9b67c0.tar.gz lens-6e84441dab0a2b89869e33d7e89d14189d9b67c0.tar.bz2 lens-6e84441dab0a2b89869e33d7e89d14189d9b67c0.zip |
feat: Add thumbnailer
Diffstat (limited to 'pkg/worker/file_scanner.go')
-rw-r--r-- | pkg/worker/file_scanner.go | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/pkg/worker/file_scanner.go b/pkg/worker/file_scanner.go index aa79035..b4f907a 100644 --- a/pkg/worker/file_scanner.go +++ b/pkg/worker/file_scanner.go @@ -2,14 +2,12 @@ package worker import ( "context" - "crypto/md5" - "encoding/hex" "io/fs" "mime" "path/filepath" - "strings" "git.sr.ht/~gabrielgio/img/pkg/database/repository" + "git.sr.ht/~gabrielgio/img/pkg/fileop" ) type ( @@ -59,18 +57,17 @@ func (f *FileScanner) Query(ctx context.Context) (<-chan string, error) { } func (f *FileScanner) Process(ctx context.Context, path string) error { - m := mime.TypeByExtension(filepath.Ext(path)) - if !strings.HasPrefix(m, "video") && !strings.HasPrefix(m, "image") { + mimetype := mime.TypeByExtension(filepath.Ext(path)) + supported := fileop.IsMimeTypeSupported(mimetype) + if !supported { return nil } - hash := md5.Sum([]byte(path)) - str := hex.EncodeToString(hash[:]) - name := filepath.Base(path) + hash := fileop.GetHashFromPath(path) - exists, errResp := f.repository.Exists(ctx, str) - if errResp != nil { - return errResp + exists, err := f.repository.Exists(ctx, hash) + if err != nil { + return err } if exists { @@ -78,9 +75,9 @@ func (f *FileScanner) Process(ctx context.Context, path string) error { } return f.repository.Create(ctx, &repository.CreateMedia{ - Name: name, + Name: filepath.Base(path), Path: path, - PathHash: str, - MIMEType: m, + PathHash: hash, + MIMEType: mimetype, }) } |