From 5c50507bfcf585f2c34fed6b9a3b4956f2fc339e Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Thu, 15 Aug 2024 16:15:04 +0100 Subject: [PATCH] setting media-description and media-focus is now optional when creating attachments --- internal/executor/create.go | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/internal/executor/create.go b/internal/executor/create.go index f77046b..6e0472a 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -244,24 +244,40 @@ func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error { ) } - if !c.mediaDescriptions.ExpectedLength(expectedNumValues) { - return fmt.Errorf( - "received an unexpected number of media descriptions: want %d", - expectedNumValues, - ) + description := "" + if !c.mediaDescriptions.Empty() { + if !c.mediaDescriptions.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media descriptions: want %d", + expectedNumValues, + ) + } + + var err error + description, err = utilities.ReadContents(c.mediaDescriptions[0]) + if err != nil { + return fmt.Errorf( + "unable to read the contents from %s: %w", + c.mediaDescriptions[0], + ) + } } - if !c.mediaFocusValues.ExpectedLength(expectedNumValues) { - return fmt.Errorf( - "received an unexpected number of media focus values: want %d", - expectedNumValues, - ) + focus := "" + if !c.mediaFocusValues.Empty() { + if !c.mediaFocusValues.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media focus values: want %d", + expectedNumValues, + ) + } + focus = c.mediaFocusValues[0] } attachment, err := gtsClient.CreateMediaAttachment( c.mediaFiles[0], - c.mediaDescriptions[0], - c.mediaFocusValues[0], + description, + focus, ) if err != nil { return fmt.Errorf("unable to create the media attachment: %w", err)