mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 16:52:25 -05:00
further refinements
This commit is contained in:
parent
7ebe0f6a15
commit
c2ff8f392b
4 changed files with 133 additions and 133 deletions
|
|
@ -24,11 +24,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||
)
|
||||
|
||||
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.AttachmentRequest) (*apimodel.Attachment, error) {
|
||||
|
|
@ -46,29 +44,15 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form
|
|||
return nil, errors.New("could not read provided attachment: size 0 bytes")
|
||||
}
|
||||
|
||||
// now parse the focus parameter
|
||||
focusx, focusy, err := parseFocus(form.Focus)
|
||||
// process the media and load it immediately
|
||||
media, err := p.mediaManager.ProcessMedia(ctx, buf.Bytes(), account.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse attachment focus: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
minAttachment := >smodel.MediaAttachment{
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
AccountID: account.ID,
|
||||
Description: text.SanitizeCaption(form.Description),
|
||||
FileMeta: gtsmodel.FileMeta{
|
||||
Focus: gtsmodel.Focus{
|
||||
X: focusx,
|
||||
Y: focusy,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// allow the mediaManager to work its magic of processing the attachment bytes, and putting them in whatever storage backend we're using
|
||||
attachment, err := p.mediaManager.ProcessAttachment(ctx, buf.Bytes(), minAttachment)
|
||||
attachment, err := media.Load(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading attachment: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// prepare the frontend representation now -- if there are any errors here at least we can bail without
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue