@dongdev/fca-unofficial 0.0.2 → 0.0.4
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 +114 -95
- package/package.json +23 -56
package/index.js
CHANGED
@@ -10,73 +10,76 @@ var defaultLogRecordSize = 100;
|
|
10
10
|
log.maxRecordSize = defaultLogRecordSize;
|
11
11
|
|
12
12
|
function setOptions(globalOptions, options) {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
13
|
+
if (options && typeof options === 'object') {
|
14
|
+
Object.keys(options).map(function (key) {
|
15
|
+
switch (key) {
|
16
|
+
case 'pauseLog':
|
17
|
+
if (options.pauseLog) log.pause();
|
18
|
+
break;
|
19
|
+
case 'online':
|
20
|
+
globalOptions.online = Boolean(options.online);
|
21
|
+
break;
|
22
|
+
case 'logLevel':
|
23
|
+
log.level = options.logLevel;
|
24
|
+
globalOptions.logLevel = options.logLevel;
|
25
|
+
break;
|
26
|
+
case 'logRecordSize':
|
27
|
+
log.maxRecordSize = options.logRecordSize;
|
28
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
29
|
+
break;
|
30
|
+
case 'selfListen':
|
31
|
+
globalOptions.selfListen = Boolean(options.selfListen);
|
32
|
+
break;
|
33
|
+
case 'listenEvents':
|
34
|
+
globalOptions.listenEvents = Boolean(options.listenEvents);
|
35
|
+
break;
|
36
|
+
case 'pageID':
|
37
|
+
globalOptions.pageID = options.pageID.toString();
|
38
|
+
break;
|
39
|
+
case 'updatePresence':
|
40
|
+
globalOptions.updatePresence = Boolean(options.updatePresence);
|
41
|
+
break;
|
42
|
+
case 'forceLogin':
|
43
|
+
globalOptions.forceLogin = Boolean(options.forceLogin);
|
44
|
+
break;
|
45
|
+
case 'userAgent':
|
46
|
+
globalOptions.userAgent = options.userAgent;
|
47
|
+
break;
|
48
|
+
case 'autoMarkDelivery':
|
49
|
+
globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
|
50
|
+
break;
|
51
|
+
case 'autoMarkRead':
|
52
|
+
globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
|
53
|
+
break;
|
54
|
+
case 'listenTyping':
|
55
|
+
globalOptions.listenTyping = Boolean(options.listenTyping);
|
56
|
+
break;
|
57
|
+
case 'proxy':
|
58
|
+
if (typeof options.proxy != "string") {
|
59
|
+
delete globalOptions.proxy;
|
60
|
+
utils.setProxy();
|
61
|
+
} else {
|
62
|
+
globalOptions.proxy = options.proxy;
|
63
|
+
utils.setProxy(globalOptions.proxy);
|
64
|
+
}
|
65
|
+
break;
|
66
|
+
case 'autoReconnect':
|
67
|
+
globalOptions.autoReconnect = Boolean(options.autoReconnect);
|
68
|
+
break;
|
69
|
+
case 'emitReady':
|
70
|
+
globalOptions.emitReady = Boolean(options.emitReady);
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
});
|
77
|
+
} else {
|
78
|
+
log.warn("setOptions", "Invalid or undefined options provided.");
|
79
|
+
}
|
77
80
|
}
|
78
81
|
|
79
|
-
function buildAPI(globalOptions, html, jar) {
|
82
|
+
function buildAPI(globalOptions, html, jar, bypass_region_err) {
|
80
83
|
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) {
|
81
84
|
return val.cookieString().split("=")[0] === "c_user";
|
82
85
|
});
|
@@ -126,6 +129,7 @@ function buildAPI(globalOptions, html, jar) {
|
|
126
129
|
}
|
127
130
|
else {
|
128
131
|
log.warn("login", "Cannot get MQTT region & sequence ID.");
|
132
|
+
log.info('login', 'Bypass vùng tài khoản thành công');
|
129
133
|
noMqttData = html;
|
130
134
|
}
|
131
135
|
}
|
@@ -156,6 +160,7 @@ function buildAPI(globalOptions, html, jar) {
|
|
156
160
|
};
|
157
161
|
|
158
162
|
if (noMqttData) api["htmlData"] = noMqttData;
|
163
|
+
if (bypass_region_err) log.info('login', 'Bypass vùng tài khoản thành công');
|
159
164
|
|
160
165
|
const apiFuncNames = [
|
161
166
|
'addExternalModule',
|
@@ -453,36 +458,50 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
453
458
|
|
454
459
|
var redirect = [1, "https://m.facebook.com/"], bypass_region_err = false, ctx, _defaultFuncs, api;
|
455
460
|
function CheckAndFixErr(res) {
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
461
|
+
let reg_antierr = /This browser is not supported/gs;
|
462
|
+
if (reg_antierr.test(res.body)) {
|
463
|
+
const Data = JSON.stringify(res.body);
|
464
|
+
const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
|
465
|
+
if (Dt_Check == undefined) return res
|
466
|
+
const fid = Dt_Check.split("\\\\")[0];
|
467
|
+
if (Dt_Check == undefined || Dt_Check == "") return res
|
468
|
+
const final_fid = fid.split(`\\`)[0];
|
469
|
+
if (final_fid == undefined || final_fid == '') return res;
|
470
|
+
const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
|
471
|
+
bypass_region_err = true;
|
472
|
+
log.info('login', 'Bypass vùng tài khoản thành công');
|
473
|
+
return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
|
474
|
+
}
|
475
|
+
else return res
|
476
|
+
}
|
477
|
+
function Redirect(res) {
|
478
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
479
|
+
redirect = reg.exec(res.body);
|
480
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
481
|
+
return res;
|
482
|
+
}
|
483
|
+
|
484
|
+
mainPromise = mainPromise
|
485
|
+
.then(res => Redirect(res))
|
486
|
+
.then(res => CheckAndFixErr(res))
|
487
|
+
.then(function(res) {
|
488
|
+
let Regex_Via = /MPageLoadClientMetrics/gs;
|
489
|
+
if (!Regex_Via.test(res.body)) {
|
490
|
+
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";
|
491
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
492
|
+
}
|
493
|
+
else return res
|
494
|
+
})
|
495
|
+
.then(res => Redirect(res))
|
496
|
+
.then(res => CheckAndFixErr(res))
|
497
|
+
.then(function (res) {
|
498
|
+
var html = res.body;
|
499
|
+
var stuff = buildAPI(globalOptions, html, jar, bypass_region_err);
|
500
|
+
ctx = stuff[0];
|
501
|
+
_defaultFuncs = stuff[1];
|
502
|
+
api = stuff[2];
|
503
|
+
return res;
|
504
|
+
});
|
486
505
|
|
487
506
|
// given a pageID we log in as a page
|
488
507
|
if (globalOptions.pageID) {
|
package/package.json
CHANGED
@@ -1,24 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dongdev/fca-unofficial",
|
3
|
-
"version": "0.0.
|
4
|
-
"description": "A Facebook chat API
|
5
|
-
"
|
6
|
-
"test": "mocha",
|
7
|
-
"lint": "eslint **.js",
|
8
|
-
"prettier": "prettier utils.js src/* --write"
|
9
|
-
},
|
3
|
+
"version": "0.0.4",
|
4
|
+
"description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
|
5
|
+
"main": "index.js",
|
10
6
|
"repository": {
|
11
7
|
"type": "git",
|
12
|
-
"url": "
|
13
|
-
},
|
14
|
-
"keywords": [
|
15
|
-
"facebook",
|
16
|
-
"chat",
|
17
|
-
"api",
|
18
|
-
"fca"
|
19
|
-
],
|
20
|
-
"bugs": {
|
21
|
-
"url": "https://github.com/DongDevVN/fca-unofficial/issues"
|
8
|
+
"url": "https://github.com/DongDev-VN/fca-unofficial.git"
|
22
9
|
},
|
23
10
|
"author": "Avery, David, Maude, Benjamin, UIRI, MiraiTeam",
|
24
11
|
"license": "MIT",
|
@@ -31,51 +18,31 @@
|
|
31
18
|
"request": "^2.53.0",
|
32
19
|
"websocket-stream": "^5.5.0"
|
33
20
|
},
|
34
|
-
"engines": {
|
35
|
-
"node": ">=10.x"
|
36
|
-
},
|
37
21
|
"devDependencies": {
|
38
22
|
"eslint": "^7.5.0",
|
39
23
|
"mocha": "^7.0.1",
|
40
24
|
"prettier": "^1.11.1"
|
41
25
|
},
|
42
|
-
"
|
43
|
-
"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
"
|
49
|
-
"
|
50
|
-
|
51
|
-
|
52
|
-
"
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
],
|
61
|
-
"no-unused-vars": [
|
62
|
-
1,
|
63
|
-
{
|
64
|
-
"argsIgnorePattern": "^_",
|
65
|
-
"varsIgnorePattern": "^_"
|
66
|
-
}
|
67
|
-
],
|
68
|
-
"no-empty": [
|
69
|
-
"error",
|
70
|
-
{
|
71
|
-
"allowEmptyCatch": true
|
72
|
-
}
|
73
|
-
]
|
74
|
-
}
|
26
|
+
"scripts": {
|
27
|
+
"test": "mocha",
|
28
|
+
"lint": "eslint **/*.js",
|
29
|
+
"prettier": "prettier utils.js src/* --write"
|
30
|
+
},
|
31
|
+
"keywords": [
|
32
|
+
"facebook",
|
33
|
+
"chat",
|
34
|
+
"api",
|
35
|
+
"fca",
|
36
|
+
"facebook-chat-api"
|
37
|
+
],
|
38
|
+
"engines": {
|
39
|
+
"node": ">=10.x"
|
40
|
+
},
|
41
|
+
"homepage": "https://github.com/DongDev-VN/fca-unofficial#readme",
|
42
|
+
"bugs": {
|
43
|
+
"url": "https://github.com/DongDev-VN/fca-unofficial/issues"
|
75
44
|
},
|
76
|
-
"homepage": "https://github.com/DongDevVN/fca-unofficial#readme",
|
77
|
-
"main": "index.js",
|
78
45
|
"directories": {
|
79
46
|
"test": "test"
|
80
47
|
}
|
81
|
-
}
|
48
|
+
}
|