@dongdev/fca-unofficial 0.0.2 → 0.0.3
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 +111 -94
- package/package.json +23 -56
package/index.js
CHANGED
@@ -10,70 +10,73 @@ 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
82
|
function buildAPI(globalOptions, html, jar) {
|
@@ -453,36 +456,50 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
453
456
|
|
454
457
|
var redirect = [1, "https://m.facebook.com/"], bypass_region_err = false, ctx, _defaultFuncs, api;
|
455
458
|
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
|
-
|
459
|
+
let reg_antierr = /This browser is not supported/gs;
|
460
|
+
if (reg_antierr.test(res.body)) {
|
461
|
+
const Data = JSON.stringify(res.body);
|
462
|
+
const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
|
463
|
+
if (Dt_Check == undefined) return res
|
464
|
+
const fid = Dt_Check.split("\\\\")[0];
|
465
|
+
if (Dt_Check == undefined || Dt_Check == "") return res
|
466
|
+
const final_fid = fid.split(`\\`)[0];
|
467
|
+
if (final_fid == undefined || final_fid == '') return res;
|
468
|
+
const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
|
469
|
+
bypass_region_err = true;
|
470
|
+
log.info('login', 'Bypass vùng tài khoản thành công');
|
471
|
+
return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
|
472
|
+
}
|
473
|
+
else return res
|
474
|
+
}
|
475
|
+
function Redirect(res) {
|
476
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
477
|
+
redirect = reg.exec(res.body);
|
478
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
479
|
+
return res;
|
480
|
+
}
|
481
|
+
|
482
|
+
mainPromise = mainPromise
|
483
|
+
.then(res => Redirect(res))
|
484
|
+
.then(res => CheckAndFixErr(res))
|
485
|
+
.then(function(res) {
|
486
|
+
let Regex_Via = /MPageLoadClientMetrics/gs;
|
487
|
+
if (!Regex_Via.test(res.body)) {
|
488
|
+
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";
|
489
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
490
|
+
}
|
491
|
+
else return res
|
492
|
+
})
|
493
|
+
.then(res => Redirect(res))
|
494
|
+
.then(res => CheckAndFixErr(res))
|
495
|
+
.then(function (res) {
|
496
|
+
var html = res.body;
|
497
|
+
var stuff = buildAPI(globalOptions, html, jar, bypass_region_err);
|
498
|
+
ctx = stuff[0];
|
499
|
+
_defaultFuncs = stuff[1];
|
500
|
+
api = stuff[2];
|
501
|
+
return res;
|
502
|
+
});
|
486
503
|
|
487
504
|
// given a pageID we log in as a page
|
488
505
|
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.3",
|
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
|
+
}
|