Skip to content

Commit

Permalink
check only the existence of the thumb and add ContentType metadata wh…
Browse files Browse the repository at this point in the history
…en creating the thumb
  • Loading branch information
ganigeorgiev committed Mar 31, 2023
1 parent 216efb9 commit 48d6803
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 2 additions & 5 deletions apis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion tools/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 48d6803

Please sign in to comment.