Compare commits
5 commits
4fabf72b1f
...
b2b2b3422f
Author | SHA1 | Date | |
---|---|---|---|
b2b2b3422f | |||
326d3e2576 | |||
2f530bca5a | |||
64e8d6f0ba | |||
ef2b02b799 |
12 changed files with 32 additions and 22 deletions
|
@ -25,7 +25,7 @@ func (a *AcceptExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, a.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, a.accountName, a.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||
)
|
||||
|
@ -12,8 +13,9 @@ func getAccountID(
|
|||
gtsClient *client.Client,
|
||||
myAccount bool,
|
||||
accountNames internalFlag.StringSliceValue,
|
||||
credentialsFile string,
|
||||
) (string, error) {
|
||||
account, err := getAccount(gtsClient, myAccount, accountNames)
|
||||
account, err := getAccount(gtsClient, myAccount, accountNames, credentialsFile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to get the account information: %w", err)
|
||||
}
|
||||
|
@ -25,6 +27,7 @@ func getAccount(
|
|||
gtsClient *client.Client,
|
||||
myAccount bool,
|
||||
accountNames internalFlag.StringSliceValue,
|
||||
credentialsFile string,
|
||||
) (model.Account, error) {
|
||||
var (
|
||||
account model.Account
|
||||
|
@ -33,7 +36,7 @@ func getAccount(
|
|||
|
||||
switch {
|
||||
case myAccount:
|
||||
account, err = getMyAccount(gtsClient)
|
||||
account, err = getMyAccount(gtsClient, credentialsFile)
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
@ -49,8 +52,15 @@ func getAccount(
|
|||
return account, nil
|
||||
}
|
||||
|
||||
func getMyAccount(gtsClient *client.Client) (model.Account, error) {
|
||||
account, err := gtsClient.VerifyCredentials()
|
||||
func getMyAccount(gtsClient *client.Client, path string) (model.Account, error) {
|
||||
authConfig, err := config.NewCredentialsConfigFromFile(path)
|
||||
if err != nil {
|
||||
return model.Account{}, fmt.Errorf("unable to retrieve the authentication configuration: %w", err)
|
||||
}
|
||||
|
||||
accountURI := authConfig.CurrentAccount
|
||||
|
||||
account, err := gtsClient.GetAccount(accountURI)
|
||||
if err != nil {
|
||||
return model.Account{}, fmt.Errorf("unable to retrieve your account: %w", err)
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ func (a *AddExecutor) addToAccount(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, a.accountNames)
|
||||
accountID, err := getAccountID(gtsClient, false, a.accountNames, a.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func (a *AddExecutor) addVoteToStatus(gtsClient *client.Client) error {
|
|||
return MultipleChoiceError{}
|
||||
}
|
||||
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil)
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil, a.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (b *BlockExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, b.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (f *FollowExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, f.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (m *MuteExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, m.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (r *RejectExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, r.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, r.accountName, r.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ func (r *RemoveExecutor) removeFromAccount(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, r.accountNames)
|
||||
accountID, err := getAccountID(gtsClient, false, r.accountNames, r.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func (s *ShowExecutor) showInstance(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
||||
account, err := getAccount(gtsClient, s.myAccount, s.accountName)
|
||||
account, err := getAccount(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get the account information: %w", err)
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (s *ShowExecutor) showStatus(gtsClient *client.Client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil)
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ func (s *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil)
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName)
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName)
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ func (s *ShowExecutor) showBookmarks(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
if len(bookmarks.Statuses) > 0 {
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil)
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ func (s *ShowExecutor) showLiked(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
if len(liked.Statuses) > 0 {
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil)
|
||||
myAccountID, err := getAccountID(gtsClient, true, nil, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get your account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (b *UnblockExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, b.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (f *UnfollowExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, f.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (m *UnmuteExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, m.accountName)
|
||||
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue