From 7ca5bac7c678dff0e9fb33b3cf5824165ca9d3f1 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 22 Jul 2022 13:43:51 +0200 Subject: [PATCH] [bugfix] Fix Toot CLI media attachments not working properly (#726) --- docs/api/swagger.yaml | 11 +++++++++++ internal/api/client/status/statuscreate_test.go | 2 +- internal/api/model/status.go | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/api/swagger.yaml b/docs/api/swagger.yaml index 1da03d662..334acb93b 100644 --- a/docs/api/swagger.yaml +++ b/docs/api/swagger.yaml @@ -161,6 +161,10 @@ definitions: description: |- Array of Attachment ids to be attached as media. If provided, status becomes optional, and poll cannot be used. + + If the status is being submitted as a form, the key is 'media_ids[]', + but if it's json or xml, the key is 'media_ids'. + in: formData items: type: string @@ -422,6 +426,10 @@ definitions: description: |- Array of Attachment ids to be attached as media. If provided, status becomes optional, and poll cannot be used. + + If the status is being submitted as a form, the key is 'media_ids[]', + but if it's json or xml, the key is 'media_ids'. + in: formData items: type: string @@ -3531,6 +3539,9 @@ paths: - description: |- Array of Attachment ids to be attached as media. If provided, status becomes optional, and poll cannot be used. + + If the status is being submitted as a form, the key is 'media_ids[]', + but if it's json or xml, the key is 'media_ids'. in: formData items: type: string diff --git a/internal/api/client/status/statuscreate_test.go b/internal/api/client/status/statuscreate_test.go index f83ac8e8f..2a1516d9b 100644 --- a/internal/api/client/status/statuscreate_test.go +++ b/internal/api/client/status/statuscreate_test.go @@ -313,7 +313,7 @@ func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() { ctx.Request.Header.Set("accept", "application/json") ctx.Request.Form = url.Values{ "status": {"here's an image attachment"}, - "media_ids": {attachment.ID}, + "media_ids[]": {attachment.ID}, } suite.statusModule.StatusCreatePOSTHandler(ctx) diff --git a/internal/api/model/status.go b/internal/api/model/status.go index 6e25f787a..62efaf434 100644 --- a/internal/api/model/status.go +++ b/internal/api/model/status.go @@ -144,8 +144,12 @@ type StatusCreateRequest struct { Status string `form:"status" json:"status" xml:"status"` // Array of Attachment ids to be attached as media. // If provided, status becomes optional, and poll cannot be used. + // + // If the status is being submitted as a form, the key is 'media_ids[]', + // but if it's json or xml, the key is 'media_ids'. + // // in: formData - MediaIDs []string `form:"media_ids" json:"media_ids" xml:"media_ids"` + MediaIDs []string `form:"media_ids[]" json:"media_ids" xml:"media_ids"` // Poll to include with this status. // swagger:ignore Poll *PollRequest `form:"poll" json:"poll" xml:"poll"`