Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 096cb8a

Browse files
committed
TODO: test implementation
1 parent de029fd commit 096cb8a

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

src/igservice.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export class IGService {
4747
return data.map(e => { return { 'parent': parent, 'child': e.id } });
4848
}
4949

50-
public dataStorage(keyMap: any, data: Array<any>, collectionName: string) {
50+
public dataStorage(keyMap: any = {}, data: Array<any>, collectionName: string) {
51+
return IGService.dataStorage(keyMap, data, collectionName);
52+
}
53+
public static dataStorage(keyMap: any = {}, data: Array<any>, collectionName: string) {
5154
return collection(collectionName)
5255
.then(collection => collection.insertMany(
5356
[...removeKey(data.map(e => Object.assign(e._params, keyMap)), "_session", "account")])
@@ -65,7 +68,7 @@ export class IGService {
6568
public login() {
6669
return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password))
6770
}
68-
public static login(){
71+
public static login() {
6972
return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password))
7073
}
7174
}

src/index.ts

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,57 @@ function handleWithDelay<T>(delayProcess: number = 500, dataSet: Array<any>, han
1919
return outData.values
2020
}
2121

22-
// let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id))
23-
// userMedia.then(tempMedia => console.log(tempMedia[0]))
24-
// let account = user
25-
// user.account().then((account:any) => user.getAccount(account.id)).then(console.log)
22+
let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id))
23+
userMedia.then(tempMedia => tempMedia.forEach((media: any) => IGService.getEventEmiter().emit("media", media)))
24+
let account = user.account().then((account: any) =>
25+
user.getAccount(account.id).then(account => IGService.getEventEmiter().emit("media", account))
26+
)
2627

2728

2829
let followers = user.search("luna2d")
2930
.then((account: any) => user.getUserFollowers(account.id))
31+
32+
followers.then((accounts: Array<any>) =>
33+
accounts.forEach(account => IGService.getEventEmiter().emit("user", account))
34+
)
35+
36+
37+
38+
39+
let fullFollwers = followers
40+
.then((accounts: Array<any>) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount))
41+
42+
fullFollwers.then(array => array.forEach(element => {
43+
element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value))
44+
45+
}))
46+
47+
3048
// let fullFollwers = followers
3149
// .then((accounts: Array<any>) => Promise.all(accounts.map(account => user.getAccount(account.id))))
3250
// followers.then(_ => console.log(_.length))
3351
// console.log(user.getAccount)
34-
3552
// fullFollwers.then(value => console.log("all has been Processed" + value.length))
3653

3754

3855

3956
let following = user.account()
4057
.then((account: any) => user.getUserFollowing(account.id))
58+
59+
following.then((accounts: Array<any>) =>
60+
accounts.forEach(account => IGService.getEventEmiter().emit("user", account))
61+
)
62+
63+
64+
65+
66+
let fullFollowin = following
67+
.then((accounts: Array<any>) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount))
68+
69+
fullFollowin.then(array => array.forEach(element => {
70+
element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value))
71+
72+
}))
4173
// let fullFollowin = following
4274
// .then((accounts: Array<any>) => Promise.all(accounts.map(account => user.getAccount(account.id))))
4375

@@ -47,4 +79,36 @@ let following = user.account()
4779
// let mediaLikers = userMedia.map((_: any) => _.id)
4880
// .then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaLikersHandler(id))))
4981

50-
// followers.then((dataSet => dataSet.slice(2))).then(console.log)
82+
// followers.then((dataSet => dataSet.slice(2))).then(console.log)
83+
84+
85+
86+
87+
88+
89+
let mediaComments = userMedia.map((_: any) => _.id)
90+
.then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaCommentsHandler(id))))
91+
92+
let mediaLikers = userMedia.map((_: any) => _.id)
93+
.then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaLikersHandler(id))))
94+
95+
followers.then((dataSet => dataSet.slice(2))).then(console.log)
96+
let keyMedia = "media"
97+
IGService.getEventEmiter().on(keyMedia, (data:any)=>{
98+
IGService.dataStorage({}, data, keyMedia)
99+
})
100+
let keyUser = "user"
101+
IGService.getEventEmiter().on(keyUser, (data:any)=>{
102+
IGService.dataStorage({}, data, keyUser)
103+
104+
})
105+
let keyFollowing = "following"
106+
IGService.getEventEmiter().on(keyFollowing, (data:any)=>{
107+
IGService.dataStorage({}, data, keyFollowing)
108+
109+
})
110+
let keyFollower = "follower"
111+
IGService.getEventEmiter().on(keyFollowing, (data:any)=>{
112+
IGService.dataStorage({}, data, keyFollower)
113+
114+
})

0 commit comments

Comments
 (0)