@@ -24,6 +24,7 @@ type File struct {
2424 Bucket string `bson:"bucket" json:"-"`
2525 Mime string `bson:"mime" json:"mime"`
2626 ThumbnailMime string `bson:"thumbnail_mime,omitempty" json:"thumbnail_mime,omitempty"`
27+ ThumbnailSize int64 `bson:"thumbnail_size,omitempty" json:"thumbnail_size,omitempty"`
2728 Size int64 `bson:"size" json:"size"`
2829 Filename string `bson:"filename,omitempty" json:"filename,omitempty"`
2930 Width int `bson:"width,omitempty" json:"width,omitempty"`
@@ -514,25 +515,30 @@ func (f *File) GenerateThumbnail() error {
514515 }
515516
516517 // Upload thumbnail
517- if _ , err := s3Clients [s3RegionOrder [0 ]].FPutObject (
518+ uploadInfo , err := s3Clients [s3RegionOrder [0 ]].FPutObject (
518519 ctx ,
519520 f .Bucket ,
520521 fmt .Sprint (f .Hash , "_thumbnail" ),
521522 fmt .Sprint (ingestDir , "/thumbnail." , format ),
522523 minio.PutObjectOptions {
523524 ContentType : fmt .Sprint ("image/" , format ),
524525 },
525- ); err != nil {
526+ )
527+ if err != nil {
526528 sentry .CaptureException (err )
527529 return err
528530 }
529531
530532 // Update file details
531533 f .ThumbnailMime = fmt .Sprint ("image/" , format )
534+ f .ThumbnailSize = uploadInfo .Size
532535 if _ , err := db .Collection ("files" ).UpdateMany (
533536 context .TODO (),
534537 bson.M {"hash" : f .Hash , "bucket" : f .Bucket },
535- bson.M {"$set" : bson.M {"thumbnail_mime" : f .ThumbnailMime }},
538+ bson.M {"$set" : bson.M {
539+ "thumbnail_mime" : f .ThumbnailMime ,
540+ "thumbnail_size" : f .ThumbnailSize ,
541+ }},
536542 ); err != nil {
537543 sentry .CaptureException (err )
538544 return err
@@ -545,7 +551,7 @@ func (f *File) GetObject(thumbnail bool) (*minio.Object, error) {
545551 objName := f .Hash
546552 if thumbnail && f .Bucket == "attachments" && (strings .HasPrefix (f .Mime , "image/" ) || strings .HasPrefix (f .Mime , "video/" )) {
547553 // Generate thumbnail if one doesn't exist yet
548- if f .ThumbnailMime == "" {
554+ if f .ThumbnailMime == "" || f . ThumbnailSize == 0 {
549555 if err := f .GenerateThumbnail (); err != nil {
550556 return nil , err
551557 }
0 commit comments