From 48d6803d179cb3c1a70955507561f48e226bae4a Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Fri, 31 Mar 2023 23:06:22 +0300 Subject: [PATCH] check only the existence of the thumb and add ContentType metadata when creating the thumb --- apis/file.go | 7 ++----- tools/filesystem/filesystem.go | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apis/file.go b/apis/file.go index e9ac8449..43d152b6 100644 --- a/apis/file.go +++ b/apis/file.go @@ -87,11 +87,8 @@ func (api *fileApi) download(c echo.Context) error { servedName = thumbSize + "_" + filename servedPath = baseFilesPath + "/thumbs_" + filename + "/" + servedName - // check if the thumb exists: - // - if doesn't exist - create a new thumb with the specified thumb size - // - if exists - compare last modified dates to determine whether the thumb should be recreated - tAttrs, tAttrsErr := fs.Attributes(servedPath) - if tAttrsErr != nil || oAttrs.ModTime.After(tAttrs.ModTime) { + // create a new thumb if it doesn exists + if exists, _ := fs.Exists(servedPath); !exists { if err := fs.CreateThumb(originalPath, servedPath, thumbSize); err != nil { servedPath = originalPath // fallback to the original } diff --git a/tools/filesystem/filesystem.go b/tools/filesystem/filesystem.go index 9b6becda..740d2a31 100644 --- a/tools/filesystem/filesystem.go +++ b/tools/filesystem/filesystem.go @@ -411,8 +411,12 @@ func (s *System) CreateThumb(originalKey string, thumbKey, thumbSize string) err } } + opts := &blob.WriterOptions{ + ContentType: r.ContentType(), + } + // open a thumb storage writer (aka. prepare for upload) - w, writerErr := s.bucket.NewWriter(s.ctx, thumbKey, nil) + w, writerErr := s.bucket.NewWriter(s.ctx, thumbKey, opts) if writerErr != nil { return writerErr }