forked from mirrors/gotosocial
rename KVStore uses as storage to differentiate between upcoming store package
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
parent
e43a46e982
commit
7f36688643
9 changed files with 36 additions and 36 deletions
|
@ -76,8 +76,8 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
|
||||||
return fmt.Errorf("error creating router: %s", err)
|
return fmt.Errorf("error creating router: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new storage backend
|
// Open the storage backend
|
||||||
store, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
|
storage, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating storage backend: %s", err)
|
return fmt.Errorf("error creating storage backend: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,11 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
|
||||||
timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c, log)
|
timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c, log)
|
||||||
|
|
||||||
// build backend handlers
|
// build backend handlers
|
||||||
mediaHandler := media.New(c, dbService, store, log)
|
mediaHandler := media.New(c, dbService, storage, log)
|
||||||
oauthServer := oauth.New(dbService, log)
|
oauthServer := oauth.New(dbService, log)
|
||||||
transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient, log)
|
transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient, log)
|
||||||
federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter, mediaHandler)
|
federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter, mediaHandler)
|
||||||
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, store, timelineManager, dbService, log)
|
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService, log)
|
||||||
if err := processor.Start(ctx); err != nil {
|
if err := processor.Start(ctx); err != nil {
|
||||||
return fmt.Errorf("error starting processor: %s", err)
|
return fmt.Errorf("error starting processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,16 +86,16 @@ type Handler interface {
|
||||||
type mediaHandler struct {
|
type mediaHandler struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
db db.DB
|
db db.DB
|
||||||
store *kv.KVStore
|
storage *kv.KVStore
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new handler with the given config, db, storage, and logger
|
// New returns a new handler with the given config, db, storage, and logger
|
||||||
func New(config *config.Config, database db.DB, store *kv.KVStore, log *logrus.Logger) Handler {
|
func New(config *config.Config, database db.DB, storage *kv.KVStore, log *logrus.Logger) Handler {
|
||||||
return &mediaHandler{
|
return &mediaHandler{
|
||||||
config: config,
|
config: config,
|
||||||
db: database,
|
db: database,
|
||||||
store: store,
|
storage: storage,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,12 +257,12 @@ func (mh *mediaHandler) ProcessLocalEmoji(ctx context.Context, emojiBytes []byte
|
||||||
emojiStaticPath := fmt.Sprintf("%s/%s/%s/%s/%s.png", mh.config.StorageConfig.BasePath, 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 emoji
|
// Store the original emoji
|
||||||
if err := mh.store.Put(emojiPath, original.image); err != nil {
|
if err := mh.storage.Put(emojiPath, original.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the static emoji
|
// Store the static emoji
|
||||||
if err := mh.store.Put(emojiStaticPath, static.image); err != nil {
|
if err := mh.storage.Put(emojiStaticPath, static.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,13 @@ func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string
|
||||||
|
|
||||||
// we store the original...
|
// we store the original...
|
||||||
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Original, newMediaID, extension)
|
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Original, newMediaID, extension)
|
||||||
if err := mh.store.Put(originalPath, original.image); err != nil {
|
if err := mh.storage.Put(originalPath, original.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// and a thumbnail...
|
// and a thumbnail...
|
||||||
smallPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Small, newMediaID, extension)
|
smallPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, accountID, mediaType, Small, newMediaID, extension)
|
||||||
if err := mh.store.Put(smallPath, small.image); err != nil {
|
if err := mh.storage.Put(smallPath, small.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,13 @@ func (mh *mediaHandler) processImageAttachment(data []byte, minAttachment *gtsmo
|
||||||
|
|
||||||
// we store the original...
|
// we store the original...
|
||||||
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, minAttachment.AccountID, Attachment, Original, newMediaID, extension)
|
originalPath := fmt.Sprintf("%s/%s/%s/%s/%s.%s", mh.config.StorageConfig.BasePath, minAttachment.AccountID, Attachment, Original, newMediaID, extension)
|
||||||
if err := mh.store.Put(originalPath, original.image); err != nil {
|
if err := mh.storage.Put(originalPath, original.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// and a thumbnail...
|
// 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
|
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.store.Put(smallPath, small.image); err != nil {
|
if err := mh.storage.Put(smallPath, small.image); err != nil {
|
||||||
return nil, fmt.Errorf("storage error: %s", err)
|
return nil, fmt.Errorf("storage error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,14 @@ func (p *processor) Delete(ctx context.Context, mediaAttachmentID string) gtserr
|
||||||
|
|
||||||
// delete the thumbnail from storage
|
// delete the thumbnail from storage
|
||||||
if attachment.Thumbnail.Path != "" {
|
if attachment.Thumbnail.Path != "" {
|
||||||
if err := p.store.Delete(attachment.Thumbnail.Path); err != nil {
|
if err := p.storage.Delete(attachment.Thumbnail.Path); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", attachment.Thumbnail.Path, err))
|
errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", attachment.Thumbnail.Path, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the file from storage
|
// delete the file from storage
|
||||||
if attachment.File.Path != "" {
|
if attachment.File.Path != "" {
|
||||||
if err := p.store.Delete(attachment.File.Path); err != nil {
|
if err := p.storage.Delete(attachment.File.Path); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("remove file at path %s: %s", attachment.File.Path, err))
|
errs = append(errs, fmt.Sprintf("remove file at path %s: %s", attachment.File.Path, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ func (p *processor) GetFile(ctx context.Context, account *gtsmodel.Account, form
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := p.store.Get(storagePath)
|
bytes, err := p.storage.Get(storagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
|
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,18 @@ type processor struct {
|
||||||
tc typeutils.TypeConverter
|
tc typeutils.TypeConverter
|
||||||
config *config.Config
|
config *config.Config
|
||||||
mediaHandler media.Handler
|
mediaHandler media.Handler
|
||||||
store *kv.KVStore
|
storage *kv.KVStore
|
||||||
db db.DB
|
db db.DB
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new media processor.
|
// New returns a new media processor.
|
||||||
func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, store *kv.KVStore, config *config.Config, log *logrus.Logger) Processor {
|
func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage *kv.KVStore, config *config.Config, log *logrus.Logger) Processor {
|
||||||
return &processor{
|
return &processor{
|
||||||
tc: tc,
|
tc: tc,
|
||||||
config: config,
|
config: config,
|
||||||
mediaHandler: mediaHandler,
|
mediaHandler: mediaHandler,
|
||||||
store: store,
|
storage: storage,
|
||||||
db: db,
|
db: db,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,7 @@ type processor struct {
|
||||||
tc typeutils.TypeConverter
|
tc typeutils.TypeConverter
|
||||||
oauthServer oauth.Server
|
oauthServer oauth.Server
|
||||||
mediaHandler media.Handler
|
mediaHandler media.Handler
|
||||||
store *kv.KVStore
|
storage *kv.KVStore
|
||||||
timelineManager timeline.Manager
|
timelineManager timeline.Manager
|
||||||
db db.DB
|
db db.DB
|
||||||
filter visibility.Filter
|
filter visibility.Filter
|
||||||
|
@ -251,7 +251,7 @@ type processor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProcessor returns a new Processor that uses the given federator and logger
|
// 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, store *kv.KVStore, 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, storage *kv.KVStore, timelineManager timeline.Manager, db db.DB, log *logrus.Logger) Processor {
|
||||||
fromClientAPI := make(chan messages.FromClientAPI, 1000)
|
fromClientAPI := make(chan messages.FromClientAPI, 1000)
|
||||||
fromFederator := make(chan messages.FromFederator, 1000)
|
fromFederator := make(chan messages.FromFederator, 1000)
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f
|
||||||
streamingProcessor := streaming.New(db, tc, oauthServer, config, log)
|
streamingProcessor := streaming.New(db, tc, oauthServer, config, log)
|
||||||
accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config, log)
|
accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config, log)
|
||||||
adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config, log)
|
adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config, log)
|
||||||
mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, store, config, log)
|
mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config, log)
|
||||||
|
|
||||||
return &processor{
|
return &processor{
|
||||||
fromClientAPI: fromClientAPI,
|
fromClientAPI: fromClientAPI,
|
||||||
|
@ -271,7 +271,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f
|
||||||
tc: tc,
|
tc: tc,
|
||||||
oauthServer: oauthServer,
|
oauthServer: oauthServer,
|
||||||
mediaHandler: mediaHandler,
|
mediaHandler: mediaHandler,
|
||||||
store: store,
|
storage: storage,
|
||||||
timelineManager: timelineManager,
|
timelineManager: timelineManager,
|
||||||
db: db,
|
db: db,
|
||||||
filter: visibility.NewFilter(db, log),
|
filter: visibility.NewFilter(db, log),
|
||||||
|
|
|
@ -43,7 +43,7 @@ type ProcessingStandardTestSuite struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
db db.DB
|
db db.DB
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
store *kv.KVStore
|
storage *kv.KVStore
|
||||||
typeconverter typeutils.TypeConverter
|
typeconverter typeutils.TypeConverter
|
||||||
transportController transport.Controller
|
transportController transport.Controller
|
||||||
federator federation.Federator
|
federator federation.Federator
|
||||||
|
@ -89,12 +89,12 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
|
||||||
suite.config = testrig.NewTestConfig()
|
suite.config = testrig.NewTestConfig()
|
||||||
suite.db = testrig.NewTestDB()
|
suite.db = testrig.NewTestDB()
|
||||||
suite.log = testrig.NewTestLog()
|
suite.log = testrig.NewTestLog()
|
||||||
suite.store = testrig.NewTestStorage()
|
suite.storage = testrig.NewTestStorage()
|
||||||
suite.typeconverter = testrig.NewTestTypeConverter(suite.db)
|
suite.typeconverter = testrig.NewTestTypeConverter(suite.db)
|
||||||
suite.transportController = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
|
suite.transportController = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
|
||||||
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.store)
|
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage)
|
||||||
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
||||||
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.store)
|
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
|
||||||
suite.timelineManager = testrig.NewTestTimelineManager(suite.db)
|
suite.timelineManager = testrig.NewTestTimelineManager(suite.db)
|
||||||
|
|
||||||
suite.processor = processing.NewProcessor(
|
suite.processor = processing.NewProcessor(
|
||||||
|
@ -103,13 +103,13 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
|
||||||
suite.federator,
|
suite.federator,
|
||||||
suite.oauthServer,
|
suite.oauthServer,
|
||||||
suite.mediaHandler,
|
suite.mediaHandler,
|
||||||
suite.store,
|
suite.storage,
|
||||||
suite.timelineManager,
|
suite.timelineManager,
|
||||||
suite.db,
|
suite.db,
|
||||||
suite.log)
|
suite.log)
|
||||||
|
|
||||||
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
||||||
testrig.StandardStorageSetup(suite.store, "../../testrig/media")
|
testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
|
||||||
if err := suite.processor.Start(context.Background()); err != nil {
|
if err := suite.processor.Start(context.Background()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
|
||||||
|
|
||||||
func (suite *ProcessingStandardTestSuite) TearDownTest() {
|
func (suite *ProcessingStandardTestSuite) TearDownTest() {
|
||||||
testrig.StandardDBTeardown(suite.db)
|
testrig.StandardDBTeardown(suite.db)
|
||||||
testrig.StandardStorageTeardown(suite.store)
|
testrig.StandardStorageTeardown(suite.storage)
|
||||||
if err := suite.processor.Stop(); err != nil {
|
if err := suite.processor.Stop(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue