repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / shared / storage
Eric Bower · 09 Nov 24

minio.go

 1package storage
 2
 3import (
 4	"fmt"
 5	"io"
 6	"os"
 7	"path/filepath"
 8
 9	sst "github.com/picosh/pobj/storage"
10)
11
12type StorageMinio struct {
13	*sst.StorageMinio
14}
15
16func NewStorageMinio(address, user, pass string) (*StorageMinio, error) {
17	st, err := sst.NewStorageMinio(address, user, pass)
18	if err != nil {
19		return nil, err
20	}
21	return &StorageMinio{st}, nil
22}
23
24func (s *StorageMinio) ServeObject(bucket sst.Bucket, fpath string, opts *ImgProcessOpts) (io.ReadCloser, string, error) {
25	if opts == nil || os.Getenv("IMGPROXY_URL") == "" {
26		contentType := GetMimeType(fpath)
27		rc, _, err := s.GetObject(bucket, fpath)
28		return rc, contentType, err
29	}
30
31	filePath := filepath.Join(bucket.Name, fpath)
32	dataURL := fmt.Sprintf("s3://%s", filePath)
33	return HandleProxy(dataURL, opts)
34}