diff options
Diffstat (limited to 'internal/processing/media/create.go')
-rw-r--r-- | internal/processing/media/create.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/internal/processing/media/create.go b/internal/processing/media/create.go index 648e4d46a..43162f3f6 100644 --- a/internal/processing/media/create.go +++ b/internal/processing/media/create.go @@ -24,6 +24,7 @@ import ( "errors" "fmt" "io" + "time" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -45,25 +46,30 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form return nil, errors.New("could not read provided attachment: size 0 bytes") } - // allow the mediaHandler to work its magic of processing the attachment bytes, and putting them in whatever storage backend we're using - attachment, err := p.mediaHandler.ProcessAttachment(ctx, buf.Bytes(), account.ID, "") + // now parse the focus parameter + focusx, focusy, err := parseFocus(form.Focus) if err != nil { - return nil, fmt.Errorf("error reading attachment: %s", err) + return nil, fmt.Errorf("couldn't parse attachment focus: %s", err) } - // now we need to add extra fields that the attachment processor doesn't know (from the form) - // TODO: handle this inside mediaHandler.ProcessAttachment (just pass more params to it) - - // first description - attachment.Description = text.RemoveHTML(form.Description) // remove any HTML from the image description + minAttachment := >smodel.MediaAttachment{ + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + AccountID: account.ID, + Description: text.RemoveHTML(form.Description), + FileMeta: gtsmodel.FileMeta{ + Focus: gtsmodel.Focus{ + X: focusx, + Y: focusy, + }, + }, + } - // now parse the focus parameter - focusx, focusy, err := parseFocus(form.Focus) + // allow the mediaHandler to work its magic of processing the attachment bytes, and putting them in whatever storage backend we're using + attachment, err := p.mediaHandler.ProcessAttachment(ctx, buf.Bytes(), minAttachment) if err != nil { - return nil, err + return nil, fmt.Errorf("error reading attachment: %s", err) } - attachment.FileMeta.Focus.X = focusx - attachment.FileMeta.Focus.Y = focusy // prepare the frontend representation now -- if there are any errors here at least we can bail without // having already put something in the database and then having to clean it up again (eugh) |