[chore] deinterface the typeutils.Converter and update to use state structure (#2217)

* update typeconverter to use state structure

* deinterface the typeutils.TypeConverter -> typeutils.Converter

* finish copying over old type converter code comments

* fix cherry-pick merge issues, fix tests pointing to old typeutils interface type still
This commit is contained in:
kim 2023-09-23 17:44:11 +01:00 committed by GitHub
commit 8f67dd583d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
119 changed files with 611 additions and 742 deletions

View file

@ -56,7 +56,7 @@ func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorUnprocessableEntity(err)
}
apiAttachment, err := p.tc.AttachmentToAPIAttachment(ctx, attachment)
apiAttachment, err := p.converter.AttachmentToAPIAttachment(ctx, attachment)
if err != nil {
err := fmt.Errorf("error parsing media attachment to frontend type: %s", err)
return nil, gtserror.NewErrorInternalError(err)

View file

@ -39,7 +39,7 @@ func (p *Processor) GetCustomEmojis(ctx context.Context) ([]*apimodel.Emoji, gts
apiEmojis := make([]*apimodel.Emoji, 0, len(emojis))
for _, gtsEmoji := range emojis {
apiEmoji, err := p.tc.EmojiToAPIEmoji(ctx, gtsEmoji)
apiEmoji, err := p.converter.EmojiToAPIEmoji(ctx, gtsEmoji)
if err != nil {
log.Errorf(ctx, "error converting emoji with id %s: %s", gtsEmoji.ID, err)
continue

View file

@ -42,7 +42,7 @@ func (p *Processor) Get(ctx context.Context, account *gtsmodel.Account, mediaAtt
return nil, gtserror.NewErrorNotFound(errors.New("attachment not owned by requesting account"))
}
a, err := p.tc.AttachmentToAPIAttachment(ctx, attachment)
a, err := p.converter.AttachmentToAPIAttachment(ctx, attachment)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error converting attachment: %s", err))
}

View file

@ -26,16 +26,16 @@ import (
type Processor struct {
state *state.State
tc typeutils.TypeConverter
converter *typeutils.Converter
mediaManager *media.Manager
transportController transport.Controller
}
// New returns a new media processor.
func New(state *state.State, tc typeutils.TypeConverter, mediaManager *media.Manager, transportController transport.Controller) Processor {
func New(state *state.State, converter *typeutils.Converter, mediaManager *media.Manager, transportController transport.Controller) Processor {
return Processor{
state: state,
tc: tc,
converter: converter,
mediaManager: mediaManager,
transportController: transportController,
}

View file

@ -34,7 +34,7 @@ type MediaStandardTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
tc typeutils.TypeConverter
tc *typeutils.Converter
storage *storage.Driver
state state.State
mediaManager *media.Manager
@ -73,7 +73,7 @@ func (suite *MediaStandardTestSuite) SetupTest() {
suite.db = testrig.NewTestDB(&suite.state)
suite.state.DB = suite.db
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.tc = typeutils.NewConverter(&suite.state)
suite.storage = testrig.NewInMemoryStorage()
suite.state.Storage = suite.storage
suite.mediaManager = testrig.NewTestMediaManager(&suite.state)

View file

@ -49,7 +49,7 @@ func (p *Processor) Unattach(ctx context.Context, account *gtsmodel.Account, med
return nil, gtserror.NewErrorNotFound(fmt.Errorf("db error updating attachment: %s", err))
}
a, err := p.tc.AttachmentToAPIAttachment(ctx, attachment)
a, err := p.converter.AttachmentToAPIAttachment(ctx, attachment)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error converting attachment: %s", err))
}

View file

@ -65,7 +65,7 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, media
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error updating media: %s", err))
}
a, err := p.tc.AttachmentToAPIAttachment(ctx, attachment)
a, err := p.converter.AttachmentToAPIAttachment(ctx, attachment)
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error converting attachment: %s", err))
}