Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqiyue committed Jun 15, 2022
1 parent ace408a commit bec028b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/fetchFriends.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/search_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ JSESSIONID = "ajax:3513817161874270460";
useCache: false
})

let peopleSearchScroller = client.search.searchOwnConnections();
let peopleSearchScroller = client.clone().search.searchOwnConnections();
let res = [];
while(!peopleSearchScroller.hitEndOfResults){
res.push(...await peopleSearchScroller.scrollNext());
}
console.log(res)

peopleSearchScroller = client.search.searchOwnConnections();
peopleSearchScroller = client.clone().search.searchOwnConnections();
res = []
while(!peopleSearchScroller.hitEndOfResults){
res.push(...await peopleSearchScroller.scrollNext());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shiqiyue-linkedin-private-api",
"version": "1.1.23",
"version": "1.1.24",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 13 additions & 0 deletions src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LinkedInRequest } from './linkedin-request';
import { Login } from './login';
import {DecorationIds} from "./decorationIds";
import {Profile} from "../entities";
import {AuthCookies} from "../types";

interface ClientOpts {
proxy?: AxiosProxyConfig;
Expand All @@ -26,6 +27,8 @@ export class Client {

li_at?: string;

AuthCookies?:AuthCookies;

constructor({ proxy,httpAgent, httpsAgent,decorationIds }: ClientOpts = {}) {
this.request = new LinkedInRequest({ proxy,httpAgent, httpsAgent,decorationIds });
}
Expand All @@ -41,4 +44,14 @@ export class Client {
conversation = new ConversationRepository({ client: this });

message = new MessageRepository({ client: this });

clone(): Client {
const client = new Client(this.request.configs);
client.login.userCookie({
cookies: this.AuthCookies,
useCache: false
})
client.myProfile = this.myProfile
return client
}
}
16 changes: 5 additions & 11 deletions src/core/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,21 @@ export class Login {
return this.client;
}

async userCookie({
userCookie({
username,
cookies,
useCache = true,
}: {
username?: string;
cookies: AuthCookies;
useCache?: boolean;
}): Promise<Client> {
const cachedSessions = await this.readCacheFile();

if (this.tryCacheLogin({ useCache, cachedSessions, username })) {
return this.client;
}
}): Client {
console.log(username)

this.setRequestHeaders({ cookies });
this.client.li_at = cookies.li_at
this.client.AuthCookies = cookies


if (username) {
//fs.writeFile(SESSIONS_PATH, JSON.stringify({ ...cachedSessions, [username]: cookies }));
}

return this.client;
}
Expand Down
20 changes: 7 additions & 13 deletions src/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class Request {

decorationIds: DecorationIds;

configs?: any

constructor({ proxy,httpAgent,httpsAgent,decorationIds }: RequestOpts = {}) {
this.request = axios.create({
paramsSerializer,
Expand All @@ -41,20 +43,12 @@ export class Request {
this.decorationIds = defaultDecorationIds()
}

/* this.request.interceptors.request.use(function (config){
console.log('请求参数:', config)
return config
}, error => {
return Promise.reject(error);
})*/
/* this.request.interceptors.response.use(function (response){
console.log('返回结果', response)
return response
}, error => {
console.log('返回错误:', error)
return Promise.reject(error)
})*/
this.request.defaults.adapter = require('axios/lib/adapters/http');
this.configs = {}
this.configs.proxy = proxy
this.configs.httpAgent = httpAgent
this.configs.httpsAgent = httpsAgent
this.configs.decorationIds = decorationIds

}

Expand Down

0 comments on commit bec028b

Please sign in to comment.