rapido-fca 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
var utils = require("./utils");
|
|
4
4
|
var cheerio = require("cheerio");
|
|
5
5
|
var log = require("npmlog");
|
|
6
|
-
/*var { getThemeColors } = require("../../func/utils/log.js");
|
|
7
|
-
var logger = require("../../func/utils/log.js");
|
|
8
|
-
var { cra, cv, cb, co } = getThemeColors();*/
|
|
9
6
|
log.maxRecordSize = 100;
|
|
10
7
|
var checkVerified = null;
|
|
11
8
|
const Boolean_Option = ['online', 'selfListen', 'listenEvents', 'updatePresence', 'forceLogin', 'autoMarkDelivery', 'autoMarkRead', 'listenTyping', 'autoReconnect', 'emitReady'];
|
|
@@ -114,10 +111,10 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
114
111
|
}
|
|
115
112
|
} catch { }
|
|
116
113
|
if (fb_dtsg) {
|
|
117
|
-
|
|
114
|
+
log.info("Login", "Found fb_dtsg token");
|
|
118
115
|
}
|
|
119
116
|
} catch (e) {
|
|
120
|
-
|
|
117
|
+
log.error("Login", "Error finding fb_dtsg token");
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
extractFromHTML();
|
|
@@ -126,33 +123,33 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
126
123
|
var userCookie = cookies.find(cookie => cookie.cookieString().startsWith("c_user="));
|
|
127
124
|
var tiktikCookie = cookies.find(cookie => cookie.cookieString().startsWith("i_user="));
|
|
128
125
|
if (!userCookie && !tiktikCookie) {
|
|
129
|
-
return log.error("
|
|
126
|
+
return log.error("Login", "Invalid cookie state");
|
|
130
127
|
}
|
|
131
128
|
if (html.includes("/checkpoint/block/?next")) {
|
|
132
|
-
return log.error('
|
|
129
|
+
return log.error('Login', "Appstate is blocked - please renew it");
|
|
133
130
|
}
|
|
134
131
|
userID = (tiktikCookie || userCookie).cookieString().split("=")[1];
|
|
135
|
-
|
|
132
|
+
log.info("Login", `User ID: ${api.getCurrentUserID()}`);
|
|
136
133
|
try { clearInterval(checkVerified); } catch (_) { }
|
|
137
134
|
const clientID = (Math.random() * 2147483648 | 0).toString(16);
|
|
138
|
-
let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=
|
|
139
|
-
let region = "
|
|
135
|
+
let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=pnb&sid=${userID}`;
|
|
136
|
+
let region = "PNB";
|
|
140
137
|
|
|
141
138
|
try {
|
|
142
139
|
const endpointMatch = html.match(/"endpoint":"([^"]+)"/);
|
|
143
140
|
if (endpointMatch.input.includes("601051028565049")) {
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
log.error("Login", "Login error detected");
|
|
142
|
+
ditconmemay = true;
|
|
146
143
|
}
|
|
147
144
|
if (endpointMatch) {
|
|
148
145
|
mqttEndpoint = endpointMatch[1].replace(/\\\//g, '/');
|
|
149
146
|
const url = new URL(mqttEndpoint);
|
|
150
|
-
region = url.searchParams.get('region')?.toUpperCase() || "
|
|
147
|
+
region = url.searchParams.get('region')?.toUpperCase() || "PNB";
|
|
151
148
|
}
|
|
152
149
|
} catch (e) {
|
|
153
|
-
|
|
150
|
+
log.warn("Login", "Using default MQTT endpoint");
|
|
154
151
|
}
|
|
155
|
-
log.info(
|
|
152
|
+
log.info("Login", `Connecting to region: ${region}`);
|
|
156
153
|
var ctx = {
|
|
157
154
|
userID: userID,
|
|
158
155
|
jar: jar,
|
|
@@ -214,11 +211,10 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
214
211
|
|
|
215
212
|
return newDtsg;
|
|
216
213
|
} catch (e) {
|
|
217
|
-
|
|
214
|
+
log.error("Login", "Error getting fresh dtsg token");
|
|
218
215
|
return null;
|
|
219
216
|
}
|
|
220
217
|
};
|
|
221
|
-
//if (noMqttData) api.htmlData = noMqttData;
|
|
222
218
|
require('fs').readdirSync(__dirname + '/src/').filter(v => v.endsWith('.js')).forEach(v => { api[v.replace('.js', '')] = require(`./src/${v}`)(utils.makeDefaults(html, userID, ctx), api, ctx); });
|
|
223
219
|
api.listen = api.listenMqtt;
|
|
224
220
|
return {
|
|
@@ -251,7 +247,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
251
247
|
const cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
|
252
248
|
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
|
253
249
|
});
|
|
254
|
-
log.info("
|
|
250
|
+
log.info("Login", "Attempting login...");
|
|
255
251
|
const loginRes = await utils.post(
|
|
256
252
|
"https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110",
|
|
257
253
|
jar,
|
|
@@ -262,7 +258,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
262
258
|
const headers = loginRes.headers;
|
|
263
259
|
if (!headers.location) throw new Error("Wrong username/password.");
|
|
264
260
|
if (headers.location.includes('https://www.facebook.com/checkpoint/')) {
|
|
265
|
-
log.info("
|
|
261
|
+
log.info("Login", "Login approvals enabled");
|
|
266
262
|
const checkpointRes = await utils.get(headers.location, jar, null, loginOptions);
|
|
267
263
|
await utils.saveCookies(jar)(checkpointRes);
|
|
268
264
|
const checkpointHtml = checkpointRes.body;
|
|
@@ -322,7 +318,6 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
322
318
|
};
|
|
323
319
|
}
|
|
324
320
|
|
|
325
|
-
|
|
326
321
|
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
|
327
322
|
let mainPromise = null;
|
|
328
323
|
const jar = utils.getJar();
|
|
@@ -397,7 +392,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
397
392
|
|
|
398
393
|
mainPromise
|
|
399
394
|
.then(async () => {
|
|
400
|
-
log.info(
|
|
395
|
+
log.info("Login", `Successfully logged in as ${ctx.userID} in region ${ctx.region}`);
|
|
401
396
|
callback(null, api);
|
|
402
397
|
})
|
|
403
398
|
.catch(e => {
|
|
@@ -405,7 +400,6 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
405
400
|
});
|
|
406
401
|
}
|
|
407
402
|
|
|
408
|
-
|
|
409
403
|
function login(loginData, options, callback) {
|
|
410
404
|
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
|
411
405
|
callback = options;
|
|
@@ -456,5 +450,4 @@ function login(loginData, options, callback) {
|
|
|
456
450
|
return returnPromise;
|
|
457
451
|
}
|
|
458
452
|
|
|
459
|
-
|
|
460
453
|
module.exports = login;
|