diff --git a/docs/manual.md b/docs/manual.md index 95ebaf3..c7a89f2 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -54,8 +54,10 @@ - [Remove accounts from a list](#remove-accounts-from-a-list) - [Timelines](#timelines) - [View a timeline](#view-a-timeline) -- [Media Attachment](#media-attachment) - - [View media attachment](#view-media-attachment) +- [Media Attachments](#media-attachments) + - [Create a media attachment](#create-a-media-attachment) + - [Edit a media attachment](#edit-a-media-attachment) + - [View a media attachment](#view-a-media-attachment) - [Media](#media) - [View media from a status](#view-media-from-a-status) - [Bookmarks](#bookmarks) @@ -683,9 +685,51 @@ Prints a list of statuses from a timeline. | `tag` | string | false | The hashtag you want to view.
This is only required if `timeline-category` is set to `tag`. | | | `limit` | integer | false | The maximum number of statuses to print. | 20 | -## Media Attachment +## Media Attachments -### View media attachment +### Create a media attachment + +Uploads media from a file to the instance and creates a media attachment. +You can write a description of the media to a text file and specify the its path with the `media-description` flag (see the examples below). + +- Create a media attachment with a simple description and a focus of x=-0.1, y=0.5 + ``` + enbas create --type media-attachment \ + --media-file picture.png \ + --media-description "A picture of a rotten wooden bench in front of the woods." \ + --media-focus "-0.1,0.5" + ``` +- Create a media attachment using a description that has been written to the `description.txt` text file. + ``` + enbas create --type media-attachment \ + --media-file picture.png \ + --media-description file@description.txt + ``` + +| flag | type | required | description | default | +|------|------|----------|-------------|---------| +| `type` | string | true | The resource you want to create.
Here this should be `media-attachment`. | | +| `media-file` | string | true | The path to the media file. | | +| `media-description` | string | false | The description of the media attachment which will be used as the media's alt-text.
To use a description from a text file, use the `flag@` prefix followed by the path to the file (e.g. `file@description.txt`)| | +| `media-focus` | string | false | The media's focus values. This should be in the form of two comma-separated numbers between -1 and 1 (e.g. 0.25,-0.34) | | + +### Edit a media attachment + +Edits the description and/or the focus of a media attachment that you own. + +``` +enbas edit --type media-attachment \ + --attachment-id 01J5B9A8WFK59W11MS6AHPYWBR \ + --media-description "An updated description of a picture." +``` + +| flag | type | required | description | default | +|------|------|----------|-------------|---------| +| `type` | string | true | The resource you want to edit.
Here this should be `media-attachment`. | | +| `media-description` | string | false | The description of the media attachment to edit.
To use a description from a text file, use the `flag@` prefix followed by the path to the file (e.g. `file@description.txt`)| | +| `media-focus` | string | false | The media's focus values. This should be in the form of two comma-separated numbers between -1 and 1 (e.g. 0.25,-0.34) | | + +### View a media attachment Prints information about a given media attachment that you own. You can only see information about the media attachment that you own. diff --git a/internal/executor/edit.go b/internal/executor/edit.go index 996ecd7..b6097de 100644 --- a/internal/executor/edit.go +++ b/internal/executor/edit.go @@ -5,6 +5,7 @@ import ( "codeflow.dananglin.me.uk/apollo/enbas/internal/client" "codeflow.dananglin.me.uk/apollo/enbas/internal/model" + "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" ) func (e *EditExecutor) Execute() error { @@ -66,6 +67,7 @@ func (e *EditExecutor) editList(gtsClient *client.Client) error { func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error { expectedNumValues := 1 + if !e.attachmentIDs.ExpectedLength(expectedNumValues) { return fmt.Errorf( "received an unexpected number of media attachment IDs: want %d", @@ -73,36 +75,42 @@ func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error { ) } - if !e.mediaDescriptions.ExpectedLength(expectedNumValues) { - return fmt.Errorf( - "received an unexpected number of media descriptions: want %d", - expectedNumValues, - ) - } - - if !e.mediaFocusValues.ExpectedLength(expectedNumValues) { - return fmt.Errorf( - "received an unexpected number of media focus values: want %d", - expectedNumValues, - ) - } - attachment, err := gtsClient.GetMediaAttachment(e.attachmentIDs[0]) if err != nil { return fmt.Errorf("unable to get the media attachment: %w", err) } - description := e.mediaDescriptions[0] - if description == "" { - description = attachment.Description + description := attachment.Description + if !e.mediaDescriptions.Empty() { + if !e.mediaDescriptions.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media descriptions: want %d", + expectedNumValues, + ) + } + + var err error + description, err = utilities.ReadContents(e.mediaDescriptions[0]) + if err != nil { + return fmt.Errorf( + "unable to read the contents from %s: %w", + e.mediaDescriptions[0], + ) + } } - focus := e.mediaFocusValues[0] - if focus == "" { - focus = fmt.Sprintf("%f,%f", attachment.Meta.Focus.X, attachment.Meta.Focus.Y) + focus := fmt.Sprintf("%f,%f", attachment.Meta.Focus.X, attachment.Meta.Focus.Y) + if !e.mediaFocusValues.Empty() { + if !e.mediaFocusValues.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media focus values: want %d", + expectedNumValues, + ) + } + focus = e.mediaFocusValues[0] } - if _, err = gtsClient.UpdateMediaAttachment(e.attachmentIDs[0], description, focus); err != nil { + if _, err = gtsClient.UpdateMediaAttachment(attachment.ID, description, focus); err != nil { return fmt.Errorf("unable to update the media attachment: %w", err) } diff --git a/internal/executor/executors.go b/internal/executor/executors.go index be6cf67..1ef1ee1 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -178,7 +178,7 @@ func NewCreateExecutor( exe.StringVar(&exe.language, "language", "", "The ISO 639 language code for this status") exe.StringVar(&exe.listRepliesPolicy, "list-replies-policy", "list", "The replies policy of the list") exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list") - exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment that will be used as the alt-text") + exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") exe.Var(&exe.mediaFiles, "media-file", "The path to the media file") exe.BoolVar(&exe.pollAllowsMultipleChoices, "poll-allows-multiple-choices", false, "Set to true to allow viewers to make multiple choices in the poll") @@ -253,7 +253,7 @@ func NewEditExecutor( exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list") exe.StringVar(&exe.listRepliesPolicy, "list-replies-policy", "", "The replies policy of the list") - exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment that will be used as the alt-text") + exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 85440ec..3199e0a 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -98,7 +98,7 @@ }, "media-description": { "type": "StringSliceValue", - "description": "The description of the media attachment that will be used as the alt-text" + "description": "The description of the media attachment which will be used as the alt-text" }, "media-file": { "type": "StringSliceValue",