mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 15:57:29 -06:00
start updating media handler for proper processing
This commit is contained in:
parent
dc338dc881
commit
d797ddf704
5 changed files with 89 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
|
|
@ -17,6 +18,8 @@ import (
|
|||
func (p *processor) MediaCreate(authed *oauth.Auth, form *apimodel.AttachmentRequest) (*apimodel.Attachment, error) {
|
||||
// First check this user/account is permitted to create media
|
||||
// There's no point continuing otherwise.
|
||||
//
|
||||
// TODO: move this check to the oauth.Authed function and do it for all accounts
|
||||
if authed.User.Disabled || !authed.User.Approved || !authed.Account.SuspendedAt.IsZero() {
|
||||
return nil, errors.New("not authorized to post new media")
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ func (p *processor) MediaCreate(authed *oauth.Auth, form *apimodel.AttachmentReq
|
|||
attachment.Description = form.Description
|
||||
|
||||
// now parse the focus parameter
|
||||
// TODO: tidy this up into a separate function and just return an error so all the c.JSON and return calls are obviated
|
||||
// TODO: tidy this up into a separate function and just return an error
|
||||
var focusx, focusy float32
|
||||
if form.Focus != "" {
|
||||
spl := strings.Split(form.Focus, ",")
|
||||
|
|
@ -96,7 +99,29 @@ func (p *processor) MediaCreate(authed *oauth.Auth, form *apimodel.AttachmentReq
|
|||
return &mastoAttachment, nil
|
||||
}
|
||||
|
||||
func (p *processor) MediaGet(authed *oauth.Auth, form *apimodel.GetContentRequestForm) (*apimodel.Content, error) {
|
||||
func (p *processor) MediaGet(authed *oauth.Auth, mediaAttachmentID string) (*apimodel.Attachment, ErrorWithCode) {
|
||||
attachment := >smodel.MediaAttachment{}
|
||||
if err := p.db.GetByID(mediaAttachmentID, attachment); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// attachment doesn't exist
|
||||
return nil, NewErrorNotFound(errors.New("attachment doesn't exist in the db"))
|
||||
}
|
||||
return nil, NewErrorNotFound(fmt.Errorf("db error getting attachment: %s", err))
|
||||
}
|
||||
|
||||
if attachment.AccountID != authed.Account.ID {
|
||||
return nil, NewErrorNotFound(errors.New("attachment not owned by requesting account"))
|
||||
}
|
||||
|
||||
a, err := p.tc.AttachmentToMasto(attachment)
|
||||
if err != nil {
|
||||
return nil, NewErrorNotFound(fmt.Errorf("error converting attachment: %s", err))
|
||||
}
|
||||
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
func (p *processor) FileGet(authed *oauth.Auth, form *apimodel.GetContentRequestForm) (*apimodel.Content, error) {
|
||||
// parse the form fields
|
||||
mediaSize, err := media.ParseMediaSize(form.MediaSize)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -74,13 +74,16 @@ type Processor interface {
|
|||
// AppCreate processes the creation of a new API application
|
||||
AppCreate(authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, error)
|
||||
|
||||
// FileGet handles the fetching of a media attachment file via the fileserver.
|
||||
FileGet(authed *oauth.Auth, form *apimodel.GetContentRequestForm) (*apimodel.Content, error)
|
||||
|
||||
// InstanceGet retrieves instance information for serving at api/v1/instance
|
||||
InstanceGet(domain string) (*apimodel.Instance, ErrorWithCode)
|
||||
|
||||
// MediaCreate handles the creation of a media attachment, using the given form.
|
||||
MediaCreate(authed *oauth.Auth, form *apimodel.AttachmentRequest) (*apimodel.Attachment, error)
|
||||
// MediaGet handles the fetching of a media attachment, using the given request form.
|
||||
MediaGet(authed *oauth.Auth, form *apimodel.GetContentRequestForm) (*apimodel.Content, error)
|
||||
// MediaGet handles the GET of a media attachment with the given ID
|
||||
MediaGet(authed *oauth.Auth, attachmentID string) (*apimodel.Attachment, ErrorWithCode)
|
||||
|
||||
// StatusCreate processes the given form to create a new status, returning the api model representation of that status if it's OK.
|
||||
StatusCreate(authed *oauth.Auth, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue