repos / pico

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

commit
af59569
parent
c8daace
author
Eric Bower
date
2024-11-09 02:28:44 +0000 UTC
refactor(pgs): use pobj/storage
6 files changed,  +9, -31
M pgs/cli.go
+2, -2
 1@@ -13,8 +13,8 @@ import (
 2 	"github.com/charmbracelet/lipgloss/table"
 3 	"github.com/picosh/pico/db"
 4 	"github.com/picosh/pico/shared"
 5-	"github.com/picosh/pico/shared/storage"
 6 	"github.com/picosh/pico/tui/common"
 7+	sst "github.com/picosh/pobj/storage"
 8 	"github.com/picosh/utils"
 9 )
10 
11@@ -120,7 +120,7 @@ type Cmd struct {
12 	User    *db.User
13 	Session utils.CmdSession
14 	Log     *slog.Logger
15-	Store   storage.StorageServe
16+	Store   sst.ObjectStorage
17 	Dbpool  db.DB
18 	Write   bool
19 	Styles  common.Styles
M pgs/uploader.go
+7, -4
 1@@ -17,7 +17,6 @@ import (
 2 	"github.com/charmbracelet/wish"
 3 	"github.com/picosh/pico/db"
 4 	"github.com/picosh/pico/shared"
 5-	"github.com/picosh/pico/shared/storage"
 6 	"github.com/picosh/pobj"
 7 	sst "github.com/picosh/pobj/storage"
 8 	sendutils "github.com/picosh/send/utils"
 9@@ -100,10 +99,10 @@ type FileData struct {
10 type UploadAssetHandler struct {
11 	DBPool  db.DB
12 	Cfg     *shared.ConfigSite
13-	Storage storage.StorageServe
14+	Storage sst.ObjectStorage
15 }
16 
17-func NewUploadAssetHandler(dbpool db.DB, cfg *shared.ConfigSite, storage storage.StorageServe) *UploadAssetHandler {
18+func NewUploadAssetHandler(dbpool db.DB, cfg *shared.ConfigSite, storage sst.ObjectStorage) *UploadAssetHandler {
19 	return &UploadAssetHandler{
20 		DBPool:  dbpool,
21 		Cfg:     cfg,
22@@ -317,7 +316,11 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (s
23 	// calculate the filsize difference between the same file already
24 	// stored and the updated file being uploaded
25 	assetFilename := shared.GetAssetFileName(entry)
26-	curFileSize, _ := h.Storage.GetObjectSize(bucket, assetFilename)
27+	_, info, _ := h.Storage.GetObject(bucket, assetFilename)
28+	var curFileSize int64
29+	if info != nil {
30+		curFileSize = info.Size
31+	}
32 
33 	denylist := getDenylist(s)
34 	if denylist == nil {
M shared/storage/fs.go
+0, -9
 1@@ -32,12 +32,3 @@ 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/memory.go
+0, -5
1@@ -22,8 +22,3 @@ func (s *StorageMemory) ServeObject(bucket sst.Bucket, fpath string, opts *ImgPr
2 	obj, _, err := s.GetObject(bucket, fpath)
3 	return obj, GetMimeType(fpath), err
4 }
5-
6-func (s *StorageMemory) GetObjectSize(bucket sst.Bucket, fpath string) (int64, error) {
7-	_, info, err := s.GetObject(bucket, fpath)
8-	return info.Size, err
9-}
M shared/storage/minio.go
+0, -10
 1@@ -1,13 +1,11 @@
 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@@ -34,11 +32,3 @@ 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
+0, -1
1@@ -9,5 +9,4 @@ 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 }