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,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)