mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] media v2 endpoint fix unset url (#4008)
* update semantics of when media URL is left unset * fix test
This commit is contained in:
@@ -92,9 +92,10 @@ import (
|
|||||||
// '500':
|
// '500':
|
||||||
// description: internal server error
|
// description: internal server error
|
||||||
func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
|
func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
|
||||||
apiVersion, errWithCode := apiutil.ParseAPIVersion(
|
_, errWithCode := apiutil.ParseAPIVersion(
|
||||||
c.Param(apiutil.APIVersionKey),
|
c.Param(apiutil.APIVersionKey),
|
||||||
[]string{apiutil.APIv1, apiutil.APIv2}...,
|
apiutil.APIv1,
|
||||||
|
apiutil.APIv2,
|
||||||
)
|
)
|
||||||
if errWithCode != nil {
|
if errWithCode != nil {
|
||||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||||
@@ -137,14 +138,13 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiVersion == apiutil.APIv2 {
|
// The v2 mastodon endpoint always returns TextURL,
|
||||||
// the mastodon v2 media API specifies that the URL should be null
|
// but in the case that a 202 Accepted (i.e. processing
|
||||||
// and that the client should call /api/v1/media/:id to get the URL
|
// 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.
|
||||||
//
|
//
|
||||||
// so even though we have the URL already, remove it now to comply
|
// https://docs.joinmastodon.org/methods/media/#v2
|
||||||
// with the api
|
|
||||||
apiAttachment.URL = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
apiutil.JSON(c, http.StatusOK, apiAttachment)
|
apiutil.JSON(c, http.StatusOK, apiAttachment)
|
||||||
}
|
}
|
||||||
|
@@ -297,7 +297,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessfulV2() {
|
|||||||
}, *attachmentReply.Meta)
|
}, *attachmentReply.Meta)
|
||||||
suite.Equal("LiB|W-#6RQR.~qvzRjWF_3rqV@a$", *attachmentReply.Blurhash)
|
suite.Equal("LiB|W-#6RQR.~qvzRjWF_3rqV@a$", *attachmentReply.Blurhash)
|
||||||
suite.NotEmpty(attachmentReply.ID)
|
suite.NotEmpty(attachmentReply.ID)
|
||||||
suite.Nil(attachmentReply.URL)
|
suite.NotEmpty(attachmentReply.URL)
|
||||||
suite.NotEmpty(attachmentReply.PreviewURL)
|
suite.NotEmpty(attachmentReply.PreviewURL)
|
||||||
suite.Equal(len(storageKeysBeforeRequest)+2, len(storageKeysAfterRequest)) // 2 images should be added to storage: the original and the thumbnail
|
suite.Equal(len(storageKeysBeforeRequest)+2, len(storageKeysAfterRequest)) // 2 images should be added to storage: the original and the thumbnail
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user