summaryrefslogtreecommitdiff
path: root/internal/api/client/media/mediacreate.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-07-22 12:48:19 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-22 12:48:19 +0200
commit73b8839c5d1b481d1aa1330cd8c206a9f2213333 (patch)
tree877525e40448effbc37d31fdc4f6cbef23263ee8 /internal/api/client/media/mediacreate.go
parent[bugfix] update go-cache library to fix critical bug during cache sweep sched... (diff)
downloadgotosocial-73b8839c5d1b481d1aa1330cd8c206a9f2213333.tar.xz
[bugfix] Make `/api/v2/media` more compatible with masto API (#724)
* update docs * make api version into a path param * update tests * workaround to unset URL if using v2 of api * make some fields into pointers
Diffstat (limited to 'internal/api/client/media/mediacreate.go')
-rw-r--r--internal/api/client/media/mediacreate.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/internal/api/client/media/mediacreate.go b/internal/api/client/media/mediacreate.go
index f51d272b6..5a040b26c 100644
--- a/internal/api/client/media/mediacreate.go
+++ b/internal/api/client/media/mediacreate.go
@@ -31,7 +31,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
-// MediaCreatePOSTHandler swagger:operation POST /api/v1/media mediaCreate
+// MediaCreatePOSTHandler swagger:operation POST /api/{api_version}/media mediaCreate
//
// Upload a new media attachment.
//
@@ -46,6 +46,11 @@ import (
// - application/json
//
// parameters:
+// - name: api version
+// type: string
+// in: path
+// description: Version of the API to use. Must be one of v1 or v2.
+// required: true
// - name: description
// in: formData
// description: |-
@@ -95,6 +100,13 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
return
}
+ apiVersion := c.Param(APIVersionKey)
+ if apiVersion != "v1" && apiVersion != "v2" {
+ err := errors.New("api version must be one of v1 or v2")
+ api.ErrorHandler(c, gtserror.NewErrorNotFound(err, err.Error()), m.processor.InstanceGet)
+ return
+ }
+
form := &model.AttachmentRequest{}
if err := c.ShouldBind(&form); err != nil {
api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
@@ -112,6 +124,15 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
return
}
+ if apiVersion == "v2" {
+ // the mastodon v2 media API specifies that the URL should be null
+ // and that the client should call /api/v1/media/:id to get the URL
+ //
+ // so even though we have the URL already, remove it now to comply
+ // with the api
+ apiAttachment.URL = nil
+ }
+
c.JSON(http.StatusOK, apiAttachment)
}