repos / pico

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

commit
8d29755
parent
15dc5a8
author
Eric Bower
date
2024-02-18 15:06:48 +0000 UTC
chore: add `GetObjectSize`
5 files changed,  +24, -4
M go.mod
M go.sum
M go.mod
+2, -2
 1@@ -15,11 +15,12 @@ require (
 2 	github.com/gorilla/feeds v1.1.2
 3 	github.com/lib/pq v1.10.9
 4 	github.com/microcosm-cc/bluemonday v1.0.26
 5+	github.com/minio/minio-go/v7 v7.0.63
 6 	github.com/mmcdole/gofeed v1.2.1
 7 	github.com/muesli/reflow v0.3.0
 8 	github.com/neurosnap/go-exif-remove v0.0.0-20221010134343-50d1e3c35577
 9 	github.com/patrickmn/go-cache v2.1.0+incompatible
10-	github.com/picosh/pobj v0.0.0-20240217191723-5a89dec577a1
11+	github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf
12 	github.com/picosh/send v0.0.0-20240217194807-77b972121e63
13 	github.com/sendgrid/sendgrid-go v3.13.0+incompatible
14 	github.com/yuin/goldmark v1.6.0
15@@ -76,7 +77,6 @@ require (
16 	github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
17 	github.com/minio/madmin-go/v3 v3.0.29 // indirect
18 	github.com/minio/md5-simd v1.1.2 // indirect
19-	github.com/minio/minio-go/v7 v7.0.63 // indirect
20 	github.com/minio/sha256-simd v1.0.1 // indirect
21 	github.com/mmcdole/goxpp v1.1.0 // indirect
22 	github.com/mmcloughlin/md4 v0.1.2 // indirect
M go.sum
+2, -2
 1@@ -182,8 +182,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
 2 github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
 3 github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
 4 github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
 5-github.com/picosh/pobj v0.0.0-20240217191723-5a89dec577a1 h1:6aJBn2UsA0pWvwjV6C6/klcMzFUu6PpOfkI5DzHr6xo=
 6-github.com/picosh/pobj v0.0.0-20240217191723-5a89dec577a1/go.mod h1:ILtZ0GOqkozrrGCvyJqCSUIwal2XQqzSfbKCNdS+HyU=
 7+github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf h1:xtr5DoSgoOqbPFnm8p5YjTqrRKVW8KYI0bDwwRiG8yI=
 8+github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf/go.mod h1:ILtZ0GOqkozrrGCvyJqCSUIwal2XQqzSfbKCNdS+HyU=
 9 github.com/picosh/send v0.0.0-20240217194807-77b972121e63 h1:VSSbAejFzj2KBThfVnMcNXQwzHmwjPUridgi29LxihU=
10 github.com/picosh/send v0.0.0-20240217194807-77b972121e63/go.mod h1:1JCq0NVOdTDenQ0/Kd8e4rP80lu06UHJJ+6dQxhcpew=
11 github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
M shared/storage/fs.go
+9, -0
 1@@ -32,3 +32,12 @@ func (s *StorageFS) ServeObject(bucket sst.Bucket, fpath string, opts *ImgProces
 2 	dataURL := fmt.Sprintf("local://%s", filePath)
 3 	return HandleProxy(dataURL, opts)
 4 }
 5+
 6+func (s *StorageFS) GetObjectSize(bucket sst.Bucket, fpath string) (int64, error) {
 7+	fi, err := os.Stat(filepath.Join(bucket.Path, fpath))
 8+	if err != nil {
 9+		return 0, err
10+	}
11+	size := fi.Size()
12+	return size, nil
13+}
M shared/storage/minio.go
+10, -0
 1@@ -1,11 +1,13 @@
 2 package storage
 3 
 4 import (
 5+	"context"
 6 	"fmt"
 7 	"io"
 8 	"os"
 9 	"path/filepath"
10 
11+	"github.com/minio/minio-go/v7"
12 	sst "github.com/picosh/pobj/storage"
13 )
14 
15@@ -32,3 +34,11 @@ func (s *StorageMinio) ServeObject(bucket sst.Bucket, fpath string, opts *ImgPro
16 	dataURL := fmt.Sprintf("s3://%s", filePath)
17 	return HandleProxy(dataURL, opts)
18 }
19+
20+func (s *StorageMinio) GetObjectSize(bucket sst.Bucket, fpath string) (int64, error) {
21+	info, err := s.Client.StatObject(context.Background(), bucket.Name, fpath, minio.StatObjectOptions{})
22+	if err != nil {
23+		return 0, err
24+	}
25+	return info.Size, nil
26+}
M shared/storage/storage.go
+1, -0
1@@ -9,4 +9,5 @@ import (
2 type StorageServe interface {
3 	sst.ObjectStorage
4 	ServeObject(bucket sst.Bucket, fpath string, opts *ImgProcessOpts) (io.ReadCloser, string, error)
5+	GetObjectSize(bucket sst.Bucket, fpath string) (int64, error)
6 }