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:
kim (grufwub) 2021-09-11 20:12:47 +01:00
commit e43a46e982
89 changed files with 9372 additions and 240 deletions

View file

@ -6,11 +6,11 @@ import (
"net/http"
"net/http/httptest"
"git.iim.gay/grufwub/go-store/kv"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -28,7 +28,7 @@ type AccountStandardTestSuite struct {
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
storage blob.Storage
storage *kv.KVStore
federator federation.Federator
processor processing.Processor

View file

@ -26,12 +26,12 @@ import (
"net/http/httptest"
"testing"
"git.iim.gay/grufwub/go-store/kv"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -49,7 +49,7 @@ type ServeFileTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage blob.Storage
storage *kv.KVStore
federator federation.Federator
tc typeutils.TypeConverter
processor processing.Processor
@ -152,7 +152,7 @@ func (suite *ServeFileTestSuite) TestServeOriginalFileSuccessful() {
assert.NoError(suite.T(), err)
assert.NotNil(suite.T(), b)
fileInStorage, err := suite.storage.RetrieveFileFrom(targetAttachment.File.Path)
fileInStorage, err := suite.storage.Get(targetAttachment.File.Path)
assert.NoError(suite.T(), err)
assert.NotNil(suite.T(), fileInStorage)
assert.Equal(suite.T(), b, fileInStorage)

View file

@ -28,13 +28,13 @@ import (
"net/http/httptest"
"testing"
"git.iim.gay/grufwub/go-store/kv"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
mediamodule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -52,7 +52,7 @@ type MediaCreateTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage blob.Storage
storage *kv.KVStore
federator federation.Federator
tc typeutils.TypeConverter
mediaHandler media.Handler
@ -118,7 +118,6 @@ func (suite *MediaCreateTestSuite) TearDownTest() {
*/
func (suite *MediaCreateTestSuite) TestStatusCreatePOSTImageHandlerSuccessful() {
// set up the context for the request
t := suite.testTokens["local_account_1"]
oauthToken := oauth.DBTokenToToken(t)
@ -130,10 +129,15 @@ func (suite *MediaCreateTestSuite) TestStatusCreatePOSTImageHandlerSuccessful()
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
// see what's in storage *before* the request
storageKeysBeforeRequest, err := suite.storage.ListKeys()
storageKeysBeforeRequest := []string{}
iter, err := suite.storage.Iterator(nil)
if err != nil {
panic(err)
}
for iter.Next() {
storageKeysBeforeRequest = append(storageKeysBeforeRequest, iter.Key())
}
iter.Release()
// create the request
buf, w, err := testrig.CreateMultipartFormData("file", "../../../../testrig/media/test-jpeg.jpg", map[string]string{
@ -150,10 +154,15 @@ func (suite *MediaCreateTestSuite) TestStatusCreatePOSTImageHandlerSuccessful()
suite.mediaModule.MediaCreatePOSTHandler(ctx)
// check what's in storage *after* the request
storageKeysAfterRequest, err := suite.storage.ListKeys()
storageKeysAfterRequest := []string{}
iter, err = suite.storage.Iterator(nil)
if err != nil {
panic(err)
}
for iter.Next() {
storageKeysAfterRequest = append(storageKeysAfterRequest, iter.Key())
}
iter.Release()
// check response
suite.EqualValues(http.StatusOK, recorder.Code)

View file

@ -19,10 +19,10 @@
package status_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -41,7 +41,7 @@ type StatusStandardTestSuite struct {
tc typeutils.TypeConverter
federator federation.Federator
processor processing.Processor
storage blob.Storage
storage *kv.KVStore
// standard suite models
testTokens map[string]*gtsmodel.Token

View file

@ -1,11 +1,11 @@
package user_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -24,7 +24,7 @@ type UserStandardTestSuite struct {
tc typeutils.TypeConverter
federator federation.Federator
processor processing.Processor
storage blob.Storage
storage *kv.KVStore
securityModule *security.Module
// standard suite models

View file

@ -1,55 +0,0 @@
package blob
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
// NewInMem returns an in-memory implementation of the Storage interface.
// This is good for testing and whatnot but ***SHOULD ABSOLUTELY NOT EVER
// BE USED IN A PRODUCTION SETTING***, because A) everything will be wiped out
// if you restart the server and B) if you store lots of images your RAM use
// will absolutely go through the roof.
func NewInMem(c *config.Config, log *logrus.Logger) (Storage, error) {
return &inMemStorage{
stored: make(map[string][]byte),
log: log,
}, nil
}
type inMemStorage struct {
stored map[string][]byte
log *logrus.Logger
}
func (s *inMemStorage) StoreFileAt(path string, data []byte) error {
l := s.log.WithField("func", "StoreFileAt")
l.Debugf("storing at path %s", path)
s.stored[path] = data
return nil
}
func (s *inMemStorage) RetrieveFileFrom(path string) ([]byte, error) {
l := s.log.WithField("func", "RetrieveFileFrom")
l.Debugf("retrieving from path %s", path)
d, ok := s.stored[path]
if !ok || len(d) == 0 {
return nil, fmt.Errorf("no data found at path %s", path)
}
return d, nil
}
func (s *inMemStorage) ListKeys() ([]string, error) {
keys := []string{}
for k := range s.stored {
keys = append(keys, k)
}
return keys, nil
}
func (s *inMemStorage) RemoveFileAt(path string) error {
delete(s.stored, path)
return nil
}

View file

@ -1,70 +0,0 @@
package blob
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
// NewLocal returns an implementation of the Storage interface that uses
// the local filesystem for storing and retrieving files, attachments, etc.
func NewLocal(c *config.Config, log *logrus.Logger) (Storage, error) {
return &localStorage{
config: c,
log: log,
}, nil
}
type localStorage struct {
config *config.Config
log *logrus.Logger
}
func (s *localStorage) StoreFileAt(path string, data []byte) error {
l := s.log.WithField("func", "StoreFileAt")
l.Debugf("storing at path %s", path)
components := strings.Split(path, "/")
dir := strings.Join(components[0:len(components)-1], "/")
if err := os.MkdirAll(dir, 0777); err != nil {
return fmt.Errorf("error writing file at %s: %s", path, err)
}
if err := os.WriteFile(path, data, 0777); err != nil {
return fmt.Errorf("error writing file at %s: %s", path, err)
}
return nil
}
func (s *localStorage) RetrieveFileFrom(path string) ([]byte, error) {
l := s.log.WithField("func", "RetrieveFileFrom")
l.Debugf("retrieving from path %s", path)
b, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error reading file at %s: %s", path, err)
}
return b, nil
}
func (s *localStorage) ListKeys() ([]string, error) {
keys := []string{}
err := filepath.Walk(s.config.StorageConfig.BasePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
keys = append(keys, path)
}
return nil
})
if err != nil {
return nil, err
}
return keys, nil
}
func (s *localStorage) RemoveFileAt(path string) error {
return os.Remove(path)
}

View file

@ -1,29 +0,0 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package blob
// Storage is an interface for storing and retrieving blobs
// such as images, videos, and any other attachments/documents
// that shouldn't be stored in a database.
type Storage interface {
StoreFileAt(path string, data []byte) error
RetrieveFileFrom(path string) ([]byte, error)
ListKeys() ([]string, error)
RemoveFileAt(path string) error
}

View file

@ -8,6 +8,7 @@ import (
"os/signal"
"syscall"
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
@ -32,7 +33,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
@ -76,7 +76,8 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
return fmt.Errorf("error creating router: %s", err)
}
storageBackend, err := blob.NewLocal(c, log)
// Create new storage backend
store, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
if err != nil {
return fmt.Errorf("error creating storage backend: %s", err)
}
@ -86,11 +87,11 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c, log)
// build backend handlers
mediaHandler := media.New(c, dbService, storageBackend, log)
mediaHandler := media.New(c, dbService, store, log)
oauthServer := oauth.New(dbService, log)
transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient, log)
federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter, mediaHandler)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storageBackend, timelineManager, dbService, log)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, store, timelineManager, dbService, log)
if err := processor.Start(ctx); err != nil {
return fmt.Errorf("error starting processor: %s", err)
}

View file

@ -24,11 +24,11 @@ import (
"io"
"net/http"
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
@ -42,7 +42,7 @@ type DereferencerStandardTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage blob.Storage
storage *kv.KVStore
testRemoteStatuses map[string]vocab.ActivityStreamsNote
testRemoteAccounts map[string]vocab.ActivityStreamsPerson

View file

@ -24,13 +24,13 @@ import (
"net/http/httptest"
"testing"
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/pub"
"github.com/go-fed/httpsig"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -45,7 +45,7 @@ type ProtocolTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage blob.Storage
storage *kv.KVStore
typeConverter typeutils.TypeConverter
accounts map[string]*gtsmodel.Account
activities map[string]testrig.ActivityWithSignature
@ -65,7 +65,6 @@ func (suite *ProtocolTestSuite) SetupSuite() {
func (suite *ProtocolTestSuite) SetupTest() {
testrig.StandardDBSetup(suite.db, suite.accounts)
}
// TearDownTest drops tables to make sure there's no data in the db
@ -75,7 +74,6 @@ func (suite *ProtocolTestSuite) TearDownTest() {
// make sure PostInboxRequestBodyHook properly sets the inbox username and activity on the context
func (suite *ProtocolTestSuite) TestPostInboxRequestBodyHook() {
// the activity we're gonna use
activity := suite.activities["dm_for_zork"]
@ -106,7 +104,6 @@ func (suite *ProtocolTestSuite) TestPostInboxRequestBodyHook() {
}
func (suite *ProtocolTestSuite) TestAuthenticatePostInbox() {
// the activity we're gonna use
activity := suite.activities["dm_for_zork"]
sendingAccount := suite.accounts["remote_account_1"]

View file

@ -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")
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -19,10 +19,10 @@
package account_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/pub"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -43,7 +43,7 @@ type AccountStandardTestSuite struct {
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
storage blob.Storage
storage *kv.KVStore
mediaHandler media.Handler
oauthServer oauth.Server
fromClientAPIChan chan messages.FromClientAPI

View file

@ -24,14 +24,14 @@ func (p *processor) Delete(ctx context.Context, mediaAttachmentID string) gtserr
// delete the thumbnail from storage
if attachment.Thumbnail.Path != "" {
if err := p.storage.RemoveFileAt(attachment.Thumbnail.Path); err != nil {
if err := p.store.Delete(attachment.Thumbnail.Path); err != nil {
errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", attachment.Thumbnail.Path, err))
}
}
// delete the file from storage
if attachment.File.Path != "" {
if err := p.storage.RemoveFileAt(attachment.File.Path); err != nil {
if err := p.store.Delete(attachment.File.Path); err != nil {
errs = append(errs, fmt.Sprintf("remove file at path %s: %s", attachment.File.Path, err))
}
}

View file

@ -110,7 +110,7 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
}
}
bytes, err := p.storage.RetrieveFileFrom(storagePath)
bytes, err := p.store.Get(storagePath)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
}

View file

@ -21,9 +21,9 @@ package media
import (
"context"
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
@ -47,18 +47,18 @@ type processor struct {
tc typeutils.TypeConverter
config *config.Config
mediaHandler media.Handler
storage blob.Storage
store *kv.KVStore
db db.DB
log *logrus.Logger
}
// New returns a new media processor.
func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage blob.Storage, config *config.Config, log *logrus.Logger) Processor {
func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, store *kv.KVStore, config *config.Config, log *logrus.Logger) Processor {
return &processor{
tc: tc,
config: config,
mediaHandler: mediaHandler,
storage: storage,
store: store,
db: db,
log: log,
}

View file

@ -23,9 +23,9 @@ import (
"net/http"
"net/url"
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -234,7 +234,7 @@ type processor struct {
tc typeutils.TypeConverter
oauthServer oauth.Server
mediaHandler media.Handler
storage blob.Storage
store *kv.KVStore
timelineManager timeline.Manager
db db.DB
filter visibility.Filter
@ -251,8 +251,7 @@ type processor struct {
}
// NewProcessor returns a new Processor that uses the given federator and logger
func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage blob.Storage, timelineManager timeline.Manager, db db.DB, log *logrus.Logger) Processor {
func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, store *kv.KVStore, timelineManager timeline.Manager, db db.DB, log *logrus.Logger) Processor {
fromClientAPI := make(chan messages.FromClientAPI, 1000)
fromFederator := make(chan messages.FromFederator, 1000)
@ -260,7 +259,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f
streamingProcessor := streaming.New(db, tc, oauthServer, config, log)
accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config, log)
adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config, log)
mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config, log)
mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, store, config, log)
return &processor{
fromClientAPI: fromClientAPI,
@ -272,7 +271,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f
tc: tc,
oauthServer: oauthServer,
mediaHandler: mediaHandler,
storage: storage,
store: store,
timelineManager: timelineManager,
db: db,
filter: visibility.NewFilter(db, log),

View file

@ -21,9 +21,9 @@ package processing_test
import (
"context"
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@ -43,7 +43,7 @@ type ProcessingStandardTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage blob.Storage
store *kv.KVStore
typeconverter typeutils.TypeConverter
transportController transport.Controller
federator federation.Federator
@ -89,12 +89,12 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
suite.storage = testrig.NewTestStorage()
suite.store = testrig.NewTestStorage()
suite.typeconverter = testrig.NewTestTypeConverter(suite.db)
suite.transportController = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage)
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.store)
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.store)
suite.timelineManager = testrig.NewTestTimelineManager(suite.db)
suite.processor = processing.NewProcessor(
@ -103,13 +103,13 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.federator,
suite.oauthServer,
suite.mediaHandler,
suite.storage,
suite.store,
suite.timelineManager,
suite.db,
suite.log)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
testrig.StandardStorageSetup(suite.store, "../../testrig/media")
if err := suite.processor.Start(context.Background()); err != nil {
panic(err)
}
@ -117,7 +117,7 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
func (suite *ProcessingStandardTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
testrig.StandardStorageTeardown(suite.storage)
testrig.StandardStorageTeardown(suite.store)
if err := suite.processor.Stop(); err != nil {
panic(err)
}