Skip to content

Commit

Permalink
fix: Issue with login and sorting order (#235)
Browse files Browse the repository at this point in the history
* chore: Add context to error

* chore: Trimpath from compile binary

* fix: Fatal error when no users to store

* chore: Bump github.com/Davincible/goinsta/v3 to v3.2.6

* feat: Fetch followings in earliest order

* style: Fix cuddle issue

* refactor: Simplify store users code
  • Loading branch information
obalunenko authored Jan 28, 2023
1 parent b0c9b08 commit 71b0af9
Show file tree
Hide file tree
Showing 31 changed files with 579 additions and 579 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/obalunenko/instadiff-cli
go 1.19

require (
github.com/Davincible/goinsta/v3 v3.1.3
github.com/Davincible/goinsta/v3 v3.2.6
github.com/briandowns/spinner v1.20.0
github.com/disintegration/imaging v1.6.2
github.com/hashicorp/go-multierror v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7O
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Davincible/goinsta/v3 v3.1.3 h1:0XMj7upEgRA/IWSDRS1+d8DLNYtRttCASKaNzQn1H7M=
github.com/Davincible/goinsta/v3 v3.1.3/go.mod h1:jqCJarVJYVy1zJiXoIWU1zOZKmVCwdeQZbxIp8d+i3g=
github.com/Davincible/goinsta/v3 v3.2.6 h1:+lNIWU6NABWd2VSGe83UQypnef+kzWwjmfgGihPbwD8=
github.com/Davincible/goinsta/v3 v3.2.6/go.mod h1:jIDhrWZmttL/gtXj/mkCaZyeNdAAqW3UYjasOUW0YEw=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
Expand Down
11 changes: 4 additions & 7 deletions internal/client/instagram/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ func (c *Client) UploadMedia(ctx context.Context, file io.Reader, mt media.Type)
Album: nil,
Caption: "",
IsStory: isStory(mt),
IsIGTV: false,
Title: "",
IGTVPreview: false,
MuteAudio: false,
DisableComments: false,
DisableLikeViewCount: false,
Expand Down Expand Up @@ -317,7 +314,7 @@ func (c *Client) UserFollowers(ctx context.Context, user models.User) ([]models.

u.SetInstagram(c.client)

return c.makeUsersList(ctx, u.Followers())
return c.makeUsersList(ctx, u.Followers(""))
}

// UserFollowings returns user followings.
Expand All @@ -329,7 +326,7 @@ func (c *Client) UserFollowings(ctx context.Context, user models.User) ([]models

u.SetInstagram(c.client)

return c.makeUsersList(ctx, u.Following())
return c.makeUsersList(ctx, u.Following("", goinsta.EarliestOrder))
}

// GetUserByName finds user by username.
Expand Down Expand Up @@ -372,12 +369,12 @@ func (c *Client) Unfollow(ctx context.Context, user models.User) error {

// Followers returns list of followers.
func (c *Client) Followers(ctx context.Context) ([]models.User, error) {
return c.makeUsersList(ctx, c.client.Account.Followers())
return c.makeUsersList(ctx, c.client.Account.Followers(""))
}

// Followings returns list of followings.
func (c *Client) Followings(ctx context.Context) ([]models.User, error) {
return c.makeUsersList(ctx, c.client.Account.Following())
return c.makeUsersList(ctx, c.client.Account.Following("", goinsta.EarliestOrder))
}

// Username returns current account username.
Expand Down
20 changes: 8 additions & 12 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,13 @@ func (svc *Service) getUsers(ctx context.Context, bt models.UsersBatchType) ([]m
return nil, fmt.Errorf("find diff users: %w", err)
}

err = svc.storeUsers(ctx, models.UsersBatch{
batch := models.UsersBatch{
Users: users,
Type: bt,
CreatedAt: time.Now(),
})
if err != nil {
if errors.Is(err, ErrNoUsers) {
log.WithError(ctx, err).Warn("Failed to store users")

return users, nil
}
}

if err = svc.storeUsers(ctx, batch); err != nil && !errors.Is(err, ErrNoUsers) {
return nil, fmt.Errorf("store users [%s]: %w", bt.String(), err)
}

Expand Down Expand Up @@ -300,12 +295,13 @@ func (svc *Service) GetNotMutualFollowers(ctx context.Context) ([]models.User, e

bt := models.UsersBatchTypeNotMutual

err = svc.storeUsers(ctx, models.UsersBatch{
batch := models.UsersBatch{
Users: notmutual,
Type: bt,
CreatedAt: time.Now(),
})
if err != nil {
}

if err = svc.storeUsers(ctx, batch); err != nil && !errors.Is(err, ErrNoUsers) {
return nil, fmt.Errorf("store users [%s]: %w", bt, err)
}

Expand Down Expand Up @@ -889,7 +885,7 @@ func (svc *Service) UploadMedia(ctx context.Context, file io.Reader, mt media.Ty
}

if !mt.Valid() {
return errors.New("media type is invalid")
return fmt.Errorf("media type is invalid: %s", mt)
}

file, err := media.AddBorders(file, mt)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ GO_BUILD_PACKAGE="${REPO_ROOT}/cmd/${APP}"

rm -rf "${BIN_OUT}"

go build -o "${BIN_OUT}" -a -ldflags "${GO_BUILD_LDFLAGS}" "${GO_BUILD_PACKAGE}"
go build -o "${BIN_OUT}" -a -trimpath -ldflags "${GO_BUILD_LDFLAGS}" "${GO_BUILD_PACKAGE}"

echo "Binary compiled at ${BIN_OUT}"
46 changes: 15 additions & 31 deletions vendor/github.com/Davincible/goinsta/v3/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 24 additions & 44 deletions vendor/github.com/Davincible/goinsta/v3/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vendor/github.com/Davincible/goinsta/v3/activity.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 71b0af9

Please sign in to comment.