Skip to content

Commit

Permalink
Added save state as login option
Browse files Browse the repository at this point in the history
  • Loading branch information
iyarsius committed Sep 6, 2024
1 parent 2b439fb commit 3d80713
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
8 changes: 6 additions & 2 deletions src/structures/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,14 @@ class Client extends EventEmitter {
* @param {string} password The password of the Instagram account.
* @returns {Promise<Object>}
*/
async login(username, password) {
async login(username, password, options) {
try {
const ig = withFbns(withRealtime(new IgApiClient()));
// ig.request.end$.subscribe(Util.saveFile(ig));

if (options.saveState) {
ig.request.end$.subscribe(Util.saveFile(ig));
};

ig.state.generateDevice(username);

const state = Util.readFile();
Expand Down
54 changes: 29 additions & 25 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare module "node-ig-framework" {
public fetchChat(chatID: string, force?: boolean): Promise<Chat>;
public fetchUser(query: string, force?: boolean): Promise<User>;
public logout(): void;
public login(username: string, password: string): Promise<LoginResponse>;
public login(username: string, password: string, options?: LoginOptions): Promise<LoginResponse>;
public toJSON(): ClientJSON;

public on<K extends keyof ClientEvents>(
Expand Down Expand Up @@ -172,9 +172,9 @@ declare module "node-ig-framework" {
public content?: string;
public storyShareData:
| {
author: User | null;
sourceURL: string | null;
}
author: User | null;
sourceURL: string | null;
}
| undefined;
public mediaData: {
isLiked: boolean;
Expand All @@ -200,9 +200,9 @@ declare module "node-ig-framework" {
};
public voiceData:
| {
duration: number;
sourceURL: string;
}
duration: number;
sourceURL: string;
}
| undefined;
public likes: MessageLike[];
public readonly chat: Chat;
Expand Down Expand Up @@ -341,6 +341,10 @@ declare module "node-ig-framework" {
): MediaShareLocation | undefined;
}

interface LoginOptions {
saveState?: boolean;
};

interface StartTypingOptions {
duration: number;
disableOnSend: boolean;
Expand Down Expand Up @@ -407,27 +411,27 @@ declare module "node-ig-framework" {
mediaShareUrl?: string;
timestamp: string;
location?:
| {
coordinates: string | undefined;
address: string | undefined;
city: string | undefined;
name: string | undefined;
shortName: string | undefined;
}
| undefined;
};
voiceData:
| {
duration: number;
sourceURL: string;
}
coordinates: string | undefined;
address: string | undefined;
city: string | undefined;
name: string | undefined;
shortName: string | undefined;
}
| undefined;
};
voiceData:
| {
duration: number;
sourceURL: string;
}
| undefined;
storyShareData:
| {
author: User | null;
sourceURL: string | null;
}
| undefined;
| {
author: User | null;
sourceURL: string | null;
}
| undefined;
likes: MessageLike[];
}

Expand Down

0 comments on commit 3d80713

Please sign in to comment.