Skip to content

Commit

Permalink
fix(storage): check for empty metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 9, 2025
1 parent b3098e1 commit 6530b86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions shared/storage/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package storage
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -25,14 +24,14 @@ func NewStorageFS(dir string) (*StorageFS, error) {

func (s *StorageFS) ServeObject(bucket sst.Bucket, fpath string, opts *ImgProcessOpts) (io.ReadCloser, *sst.ObjectInfo, error) {
var rc io.ReadCloser
info := &sst.ObjectInfo{
Metadata: make(http.Header),
UserMetadata: map[string]string{},
}
info := &sst.ObjectInfo{}
var err error
mimeType := GetMimeType(fpath)
if !strings.HasPrefix(mimeType, "image/") || opts == nil || os.Getenv("IMGPROXY_URL") == "" {
rc, info, err = s.GetObject(bucket, fpath)
if info.Metadata == nil {
info.Metadata = map[string][]string{}
}
// StorageFS never returns a content-type.
info.Metadata.Set("content-type", mimeType)
} else {
Expand Down
9 changes: 4 additions & 5 deletions shared/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package storage
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -25,14 +24,14 @@ func NewStorageMinio(address, user, pass string) (*StorageMinio, error) {

func (s *StorageMinio) ServeObject(bucket sst.Bucket, fpath string, opts *ImgProcessOpts) (io.ReadCloser, *sst.ObjectInfo, error) {
var rc io.ReadCloser
info := &sst.ObjectInfo{
Metadata: make(http.Header),
UserMetadata: map[string]string{},
}
info := &sst.ObjectInfo{}
var err error
mimeType := GetMimeType(fpath)
if !strings.HasPrefix(mimeType, "image/") || opts == nil || os.Getenv("IMGPROXY_URL") == "" {
rc, info, err = s.GetObject(bucket, fpath)
if info.Metadata == nil {
info.Metadata = map[string][]string{}
}
// Minio always returns application/octet-stream which needs to be overridden.
info.Metadata.Set("content-type", mimeType)
} else {
Expand Down

0 comments on commit 6530b86

Please sign in to comment.