Skip to content
Snippets Groups Projects
Commit a2fca74c authored by Travis Ralston's avatar Travis Ralston
Browse files

Don't calculate blurhashes on things we wouldn't thumbnail

parent fa60acef
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/turt2live/matrix-media-repo/database" "github.com/turt2live/matrix-media-repo/database"
) )
func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sha256hash string) chan struct{} { func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeBytes int64, sha256hash string) chan struct{} {
var err error var err error
opChan := make(chan struct{}) opChan := make(chan struct{})
go func() { go func() {
...@@ -21,6 +21,9 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sha25 ...@@ -21,6 +21,9 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sha25
if !ctx.Config.Features.MSC2448Blurhash.Enabled { if !ctx.Config.Features.MSC2448Blurhash.Enabled {
return return
} }
if ctx.Config.Thumbnails.MaxSourceBytes <= sizeBytes {
return
}
var img image.Image var img image.Image
img, err = imaging.Decode(reader) img, err = imaging.Decode(reader)
......
...@@ -150,7 +150,7 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re ...@@ -150,7 +150,7 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re
} }
// Step 10: Asynchronously calculate blurhash // Step 10: Asynchronously calculate blurhash
bhChan := upload.CalculateBlurhashAsync(ctx, bhR, sha256hash) bhChan := upload.CalculateBlurhashAsync(ctx, bhR, sizeBytes, sha256hash)
// Step 11: Asynchronously upload to cache // Step 11: Asynchronously upload to cache
cacheChan := upload.PopulateCacheAsync(ctx, cacheR, sizeBytes, sha256hash) cacheChan := upload.PopulateCacheAsync(ctx, cacheR, sizeBytes, sha256hash)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment