Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/miscRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

return data.symbols.map((s) => {
const exchange = s.exchange.split(' ')[0];
const id = `${exchange.toUpperCase()}:${s.symbol}`;
const id = s.prefix ? `${s.prefix}:${s.symbol}` : `${exchange.toUpperCase()}:${s.symbol}`;

return {
id,
Expand Down Expand Up @@ -427,43 +427,43 @@
* @param {string} [location] Auth page location (For france: https://fr.tradingview.com/)
* @returns {Promise<User>} Token
*/
async getUser(session, signature = '', location = 'https://www.tradingview.com/') {
const { data, headers } = await axios.get(location, {
headers: {
cookie: genAuthCookies(session, signature),
},
maxRedirects: 0,
validateStatus,
});

if (data.includes('auth_token')) {
return {
id: /"id":([0-9]{1,10}),/.exec(data)?.[1],
username: /"username":"(.*?)"/.exec(data)?.[1],
firstName: /"first_name":"(.*?)"/.exec(data)?.[1],
lastName: /"last_name":"(.*?)"/.exec(data)?.[1],
reputation: parseFloat(/"reputation":(.*?),/.exec(data)?.[1] || 0),
following: parseFloat(/,"following":([0-9]*?),/.exec(data)?.[1] || 0),
followers: parseFloat(/,"followers":([0-9]*?),/.exec(data)?.[1] || 0),
notifications: {
following: parseFloat(/"notification_count":\{"following":([0-9]*),/.exec(data)?.[1] ?? 0),
user: parseFloat(/"notification_count":\{"following":[0-9]*,"user":([0-9]*)/.exec(data)?.[1] ?? 0),
},
session,
signature,
sessionHash: /"session_hash":"(.*?)"/.exec(data)?.[1],
privateChannel: /"private_channel":"(.*?)"/.exec(data)?.[1],
authToken: /"auth_token":"(.*?)"/.exec(data)?.[1],
joinDate: new Date(/"date_joined":"(.*?)"/.exec(data)?.[1] || 0),
};
}

if (headers.location !== location) {
return this.getUser(session, signature, headers.location);
}

throw new Error('Wrong or expired sessionid/signature');
},

Check notice on line 466 in src/miscRequests.js

View check run for this annotation

codefactor.io / CodeFactor

src/miscRequests.js#L430-L466

Complex Method

/**
* Get user's private indicators from a 'sessionid' cookie
Expand Down