node-ainzfb-new 1.7.9-uOw19mf → 1.7.10-4-fix

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +83 -41
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -9,7 +9,7 @@ process.env.UV_THREADPOOL_SIZE = require('os').cpus().length;
9
9
  global.isThread = new Array();
10
10
  global.isUser = new Array();
11
11
  global.startTime = Date.now();
12
- global.getText = require('gettext.js')();
12
+ global.getText = require('gettext.js')();
13
13
 
14
14
  /!-[ Require All Package Need Use ]-!/
15
15
  /*globalThis.Fca = new Object({
@@ -19,7 +19,7 @@ global.getText = require('gettext.js')();
19
19
  var utils = require("./utils"),
20
20
  cheerio = require("cheerio"),
21
21
  log = require("npmlog"),
22
- //{ getAccessToken } = require('./Extra/ExtraAddons'),
22
+ //{ getAccessToken } = require('./Extra/ExtraAddons'),
23
23
  logger = require('./logger'),
24
24
  fs = require('fs-extra'),
25
25
  getText = require('gettext.js')(),
@@ -90,7 +90,7 @@ var checkVerified = null;
90
90
  /!-[ Function setOptions ]-!/
91
91
 
92
92
  function setOptions(globalOptions, options) {
93
- Object.keys(options).map(function(key) {
93
+ Object.keys(options).map(function (key) {
94
94
  switch (key) {
95
95
  case 'pauseLog':
96
96
  if (options.pauseLog) log.pause();
@@ -158,7 +158,7 @@ function setOptions(globalOptions, options) {
158
158
  /!-[ Function BuildAPI ]-!/
159
159
 
160
160
  async function buildAPI(globalOptions, html, jar) {
161
- var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) { return val.cookieString().split("=")[0] === "c_user"; });
161
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) { return val.cookieString().split("=")[0] === "c_user"; });
162
162
 
163
163
  if (maybeCookie.length === 0) throw { error: Language.ErrAppState };
164
164
 
@@ -222,7 +222,9 @@ async function buildAPI(globalOptions, html, jar) {
222
222
  syncToken: undefined,
223
223
  mqttEndpoint,
224
224
  region,
225
- firstListen: true
225
+ firstListen: true,
226
+ wsReqNumber: 0,
227
+ wsTaskNumber: 0
226
228
  };
227
229
 
228
230
  var api = {
@@ -244,7 +246,7 @@ async function buildAPI(globalOptions, html, jar) {
244
246
  }
245
247
 
246
248
  function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
247
- return function(res) {
249
+ return function (res) {
248
250
  var html = res.body;
249
251
  var $ = cheerio.load(html);
250
252
  var arr = [];
@@ -252,7 +254,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
252
254
  // This will be empty, but just to be sure we leave it
253
255
  $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
254
256
 
255
- arr = arr.filter(function(v) {
257
+ arr = arr.filter(function (v) {
256
258
  return v.val && v.val.length;
257
259
  });
258
260
 
@@ -278,7 +280,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
278
280
  //
279
281
  // ---------- Very Hacky Part Starts -----------------
280
282
  var willBeCookies = html.split("\"_js_");
281
- willBeCookies.slice(1).map(function(val) {
283
+ willBeCookies.slice(1).map(function (val) {
282
284
  var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
283
285
  jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
284
286
  });
@@ -288,7 +290,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
288
290
  return utils
289
291
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
290
292
  .then(utils.saveCookies(jar))
291
- .then(function(res) {
293
+ .then(function (res) {
292
294
  var headers = res.headers;
293
295
  if (!headers.location) throw { error: Language.InvaildAccount };
294
296
 
@@ -300,21 +302,21 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
300
302
  return utils
301
303
  .get(headers.location, jar, null, loginOptions)
302
304
  .then(utils.saveCookies(jar))
303
- .then(function(res) {
305
+ .then(function (res) {
304
306
  var html = res.body;
305
307
  // Make the form in advance which will contain the fb_dtsg and nh
306
308
  var $ = cheerio.load(html);
307
309
  var arr = [];
308
310
  $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
309
311
 
310
- arr = arr.filter(function(v) {
312
+ arr = arr.filter(function (v) {
311
313
  return v.val && v.val.length;
312
314
  });
313
315
 
314
316
  var form = utils.arrToForm(arr);
315
317
  if (html.indexOf("checkpoint/?next") > -1) {
316
318
  setTimeout(() => {
317
- checkVerified = setInterval((_form) => {}, 5000, {
319
+ checkVerified = setInterval((_form) => { }, 5000, {
318
320
  fb_dtsg: form.fb_dtsg,
319
321
  jazoest: form.jazoest,
320
322
  dpr: 1
@@ -327,7 +329,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
327
329
  form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
328
330
  var prResolve = null;
329
331
  var prReject = null;
330
- var rtPromise = new Promise(function(resolve, reject) {
332
+ var rtPromise = new Promise(function (resolve, reject) {
331
333
  prResolve = resolve;
332
334
  prReject = reject;
333
335
  });
@@ -335,7 +337,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
335
337
  utils
336
338
  .post(nextURL, jar, form, loginOptions)
337
339
  .then(utils.saveCookies(jar))
338
- .then(function(res) {
340
+ .then(function (res) {
339
341
  var $ = cheerio.load(res.body);
340
342
  var error = $("#approvals_code").parent().attr("data-xui-error");
341
343
  if (error) {
@@ -347,7 +349,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
347
349
  };
348
350
  }
349
351
  })
350
- .then(function() {
352
+ .then(function () {
351
353
  // Use the same form (safe I hope)
352
354
  delete form.no_fido;
353
355
  delete form.approvals_code;
@@ -355,14 +357,14 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
355
357
 
356
358
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
357
359
  })
358
- .then(function(res) {
360
+ .then(function (res) {
359
361
  var headers = res.headers;
360
362
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
361
363
 
362
364
  var appState = utils.getAppState(jar);
363
365
 
364
366
  if (callback === prCallback) {
365
- callback = function(err, api) {
367
+ callback = function (err, api) {
366
368
  if (err) return prReject(err);
367
369
  return prResolve(api);
368
370
  };
@@ -372,7 +374,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
372
374
  // and will then complete the login process
373
375
  return loginHelper(appState, email, password, loginOptions, callback);
374
376
  })
375
- .catch(function(err) {
377
+ .catch(function (err) {
376
378
  // Check if using Promise instead of callback
377
379
  if (callback === prCallback) prReject(err);
378
380
  else callback(err);
@@ -388,7 +390,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
388
390
  clearInterval(checkVerified);
389
391
  logger(Language.VerifiedCheck, "[ FCA-SUS ]");
390
392
  if (callback === prCallback) {
391
- callback = function(err, api) {
393
+ callback = function (err, api) {
392
394
  if (err) return prReject(err);
393
395
  return prResolve(api);
394
396
  };
@@ -414,13 +416,13 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
414
416
  return utils
415
417
  .post(nextURL, jar, form, loginOptions)
416
418
  .then(utils.saveCookies(jar))
417
- .then(function() {
419
+ .then(function () {
418
420
  // Use the same form (safe I hope)
419
421
  form.name_action_selected = 'save_device';
420
422
 
421
423
  return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
422
424
  })
423
- .then(function(res) {
425
+ .then(function (res) {
424
426
  var headers = res.headers;
425
427
 
426
428
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
@@ -530,7 +532,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
530
532
  // });
531
533
 
532
534
  logger(Language.OnProcess, "[ FCA-SUS ]");
533
- var backup = async(data) => {
535
+ var backup = async (data) => {
534
536
  if (fs.existsSync('./appstate.json')) {
535
537
  try {
536
538
  fs.writeFileSync('./appstate.json', data);
@@ -578,9 +580,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
578
580
  {
579
581
  if (process.env["REPL_ID"] == undefined) {
580
582
  try {
581
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
582
-
583
- process.env['FBKEY'] = JSON.parse(body).response.key;
583
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
584
+
585
+ process.env['FBKEY'] = JSON.parse(body).response.key;
584
586
  } catch (e) {
585
587
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
586
588
  logger.Error();
@@ -609,7 +611,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
609
611
  case "android":
610
612
  {
611
613
  try {
612
- var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
614
+ var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
613
615
  process.env['FBKEY'] = JSON.parse(body).response.key;
614
616
  } catch (e) {
615
617
  logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
@@ -630,7 +632,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
630
632
  case true:
631
633
  {
632
634
  appState = JSON.parse(JSON.stringify(appState, null, "\t"));
633
- //console.log(appState);
635
+ //console.log(appState);
634
636
  switch (utils.getType(appState)) {
635
637
  case "Array":
636
638
  {
@@ -727,9 +729,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
727
729
  case "String":
728
730
  {
729
731
  logger(Language.EncryptStateOff, "[ FCA-SUS ]");
730
- //console.log("hello")
732
+ //console.log("hello")
731
733
  try {
732
- // appState = appState;
734
+ // appState = appState;
733
735
  appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
734
736
  logger(Language.DecryptSuccess, '[ FCA-SUS ]');
735
737
  } catch (e) {
@@ -825,7 +827,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
825
827
  }
826
828
  }
827
829
  try {
828
- appState.map(function(c) {
830
+ appState.map(function (c) {
829
831
  var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
830
832
  jar.setCookie(str, "http://" + c.domain);
831
833
  });
@@ -949,7 +951,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
949
951
  .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
950
952
  .then(utils.saveCookies(jar))
951
953
  .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
952
- .then(function() {
954
+ .then(function () {
953
955
  return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
954
956
  });
955
957
  }
@@ -960,15 +962,54 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
960
962
  var _defaultFuncs = null;
961
963
  var api = null;
962
964
 
965
+ let redirect = [1, "https://m.facebook.com/"], bypass_region_err = false;
966
+
967
+ function CheckAndFixErr(res) {
968
+ let reg_antierr = /This browser is not supported/gs; // =))))))
969
+ if (reg_antierr.test(res.body)) {
970
+ const Data = JSON.stringify(res.body);
971
+ const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
972
+ if (Dt_Check == undefined) return res
973
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
974
+ if (Dt_Check == undefined || Dt_Check == "") return res
975
+ const final_fid = fid.split(`\\`)[0];
976
+ if (final_fid == undefined || final_fid == '') return res;
977
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
978
+ bypass_region_err = true;
979
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
980
+ }
981
+ else return res
982
+ }
983
+
984
+ function Redirect(res) {
985
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
986
+ redirect = reg.exec(res.body);
987
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
988
+ return res;
989
+ }
990
+
963
991
  mainPromise = mainPromise
964
- .then(function(res) {
992
+ .then(function (res) {
965
993
  // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
966
994
  var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
967
995
  var redirect = reg.exec(res.body);
968
996
  if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
969
997
  return res;
970
998
  })
971
- .then(async function(res) {
999
+ .then(res => Redirect(res))
1000
+ .then(res => CheckAndFixErr(res))
1001
+ .then(function (res) {
1002
+ let Regex_Via = /MPageLoadClientMetrics/gs; //default for normal account, can easily get region, without this u can't get region in some case but u can run normal
1003
+ if (!Regex_Via.test(res.body)) {
1004
+ //www.facebook.com
1005
+ globalOptions.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1";
1006
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
1007
+ }
1008
+ else return res
1009
+ })
1010
+ .then(res => Redirect(res))
1011
+ .then(res => CheckAndFixErr(res))
1012
+ .then(async function (res) {
972
1013
  var html = res.body;
973
1014
  var stuff = await buildAPI(globalOptions, html, jar);
974
1015
  ctx = stuff[0];
@@ -976,13 +1017,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
976
1017
  api = stuff[2];
977
1018
  return res;
978
1019
  });
1020
+
979
1021
  // given a pageID we log in as a page
980
1022
  if (globalOptions.pageID) {
981
1023
  mainPromise = mainPromise
982
- .then(function() {
1024
+ .then(function () {
983
1025
  return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
984
1026
  })
985
- .then(function(resData) {
1027
+ .then(function (resData) {
986
1028
  var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
987
1029
  url = url.substring(0, url.length - 1);
988
1030
  return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
@@ -991,14 +1033,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
991
1033
 
992
1034
  // At the end we call the callback or catch an exception
993
1035
  mainPromise
994
- .then(function() {
1036
+ .then(function () {
995
1037
  logger(Language.DoneLogin, "[ FCA-SUS ]");
996
1038
  logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
997
1039
  //!---------- Auto Check, Update START -----------------!//
998
1040
  var Fetch = require('got');
999
1041
  var { readFileSync } = require('fs-extra');
1000
1042
  const { execSync } = require('child_process');
1001
- Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async(res) => {
1043
+ Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async (res) => {
1002
1044
  const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb-new/package.json')).version;
1003
1045
  if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
1004
1046
  log.warn("[ FCA-SUS ] •", getText.gettext(Language.NewVersionFound, JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version, JSON.parse(res.body.toString()).version));
@@ -1038,7 +1080,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
1038
1080
  callback(null, api);
1039
1081
  }
1040
1082
  });
1041
- }).catch(function(e) {
1083
+ }).catch(function (e) {
1042
1084
  log.error("login", e.error || e);
1043
1085
  callback(e);
1044
1086
  });
@@ -1075,11 +1117,11 @@ function login(loginData, options, callback) {
1075
1117
  if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1076
1118
  var rejectFunc = null;
1077
1119
  var resolveFunc = null;
1078
- var returnPromise = new Promise(function(resolve, reject) {
1120
+ var returnPromise = new Promise(function (resolve, reject) {
1079
1121
  resolveFunc = resolve;
1080
1122
  rejectFunc = reject;
1081
1123
  });
1082
- prCallback = function(error, api) {
1124
+ prCallback = function (error, api) {
1083
1125
  if (error) return rejectFunc(error);
1084
1126
  return resolveFunc(api);
1085
1127
  };
@@ -1089,4 +1131,4 @@ function login(loginData, options, callback) {
1089
1131
  return returnPromise;
1090
1132
  }
1091
1133
 
1092
- module.exports = login;
1134
+ module.exports = login;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ainzfb-new",
3
- "version": "1.7.9-uOw19mf",
3
+ "version": "1.7.10-4-fix",
4
4
  "description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
5
5
  "scripts": {
6
6
  "test": "mocha",