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

Don't thumbnail large files

parent 38745aed
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,9 @@ uploads: ...@@ -25,6 +25,9 @@ uploads:
# The thumbnail configuration for the media repository. # The thumbnail configuration for the media repository.
thumbnails: thumbnails:
# The maximum number of bytes an image can be before the thumbnailer refuses.
maxSourceBytes: 10485760 # 10MB default, 0 to disable
# All thumbnails are generated into one of the sizes listed here. The first size is used as # All thumbnails are generated into one of the sizes listed here. The first size is used as
# the default for when no width or height is requested. The media repository will return # the default for when no width or height is requested. The media repository will return
# either an exact match or the next largest size of thumbnail. # either an exact match or the next largest size of thumbnail.
......
...@@ -24,6 +24,7 @@ type MediaRepoConfig struct { ...@@ -24,6 +24,7 @@ type MediaRepoConfig struct {
} `yaml:"uploads"` } `yaml:"uploads"`
Thumbnails struct { Thumbnails struct {
MaxSourceBytes int64 `yaml:"maxSourceBytes"`
Sizes []struct { Sizes []struct {
Width int `yaml:"width"` Width int `yaml:"width"`
Height int `yaml:"height"` Height int `yaml:"height"`
......
...@@ -66,6 +66,10 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, ...@@ -66,6 +66,10 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int,
return thumb, err return thumb, err
} }
if media.SizeBytes > c.Thumbnails.MaxSourceBytes {
return thumb, errors.New("cannot thumbnail, image too large")
}
return generateThumbnail(ctx, media, targetWidth, targetHeight, method, c, db) return generateThumbnail(ctx, media, targetWidth, targetHeight, method, c, db)
} }
......
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