Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 71b0af9

Browse files
authored
fix: Issue with login and sorting order (#235)
* 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
1 parent b0c9b08 commit 71b0af9

31 files changed

+579
-579
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/obalunenko/instadiff-cli
33
go 1.19
44

55
require (
6-
github.com/Davincible/goinsta/v3 v3.1.3
6+
github.com/Davincible/goinsta/v3 v3.2.6
77
github.com/briandowns/spinner v1.20.0
88
github.com/disintegration/imaging v1.6.2
99
github.com/hashicorp/go-multierror v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7O
4040
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
4141
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4242
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
43-
github.com/Davincible/goinsta/v3 v3.1.3 h1:0XMj7upEgRA/IWSDRS1+d8DLNYtRttCASKaNzQn1H7M=
44-
github.com/Davincible/goinsta/v3 v3.1.3/go.mod h1:jqCJarVJYVy1zJiXoIWU1zOZKmVCwdeQZbxIp8d+i3g=
43+
github.com/Davincible/goinsta/v3 v3.2.6 h1:+lNIWU6NABWd2VSGe83UQypnef+kzWwjmfgGihPbwD8=
44+
github.com/Davincible/goinsta/v3 v3.2.6/go.mod h1:jIDhrWZmttL/gtXj/mkCaZyeNdAAqW3UYjasOUW0YEw=
4545
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
4646
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
4747
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=

internal/client/instagram/instagram.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ func (c *Client) UploadMedia(ctx context.Context, file io.Reader, mt media.Type)
253253
Album: nil,
254254
Caption: "",
255255
IsStory: isStory(mt),
256-
IsIGTV: false,
257-
Title: "",
258-
IGTVPreview: false,
259256
MuteAudio: false,
260257
DisableComments: false,
261258
DisableLikeViewCount: false,
@@ -317,7 +314,7 @@ func (c *Client) UserFollowers(ctx context.Context, user models.User) ([]models.
317314

318315
u.SetInstagram(c.client)
319316

320-
return c.makeUsersList(ctx, u.Followers())
317+
return c.makeUsersList(ctx, u.Followers(""))
321318
}
322319

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

330327
u.SetInstagram(c.client)
331328

332-
return c.makeUsersList(ctx, u.Following())
329+
return c.makeUsersList(ctx, u.Following("", goinsta.EarliestOrder))
333330
}
334331

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

373370
// Followers returns list of followers.
374371
func (c *Client) Followers(ctx context.Context) ([]models.User, error) {
375-
return c.makeUsersList(ctx, c.client.Account.Followers())
372+
return c.makeUsersList(ctx, c.client.Account.Followers(""))
376373
}
377374

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

383380
// Username returns current account username.

internal/service/service.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,13 @@ func (svc *Service) getUsers(ctx context.Context, bt models.UsersBatchType) ([]m
184184
return nil, fmt.Errorf("find diff users: %w", err)
185185
}
186186

187-
err = svc.storeUsers(ctx, models.UsersBatch{
187+
batch := models.UsersBatch{
188188
Users: users,
189189
Type: bt,
190190
CreatedAt: time.Now(),
191-
})
192-
if err != nil {
193-
if errors.Is(err, ErrNoUsers) {
194-
log.WithError(ctx, err).Warn("Failed to store users")
195-
196-
return users, nil
197-
}
191+
}
198192

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

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

301296
bt := models.UsersBatchTypeNotMutual
302297

303-
err = svc.storeUsers(ctx, models.UsersBatch{
298+
batch := models.UsersBatch{
304299
Users: notmutual,
305300
Type: bt,
306301
CreatedAt: time.Now(),
307-
})
308-
if err != nil {
302+
}
303+
304+
if err = svc.storeUsers(ctx, batch); err != nil && !errors.Is(err, ErrNoUsers) {
309305
return nil, fmt.Errorf("store users [%s]: %w", bt, err)
310306
}
311307

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

891887
if !mt.Valid() {
892-
return errors.New("media type is invalid")
888+
return fmt.Errorf("media type is invalid: %s", mt)
893889
}
894890

895891
file, err := media.AddBorders(file, mt)

scripts/build/compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ GO_BUILD_PACKAGE="${REPO_ROOT}/cmd/${APP}"
3939

4040
rm -rf "${BIN_OUT}"
4141

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

4444
echo "Binary compiled at ${BIN_OUT}"

vendor/github.com/Davincible/goinsta/v3/README.md

Lines changed: 15 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Davincible/goinsta/v3/account.go

Lines changed: 24 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Davincible/goinsta/v3/activity.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)