diff options
| author | 2025-04-14 12:32:49 +0000 | |
|---|---|---|
| committer | 2025-04-14 13:32:49 +0100 | |
| commit | 36758ea0de6a7ce7b94d5db561fa1d81f37b96d0 (patch) | |
| tree | 030a0dd8764d7343d61781d19a99940587333a59 /internal/api/client/media | |
| parent | [chore] Update + add fonts for additional scripts, use locally installed font... (diff) | |
| download | gotosocial-36758ea0de6a7ce7b94d5db561fa1d81f37b96d0.tar.xz | |
[bugfix] media v2 endpoint fix unset url (#4008)
* update semantics of when media URL is left unset
* fix test
Diffstat (limited to 'internal/api/client/media')
| -rw-r--r-- | internal/api/client/media/mediacreate.go | 20 | ||||
| -rw-r--r-- | internal/api/client/media/mediacreate_test.go | 2 |
2 files changed, 11 insertions, 11 deletions
diff --git a/internal/api/client/media/mediacreate.go b/internal/api/client/media/mediacreate.go index 0f9de7b56..4abcb8b22 100644 --- a/internal/api/client/media/mediacreate.go +++ b/internal/api/client/media/mediacreate.go @@ -92,9 +92,10 @@ import ( // '500': // description: internal server error func (m *Module) MediaCreatePOSTHandler(c *gin.Context) { - apiVersion, errWithCode := apiutil.ParseAPIVersion( + _, errWithCode := apiutil.ParseAPIVersion( c.Param(apiutil.APIVersionKey), - []string{apiutil.APIv1, apiutil.APIv2}..., + apiutil.APIv1, + apiutil.APIv2, ) if errWithCode != nil { apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) @@ -137,14 +138,13 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) { return } - if apiVersion == apiutil.APIv2 { - // 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 - } + // The v2 mastodon endpoint always returns TextURL, + // but in the case that a 202 Accepted (i.e. processing + // still in progress) is returned then the URL will be + // nil. Since we only ever return a 200 OK, we behave + // exactly the same as the v1 endpoint. + // + // https://docs.joinmastodon.org/methods/media/#v2 apiutil.JSON(c, http.StatusOK, apiAttachment) } diff --git a/internal/api/client/media/mediacreate_test.go b/internal/api/client/media/mediacreate_test.go index fabff595b..6f7bf781f 100644 --- a/internal/api/client/media/mediacreate_test.go +++ b/internal/api/client/media/mediacreate_test.go @@ -297,7 +297,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessfulV2() { }, *attachmentReply.Meta) suite.Equal("LiB|W-#6RQR.~qvzRjWF_3rqV@a$", *attachmentReply.Blurhash) suite.NotEmpty(attachmentReply.ID) - suite.Nil(attachmentReply.URL) + suite.NotEmpty(attachmentReply.URL) suite.NotEmpty(attachmentReply.PreviewURL) suite.Equal(len(storageKeysBeforeRequest)+2, len(storageKeysAfterRequest)) // 2 images should be added to storage: the original and the thumbnail } |
