Compare commits
No commits in common. "0065e353997e166e91094fa13820ebb8fe70c4f6" and "795e3441985e4241dd14a2ee77e0313a25ca7ea8" have entirely different histories.
0065e35399
...
795e344198
5 changed files with 40 additions and 165 deletions
|
@ -1,7 +1,6 @@
|
|||
package executor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||
|
@ -68,71 +67,6 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
|||
sensitive bool
|
||||
)
|
||||
|
||||
attachmentIDs := []string(c.attachmentIDs)
|
||||
|
||||
if !c.mediaFiles.Empty() {
|
||||
descriptionsExists := false
|
||||
focusValuesExists := false
|
||||
expectedLength := len(c.mediaFiles)
|
||||
mediaDescriptions := make([]string, expectedLength)
|
||||
|
||||
if !c.mediaDescriptions.Empty() {
|
||||
descriptionsExists = true
|
||||
|
||||
if !c.mediaDescriptions.ExpectedLength(expectedLength) {
|
||||
return errors.New("the number of media descriptions does not match the number of media files")
|
||||
}
|
||||
}
|
||||
|
||||
if !c.mediaFocusValues.Empty() {
|
||||
focusValuesExists = true
|
||||
|
||||
if !c.mediaFocusValues.ExpectedLength(expectedLength) {
|
||||
return errors.New("the number of media focus values does not match the number of media files")
|
||||
}
|
||||
}
|
||||
|
||||
if descriptionsExists {
|
||||
for ind := 0; ind < expectedLength; ind++ {
|
||||
content, err := utilities.ReadContents(c.mediaDescriptions[ind])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read the contents from %s: %w", c.mediaDescriptions[ind], err)
|
||||
}
|
||||
|
||||
mediaDescriptions[ind] = content
|
||||
}
|
||||
}
|
||||
|
||||
for ind := 0; ind < expectedLength; ind++ {
|
||||
var (
|
||||
mediaFile string
|
||||
description string
|
||||
focus string
|
||||
)
|
||||
|
||||
mediaFile = c.mediaFiles[ind]
|
||||
|
||||
if descriptionsExists {
|
||||
description = mediaDescriptions[ind]
|
||||
}
|
||||
|
||||
if focusValuesExists {
|
||||
focus = c.mediaFocusValues[ind]
|
||||
}
|
||||
|
||||
attachment, err := gtsClient.CreateMediaAttachment(
|
||||
mediaFile,
|
||||
description,
|
||||
focus,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create the media attachment for %s: %w", mediaFile, err)
|
||||
}
|
||||
|
||||
attachmentIDs = append(attachmentIDs, attachment.ID)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case c.content != "":
|
||||
content = c.content
|
||||
|
@ -142,7 +76,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
|||
return fmt.Errorf("unable to get the status contents from %q: %w", c.fromFile, err)
|
||||
}
|
||||
default:
|
||||
if len(attachmentIDs) == 0 {
|
||||
if c.attachmentIDs.Empty() {
|
||||
// TODO: revisit this error type
|
||||
return EmptyContentError{
|
||||
ResourceType: resourceStatus,
|
||||
|
@ -234,33 +168,11 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error {
|
||||
expectedNumValues := 1
|
||||
if !c.mediaFiles.ExpectedLength(expectedNumValues) {
|
||||
return fmt.Errorf(
|
||||
"received an unexpected number of media files: want %d",
|
||||
expectedNumValues,
|
||||
)
|
||||
if c.fromFile == "" {
|
||||
return FlagNotSetError{flagText: flagFromFile}
|
||||
}
|
||||
|
||||
if !c.mediaDescriptions.ExpectedLength(expectedNumValues) {
|
||||
return fmt.Errorf(
|
||||
"received an unexpected number of media descriptions: want %d",
|
||||
expectedNumValues,
|
||||
)
|
||||
}
|
||||
|
||||
if !c.mediaFocusValues.ExpectedLength(expectedNumValues) {
|
||||
return fmt.Errorf(
|
||||
"received an unexpected number of media focus values: want %d",
|
||||
expectedNumValues,
|
||||
)
|
||||
}
|
||||
|
||||
attachment, err := gtsClient.CreateMediaAttachment(
|
||||
c.mediaFiles[0],
|
||||
c.mediaDescriptions[0],
|
||||
c.mediaFocusValues[0],
|
||||
)
|
||||
attachment, err := gtsClient.CreateMediaAttachment(c.fromFile, c.description, c.focus)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create the media attachment: %w", err)
|
||||
}
|
||||
|
|
|
@ -65,25 +65,11 @@ func (e *EditExecutor) editList(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error {
|
||||
expectedNumValues := 1
|
||||
if !e.attachmentIDs.ExpectedLength(expectedNumValues) {
|
||||
expectedNumMediaAttachmentIDs := 1
|
||||
if !e.attachmentIDs.ExpectedLength(expectedNumMediaAttachmentIDs) {
|
||||
return fmt.Errorf(
|
||||
"received an unexpected number of media attachment IDs: want %d",
|
||||
expectedNumValues,
|
||||
)
|
||||
}
|
||||
|
||||
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,
|
||||
expectedNumMediaAttachmentIDs,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -92,12 +78,12 @@ func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error {
|
|||
return fmt.Errorf("unable to get the media attachment: %w", err)
|
||||
}
|
||||
|
||||
description := e.mediaDescriptions[0]
|
||||
description := e.description
|
||||
if description == "" {
|
||||
description = attachment.Description
|
||||
}
|
||||
|
||||
focus := e.mediaFocusValues[0]
|
||||
focus := e.focus
|
||||
if focus == "" {
|
||||
focus = fmt.Sprintf("%f,%f", attachment.Meta.Focus.X, attachment.Meta.Focus.Y)
|
||||
}
|
||||
|
|
|
@ -124,18 +124,17 @@ type CreateExecutor struct {
|
|||
attachmentIDs internalFlag.StringSliceValue
|
||||
content string
|
||||
contentType string
|
||||
description string
|
||||
federated bool
|
||||
likeable bool
|
||||
replyable bool
|
||||
boostable bool
|
||||
focus string
|
||||
fromFile string
|
||||
inReplyTo string
|
||||
language string
|
||||
listRepliesPolicy string
|
||||
listTitle string
|
||||
mediaDescriptions internalFlag.StringSliceValue
|
||||
mediaFocusValues internalFlag.StringSliceValue
|
||||
mediaFiles internalFlag.StringSliceValue
|
||||
pollAllowsMultipleChoices bool
|
||||
pollExpiresIn internalFlag.TimeDurationValue
|
||||
pollHidesVoteCounts bool
|
||||
|
@ -155,9 +154,6 @@ func NewCreateExecutor(
|
|||
printer: printer,
|
||||
config: config,
|
||||
attachmentIDs: internalFlag.NewStringSliceValue(),
|
||||
mediaDescriptions: internalFlag.NewStringSliceValue(),
|
||||
mediaFocusValues: internalFlag.NewStringSliceValue(),
|
||||
mediaFiles: internalFlag.NewStringSliceValue(),
|
||||
pollExpiresIn: internalFlag.NewTimeDurationValue(),
|
||||
pollOptions: internalFlag.NewStringSliceValue(),
|
||||
sensitive: internalFlag.NewBoolPtrValue(),
|
||||
|
@ -169,18 +165,17 @@ func NewCreateExecutor(
|
|||
exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment")
|
||||
exe.StringVar(&exe.content, "content", "", "The content of the created resource")
|
||||
exe.StringVar(&exe.contentType, "content-type", "plain", "The type that the contents should be parsed from (valid values are plain and markdown)")
|
||||
exe.StringVar(&exe.description, "description", "", "The description of the media attachment that will be used as the alt-text")
|
||||
exe.BoolVar(&exe.federated, "enable-federation", true, "Set to true to federate the status beyond the local timelines")
|
||||
exe.BoolVar(&exe.likeable, "enable-likes", true, "Set to true to allow the status to be liked (favourited)")
|
||||
exe.BoolVar(&exe.replyable, "enable-replies", true, "Set to true to allow viewers to reply to the status")
|
||||
exe.BoolVar(&exe.boostable, "enable-reposts", true, "Set to true to allow the status to be reposted (boosted) by others")
|
||||
exe.StringVar(&exe.focus, "focus", "", "The focus of the media file")
|
||||
exe.StringVar(&exe.fromFile, "from-file", "", "The file path where to read the contents from")
|
||||
exe.StringVar(&exe.inReplyTo, "in-reply-to", "", "The ID of the status that you want to reply to")
|
||||
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.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")
|
||||
exe.Var(&exe.pollExpiresIn, "poll-expires-in", "The duration in which the poll is open for")
|
||||
exe.BoolVar(&exe.pollHidesVoteCounts, "poll-hides-vote-counts", false, "Set to true to hide the vote count until the poll is closed")
|
||||
|
@ -226,11 +221,11 @@ type EditExecutor struct {
|
|||
printer *printer.Printer
|
||||
config *config.Config
|
||||
attachmentIDs internalFlag.StringSliceValue
|
||||
description string
|
||||
focus string
|
||||
listID string
|
||||
listTitle string
|
||||
listRepliesPolicy string
|
||||
mediaDescriptions internalFlag.StringSliceValue
|
||||
mediaFocusValues internalFlag.StringSliceValue
|
||||
resourceType string
|
||||
}
|
||||
|
||||
|
@ -243,18 +238,16 @@ func NewEditExecutor(
|
|||
printer: printer,
|
||||
config: config,
|
||||
attachmentIDs: internalFlag.NewStringSliceValue(),
|
||||
mediaDescriptions: internalFlag.NewStringSliceValue(),
|
||||
mediaFocusValues: internalFlag.NewStringSliceValue(),
|
||||
}
|
||||
|
||||
exe.Usage = usage.ExecutorUsageFunc("edit", "Edit a specific resource", exe.FlagSet)
|
||||
|
||||
exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment")
|
||||
exe.StringVar(&exe.description, "description", "", "The description of the media attachment that will be used as the alt-text")
|
||||
exe.StringVar(&exe.focus, "focus", "", "The focus of the media file")
|
||||
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.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)")
|
||||
|
||||
return &exe
|
||||
|
|
|
@ -4,19 +4,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const filePrefix string = "file@"
|
||||
|
||||
func ReadContents(text string) (string, error) {
|
||||
if !strings.HasPrefix(text, filePrefix) {
|
||||
return text, nil
|
||||
}
|
||||
|
||||
return ReadFile(strings.TrimPrefix(text, filePrefix))
|
||||
}
|
||||
|
||||
func ReadFile(path string) (string, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
"type": "string",
|
||||
"description": "The type that the contents should be parsed from (valid values are plain and markdown)"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "The description of the media attachment that will be used as the alt-text"
|
||||
},
|
||||
"enable-federation": {
|
||||
"type": "bool",
|
||||
"description": "Set to true to federate the status beyond the local timelines"
|
||||
|
@ -56,6 +60,10 @@
|
|||
"type": "bool",
|
||||
"description": "Set to true to exclude statuses that are a reply to another status"
|
||||
},
|
||||
"focus": {
|
||||
"type": "string",
|
||||
"description": "The focus of the media file"
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
"description": "The resource type to action the target resource from (e.g. status)"
|
||||
|
@ -96,18 +104,6 @@
|
|||
"type": "string",
|
||||
"description": "The replies policy of the list"
|
||||
},
|
||||
"media-description": {
|
||||
"type": "StringSliceValue",
|
||||
"description": "The description of the media attachment that will be used as the alt-text"
|
||||
},
|
||||
"media-file": {
|
||||
"type": "StringSliceValue",
|
||||
"description": "The path to the media file"
|
||||
},
|
||||
"media-focus": {
|
||||
"type": "StringSliceValue",
|
||||
"description": "The focus of the media file"
|
||||
},
|
||||
"mute-duration": {
|
||||
"type": "TimeDurationValue",
|
||||
"description": "Specify how long the mute should last for. To mute indefinitely, set this to 0s"
|
||||
|
@ -249,18 +245,17 @@
|
|||
{ "flag": "attachment-id", "fieldName": "attachmentIDs" },
|
||||
{ "flag": "content", "default": "" },
|
||||
{ "flag": "content-type", "default": "plain" },
|
||||
{ "flag": "description", "default": "" },
|
||||
{ "flag": "enable-federation", "fieldName": "federated", "default": "true" },
|
||||
{ "flag": "enable-likes", "fieldName": "likeable", "default": "true" },
|
||||
{ "flag": "enable-replies", "fieldName": "replyable", "default": "true" },
|
||||
{ "flag": "enable-reposts", "fieldName": "boostable", "default": "true" },
|
||||
{ "flag": "focus", "default": "" },
|
||||
{ "flag": "from-file", "default": "" },
|
||||
{ "flag": "in-reply-to", "default": "" },
|
||||
{ "flag": "language", "default": "" },
|
||||
{ "flag": "list-replies-policy", "default": "list" },
|
||||
{ "flag": "list-title", "default": "" },
|
||||
{ "flag": "media-description", "fieldName": "mediaDescriptions" },
|
||||
{ "flag": "media-focus", "fieldName": "mediaFocusValues" },
|
||||
{ "flag": "media-file", "fieldName": "mediaFiles" },
|
||||
{ "flag": "poll-allows-multiple-choices", "default": "false" },
|
||||
{ "flag": "poll-expires-in" },
|
||||
{ "flag": "poll-hides-vote-counts", "default": "false" },
|
||||
|
@ -288,11 +283,11 @@
|
|||
"additionalFields": [],
|
||||
"flags": [
|
||||
{ "flag": "attachment-id", "fieldName": "attachmentIDs" },
|
||||
{ "flag": "description", "default": "" },
|
||||
{ "flag": "focus", "default": "" },
|
||||
{ "flag": "list-id", "fieldName": "listID", "default": ""},
|
||||
{ "flag": "list-title", "default": "" },
|
||||
{ "flag": "list-replies-policy", "default": "" },
|
||||
{ "flag": "media-description", "fieldName": "mediaDescriptions" },
|
||||
{ "flag": "media-focus", "fieldName": "mediaFocusValues" },
|
||||
{ "flag": "type", "fieldName": "resourceType", "default": "" }
|
||||
],
|
||||
"summary": "Edit a specific resource",
|
||||
|
|
Loading…
Reference in a new issue