summaryrefslogtreecommitdiff
path: root/internal/api/client/media
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/media')
-rw-r--r--internal/api/client/media/media.go2
-rw-r--r--internal/api/client/media/mediacreate.go20
-rw-r--r--internal/api/client/media/mediaget.go2
3 files changed, 14 insertions, 10 deletions
diff --git a/internal/api/client/media/media.go b/internal/api/client/media/media.go
index e45eec7ea..f68a73c2c 100644
--- a/internal/api/client/media/media.go
+++ b/internal/api/client/media/media.go
@@ -33,8 +33,10 @@ import (
// BasePath is the base API path for making media requests
const BasePath = "/api/v1/media"
+
// IDKey is the key for media attachment IDs
const IDKey = "id"
+
// BasePathWithID corresponds to a media attachment with the given ID
const BasePathWithID = BasePath + "/:" + IDKey
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")
}
diff --git a/internal/api/client/media/mediaget.go b/internal/api/client/media/mediaget.go
index 31c40a5aa..7acb475ce 100644
--- a/internal/api/client/media/mediaget.go
+++ b/internal/api/client/media/mediaget.go
@@ -43,7 +43,7 @@ func (m *Module) MediaGETHandler(c *gin.Context) {
attachment, errWithCode := m.processor.MediaGet(authed, attachmentID)
if errWithCode != nil {
- c.JSON(errWithCode.Code(),gin.H{"error": errWithCode.Safe()})
+ c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
return
}