Skip to content

Commit

Permalink
rename KVStore uses as storage to differentiate between upcoming stor…
Browse files Browse the repository at this point in the history
…e package

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
  • Loading branch information
NyaaaWhatsUpDoc committed Sep 11, 2021
1 parent e43a46e commit 7f36688
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions internal/cliactions/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
return fmt.Errorf("error creating router: %s", err)
}

// Create new storage backend
store, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
// Open the storage backend
storage, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
if err != nil {
return fmt.Errorf("error creating storage backend: %s", err)
}
Expand All @@ -87,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, store, log)
mediaHandler := media.New(c, dbService, storage, 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, store, timelineManager, dbService, log)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService, log)
if err := processor.Start(ctx); err != nil {
return fmt.Errorf("error starting processor: %s", err)
}
Expand Down
22 changes: 11 additions & 11 deletions internal/media/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ type Handler interface {
}

type mediaHandler struct {
config *config.Config
db db.DB
store *kv.KVStore
log *logrus.Logger
config *config.Config
db db.DB
storage *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, store *kv.KVStore, log *logrus.Logger) Handler {
func New(config *config.Config, database db.DB, storage *kv.KVStore, log *logrus.Logger) Handler {
return &mediaHandler{
config: config,
db: database,
store: store,
log: log,
config: config,
db: database,
storage: storage,
log: log,
}
}

Expand Down Expand Up @@ -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)

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

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

Expand Down
4 changes: 2 additions & 2 deletions internal/media/processicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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)
}

// and a thumbnail...
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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/media/processimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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)
}

// 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.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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/processing/media/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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))
}
}

// delete the file from storage
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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/processing/media/getfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
}
Expand Down
6 changes: 3 additions & 3 deletions internal/processing/media/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ type processor struct {
tc typeutils.TypeConverter
config *config.Config
mediaHandler media.Handler
store *kv.KVStore
storage *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, 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{
tc: tc,
config: config,
mediaHandler: mediaHandler,
store: store,
storage: storage,
db: db,
log: log,
}
Expand Down
8 changes: 4 additions & 4 deletions internal/processing/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ type processor struct {
tc typeutils.TypeConverter
oauthServer oauth.Server
mediaHandler media.Handler
store *kv.KVStore
storage *kv.KVStore
timelineManager timeline.Manager
db db.DB
filter visibility.Filter
Expand All @@ -251,15 +251,15 @@ 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, 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)
fromFederator := make(chan messages.FromFederator, 1000)

statusProcessor := status.New(db, tc, config, fromClientAPI, log)
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, store, config, log)
mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config, log)

return &processor{
fromClientAPI: fromClientAPI,
Expand All @@ -271,7 +271,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f
tc: tc,
oauthServer: oauthServer,
mediaHandler: mediaHandler,
store: store,
storage: storage,
timelineManager: timelineManager,
db: db,
filter: visibility.NewFilter(db, log),
Expand Down
14 changes: 7 additions & 7 deletions internal/processing/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ProcessingStandardTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
store *kv.KVStore
storage *kv.KVStore
typeconverter typeutils.TypeConverter
transportController transport.Controller
federator federation.Federator
Expand Down Expand Up @@ -89,12 +89,12 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
suite.store = testrig.NewTestStorage()
suite.storage = 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.store)
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage)
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.processor = processing.NewProcessor(
Expand All @@ -103,21 +103,21 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.federator,
suite.oauthServer,
suite.mediaHandler,
suite.store,
suite.storage,
suite.timelineManager,
suite.db,
suite.log)

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 {
panic(err)
}
}

func (suite *ProcessingStandardTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
testrig.StandardStorageTeardown(suite.store)
testrig.StandardStorageTeardown(suite.storage)
if err := suite.processor.Stop(); err != nil {
panic(err)
}
Expand Down

0 comments on commit 7f36688

Please sign in to comment.