diff options
| author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-03 23:13:04 +0200 | 
|---|---|---|
| committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-03 23:13:04 +0200 | 
| commit | c2d666b43477ea7042b574ad940c508216cb0e83 (patch) | |
| tree | a459b552374114c4ef9ebe9966ed6ec83bb9a11d /pkg/worker | |
| parent | 6e84441dab0a2b89869e33d7e89d14189d9b67c0 (diff) | |
| download | lens-c2d666b43477ea7042b574ad940c508216cb0e83.tar.gz lens-c2d666b43477ea7042b574ad940c508216cb0e83.tar.bz2 lens-c2d666b43477ea7042b574ad940c508216cb0e83.zip  | |
fix: Fix content type
Content type was always being set to `text/html`.
Also swap lib for processing thumbnail for something that accepts HEIC.
Diffstat (limited to 'pkg/worker')
| -rw-r--r-- | pkg/worker/list_processor.go | 13 | ||||
| -rw-r--r-- | pkg/worker/thumbnail_scanner.go | 7 | 
2 files changed, 17 insertions, 3 deletions
diff --git a/pkg/worker/list_processor.go b/pkg/worker/list_processor.go index 0a07085..c060583 100644 --- a/pkg/worker/list_processor.go +++ b/pkg/worker/list_processor.go @@ -16,6 +16,10 @@ type (  		Process(context.Context, T) error  	} +	OnFail[T any] interface { +		OnFail(context.Context, T, error) +	} +  	BatchProcessor[T any] interface {  		Query(context.Context) ([]T, error)  		Process(context.Context, T) error @@ -77,6 +81,12 @@ func (l *batchProcessorWorker[T]) Start(ctx context.Context) error {  		var wg sync.WaitGroup  		for _, v := range values { +			select { +			case <-ctx.Done(): +				return ctx.Err() +			default: +			} +  			wg.Add(1)  			l.scheduler.Take()  			go func(v T) { @@ -84,6 +94,9 @@ func (l *batchProcessorWorker[T]) Start(ctx context.Context) error {  				defer wg.Done()  				if err := l.batchProcessor.Process(ctx, v); err != nil && !errors.Is(err, context.Canceled) {  					l.logrus.WithError(err).Error("Error processing batch") +					if failure, ok := l.batchProcessor.(OnFail[T]); ok { +						failure.OnFail(ctx, v, err) +					}  				}  			}(v)  		} diff --git a/pkg/worker/thumbnail_scanner.go b/pkg/worker/thumbnail_scanner.go index cc201b8..168abef 100644 --- a/pkg/worker/thumbnail_scanner.go +++ b/pkg/worker/thumbnail_scanner.go @@ -2,6 +2,7 @@ package worker  import (  	"context" +	"fmt"  	"math"  	"os"  	"path" @@ -47,12 +48,12 @@ func (t *ThumbnailScanner) Process(ctx context.Context, media *repository.Media)  	if media.IsVideo() {  		err := fileop.EncodeVideoThumbnail(media.Path, output, 1080, 1080)  		if err != nil { -			return err +			return fmt.Errorf("Error thumbnail video %d; %w", media.ID, err)  		}  	} else { -		err := fileop.EncodeImageThumbnail(media.Path, output, 1080, math.MaxInt) +		err := fileop.EncodeImageThumbnail(media.Path, output, 1080, math.MinInt32)  		if err != nil { -			return err +			return fmt.Errorf("Error thumbnail image %d; %w", media.ID, err)  		}  	}  | 
