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

fs.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 StorageFS struct {
13	*sst.StorageFS
14}
15
16func NewStorageFS(dir string) (*StorageFS, error) {
17	st, err := sst.NewStorageFS(dir)
18	if err != nil {
19		return nil, err
20	}
21	return &StorageFS{st}, nil
22}
23
24func (s *StorageFS) 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.Path, fpath)
32	dataURL := fmt.Sprintf("local://%s", filePath)
33	return HandleProxy(dataURL, opts)
34}