summaryrefslogtreecommitdiff
path: root/internal/api/client/media/mediacreate.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-15 11:58:11 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-15 11:58:11 +0200
commitcc48294c31a76e94fa879ad0d8d5dbd7e94c651b (patch)
tree7c26d33b41bab33bbdfbba540958444f4c296602 /internal/api/client/media/mediacreate.go
parentMediahandler (#21) (diff)
downloadgotosocial-cc48294c31a76e94fa879ad0d8d5dbd7e94c651b.tar.xz
Inbox post (#22)
Inbox POST from federated servers now working for statuses and follow requests. Follow request client API added. Start work on federating outgoing messages. Other fixes and changes/tidying up.
Diffstat (limited to 'internal/api/client/media/mediacreate.go')
-rw-r--r--internal/api/client/media/mediacreate.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/api/client/media/mediacreate.go b/internal/api/client/media/mediacreate.go
index c0b4a80d7..9f4702b6b 100644
--- a/internal/api/client/media/mediacreate.go
+++ b/internal/api/client/media/mediacreate.go
@@ -35,30 +35,32 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true) // posting new media is serious business so we want *everything*
if err != nil {
l.Debugf("couldn't auth: %s", err)
- c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
+ c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
return
}
// extract the media create form from the request context
l.Tracef("parsing request form: %s", c.Request.Form)
- var form model.AttachmentRequest
+ form := &model.AttachmentRequest{}
if err := c.ShouldBind(&form); err != nil {
- l.Debugf("could not parse form from request: %s", err)
- c.JSON(http.StatusBadRequest, gin.H{"error": "missing one or more required form values"})
+ l.Debugf("error parsing form: %s", err)
+ c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("could not parse form: %s", err)})
return
}
// Give the fields on the request form a first pass to make sure the request is superficially valid.
l.Tracef("validating form %+v", form)
- if err := validateCreateMedia(&form, m.config.MediaConfig); err != nil {
+ if err := validateCreateMedia(form, m.config.MediaConfig); err != nil {
l.Debugf("error validating form: %s", err)
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ c.JSON(http.StatusUnprocessableEntity, gin.H{"error": err.Error()})
return
}
- mastoAttachment, err := m.processor.MediaCreate(authed, &form)
+ l.Debug("calling processor media create func")
+ mastoAttachment, err := m.processor.MediaCreate(authed, form)
if err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ l.Debugf("error creating attachment: %s", err)
+ c.JSON(http.StatusUnprocessableEntity, gin.H{"error": err.Error()})
return
}
@@ -67,7 +69,7 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
func validateCreateMedia(form *model.AttachmentRequest, config *config.MediaConfig) error {
// check there actually is a file attached and it's not size 0
- if form.File == nil || form.File.Size == 0 {
+ if form.File == nil {
return errors.New("no attachment given")
}