mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 10:02:24 -05:00
add git.iim.gay/grufwub/go-store for storage backend, replacing blob.Storage
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
parent
ab32ce642b
commit
e43a46e982
89 changed files with 9372 additions and 240 deletions
|
|
@ -26,8 +26,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"git.iim.gay/grufwub/go-store/kv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/blob"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
|
|
@ -84,19 +84,19 @@ type Handler interface {
|
|||
}
|
||||
|
||||
type mediaHandler struct {
|
||||
config *config.Config
|
||||
db db.DB
|
||||
storage blob.Storage
|
||||
log *logrus.Logger
|
||||
config *config.Config
|
||||
db db.DB
|
||||
store *kv.KVStore
|
||||
log *logrus.Logger
|
||||
}
|
||||
|
||||
// New returns a new handler with the given config, db, storage, and logger
|
||||
func New(config *config.Config, database db.DB, storage blob.Storage, log *logrus.Logger) Handler {
|
||||
func New(config *config.Config, database db.DB, store *kv.KVStore, log *logrus.Logger) Handler {
|
||||
return &mediaHandler{
|
||||
config: config,
|
||||
db: database,
|
||||
storage: storage,
|
||||
log: log,
|
||||
config: config,
|
||||
db: database,
|
||||
store: store,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,13 +256,13 @@ func (mh *mediaHandler) ProcessLocalEmoji(ctx context.Context, emojiBytes []byte
|
|||
emojiStaticURL := fmt.Sprintf("%s/%s/%s/%s/%s.png", URLbase, instanceAccount.ID, Emoji, Static, newEmojiID)
|
||||
emojiStaticPath := fmt.Sprintf("%s/%s/%s/%s/%s.png", mh.config.StorageConfig.BasePath, instanceAccount.ID, Emoji, Static, newEmojiID)
|
||||
|
||||
// store the original
|
||||
if err := mh.storage.StoreFileAt(emojiPath, original.image); err != nil {
|
||||
// Store the original emoji
|
||||
if err := mh.store.Put(emojiPath, original.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
// store the static
|
||||
if err := mh.storage.StoreFileAt(emojiStaticPath, static.image); err != nil {
|
||||
// Store the static emoji
|
||||
if err := mh.store.Put(emojiStaticPath, static.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +293,6 @@ func (mh *mediaHandler) ProcessLocalEmoji(ctx context.Context, emojiBytes []byte
|
|||
}
|
||||
|
||||
func (mh *mediaHandler) ProcessRemoteHeaderOrAvatar(ctx context.Context, t transport.Transport, currentAttachment *gtsmodel.MediaAttachment, accountID string) (*gtsmodel.MediaAttachment, error) {
|
||||
|
||||
if !currentAttachment.Header && !currentAttachment.Avatar {
|
||||
return nil, errors.New("provided attachment was set to neither header nor avatar")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,13 +85,13 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
|||
|
||||
// we store the original...
|
||||
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Original, newMediaID, extension)
|
||||
if err := mh.storage.StoreFileAt(originalPath, original.image); err != nil {
|
||||
if err := mh.store.Put(originalPath, original.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
// and a thumbnail...
|
||||
smallPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Small, newMediaID, extension)
|
||||
if err := mh.storage.StoreFileAt(smallPath, small.image); err != nil {
|
||||
if err := mh.store.Put(smallPath, small.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@ func (mh *mediaHandler) processImageAttachment(data []byte, minAttachment *gtsmo
|
|||
|
||||
// we store the original...
|
||||
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, minAttachment.AccountID, Attachment, Original, newMediaID, extension)
|
||||
if err := mh.storage.StoreFileAt(originalPath, original.image); err != nil {
|
||||
if err := mh.store.Put(originalPath, original.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
// and a thumbnail...
|
||||
smallPath := fmt.Sprintf("%s/%s/%s/%s/%s.jpeg", mh.config.StorageConfig.BasePath, minAttachment.AccountID, Attachment, Small, newMediaID) // all thumbnails/smalls are encoded as jpeg
|
||||
if err := mh.storage.StoreFileAt(smallPath, small.image); err != nil {
|
||||
if err := mh.store.Put(smallPath, small.image); err != nil {
|
||||
return nil, fmt.Errorf("storage error: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -130,5 +130,4 @@ func (mh *mediaHandler) processImageAttachment(data []byte, minAttachment *gtsmo
|
|||
}
|
||||
|
||||
return attachment, nil
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue