diff options
author | 2021-09-04 14:02:01 +0200 | |
---|---|---|
committer | 2021-09-04 14:02:01 +0200 | |
commit | 2b14b208025e5f7e57f71dcaba6d396081bdc54b (patch) | |
tree | 0ace50114ac9ac441b361a92216a57bdc6ae40d7 /internal/processing | |
parent | tests + announce notification fix (#193) (diff) | |
download | gotosocial-2b14b208025e5f7e57f71dcaba6d396081bdc54b.tar.xz |
rework media processing a little bit (#191)
* rework media processing a little bit
* review changes
Diffstat (limited to 'internal/processing')
-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) |