setting media-description and media-focus is now optional when creating attachments

This commit is contained in:
Dan Anglin 2024-08-15 16:15:04 +01:00
parent 4472808f20
commit 5c50507bfc
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638

View file

@ -244,6 +244,8 @@ func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error {
) )
} }
description := ""
if !c.mediaDescriptions.Empty() {
if !c.mediaDescriptions.ExpectedLength(expectedNumValues) { if !c.mediaDescriptions.ExpectedLength(expectedNumValues) {
return fmt.Errorf( return fmt.Errorf(
"received an unexpected number of media descriptions: want %d", "received an unexpected number of media descriptions: want %d",
@ -251,17 +253,31 @@ func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error {
) )
} }
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],
)
}
}
focus := ""
if !c.mediaFocusValues.Empty() {
if !c.mediaFocusValues.ExpectedLength(expectedNumValues) { if !c.mediaFocusValues.ExpectedLength(expectedNumValues) {
return fmt.Errorf( return fmt.Errorf(
"received an unexpected number of media focus values: want %d", "received an unexpected number of media focus values: want %d",
expectedNumValues, expectedNumValues,
) )
} }
focus = c.mediaFocusValues[0]
}
attachment, err := gtsClient.CreateMediaAttachment( attachment, err := gtsClient.CreateMediaAttachment(
c.mediaFiles[0], c.mediaFiles[0],
c.mediaDescriptions[0], description,
c.mediaFocusValues[0], focus,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable to create the media attachment: %w", err) return fmt.Errorf("unable to create the media attachment: %w", err)