fca-nx 6.7.0 → 6.7.2
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.d.ts +120 -0
- package/module/loginHelper.js +42 -11
- package/package.json +12 -8
- package/src/api/action/refreshFb_dtsg.js +1 -2
- package/src/api/messaging/changeGroupImage.js +1 -0
- package/src/api/messaging/uploadAttachment.js +3 -0
- package/src/api/socket/core/connectMqtt.js +15 -2
- package/src/api/socket/core/getSeqID.js +6 -1
- package/src/api/socket/e2ee/index.js +25 -5
- package/src/api/socket/listenMqtt.js +11 -2
- package/src/api/users/getUserID.js +1 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +14 -1
- package/src/utils/utils.js +24 -44
package/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
|
|
3
|
+
export type Callback<T = unknown> = (error: Error | null, value?: T) => void;
|
|
4
|
+
|
|
5
|
+
export interface LoginData {
|
|
6
|
+
appState?: unknown;
|
|
7
|
+
Cookie?: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
password?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LoginOptions {
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FcaApi {
|
|
18
|
+
[method: string]: any;
|
|
19
|
+
getAppState?: () => unknown;
|
|
20
|
+
listenMqtt?: (...args: any[]) => any;
|
|
21
|
+
sendMessage?: (...args: any[]) => any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Namespace {
|
|
25
|
+
[method: string]: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FcaClient {
|
|
29
|
+
raw: FcaApi;
|
|
30
|
+
messages: Namespace;
|
|
31
|
+
threads: Namespace;
|
|
32
|
+
users: Namespace;
|
|
33
|
+
account: Namespace;
|
|
34
|
+
realtime: Namespace;
|
|
35
|
+
http: Namespace;
|
|
36
|
+
scheduler: Namespace;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MessengerBotOptions {
|
|
40
|
+
commandPrefix?: string;
|
|
41
|
+
enableComposer?: boolean;
|
|
42
|
+
stopOnSignals?: boolean;
|
|
43
|
+
maxEventListeners?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface LaunchOptions {
|
|
47
|
+
stopOnSignals?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type Middleware = (context: MessengerContext, next: () => Promise<void>) => unknown;
|
|
51
|
+
export type ErrorHandler = (error: unknown, context: MessengerContext) => unknown;
|
|
52
|
+
|
|
53
|
+
export class MessengerContext {
|
|
54
|
+
constructor(bot: MessengerBot, event: any);
|
|
55
|
+
bot: MessengerBot;
|
|
56
|
+
event: any;
|
|
57
|
+
readonly threadID: string | undefined;
|
|
58
|
+
readonly senderID: string | undefined;
|
|
59
|
+
readonly messageID: string | undefined;
|
|
60
|
+
readonly body: string | undefined;
|
|
61
|
+
readonly message: any;
|
|
62
|
+
readonly text: string;
|
|
63
|
+
reply(payload: any, callback?: Callback): any;
|
|
64
|
+
replyAsync(payload: any): Promise<any>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class MessengerBot extends EventEmitter {
|
|
68
|
+
constructor(api: FcaApi, options?: MessengerBotOptions);
|
|
69
|
+
static connect(credentials: LoginData, options?: LoginOptions & MessengerBotOptions): Promise<MessengerBot>;
|
|
70
|
+
readonly api: FcaApi;
|
|
71
|
+
readonly client: FcaClient;
|
|
72
|
+
commandPrefix: string;
|
|
73
|
+
use(middleware: Middleware): this;
|
|
74
|
+
command(name: string, handler: (context: MessengerContext) => unknown): this;
|
|
75
|
+
hears(trigger: string | RegExp, handler: (context: MessengerContext) => unknown): this;
|
|
76
|
+
catch(handler: ErrorHandler): this;
|
|
77
|
+
startListening(): this;
|
|
78
|
+
launch(options?: LaunchOptions): Promise<this>;
|
|
79
|
+
stop(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ThreadInfoSyncOptions {
|
|
83
|
+
refreshParticipants?: boolean;
|
|
84
|
+
invalidateOnUnknownEvent?: boolean;
|
|
85
|
+
logger?: (...args: any[]) => void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function login(
|
|
89
|
+
loginData: LoginData,
|
|
90
|
+
options?: LoginOptions,
|
|
91
|
+
callback?: Callback<FcaApi>
|
|
92
|
+
): Promise<FcaApi> | void;
|
|
93
|
+
|
|
94
|
+
export function createFcaClient(api: FcaApi): FcaClient;
|
|
95
|
+
export function createMessengerBot(
|
|
96
|
+
credentials: LoginData,
|
|
97
|
+
options?: LoginOptions & MessengerBotOptions
|
|
98
|
+
): Promise<MessengerBot>;
|
|
99
|
+
export function attachThreadInfoRealtimeSync(
|
|
100
|
+
api: FcaApi,
|
|
101
|
+
options?: ThreadInfoSyncOptions
|
|
102
|
+
): () => void;
|
|
103
|
+
export function applyThreadInfoRealtimeEvent(
|
|
104
|
+
api: FcaApi,
|
|
105
|
+
event: any,
|
|
106
|
+
options?: ThreadInfoSyncOptions
|
|
107
|
+
): Promise<unknown>;
|
|
108
|
+
|
|
109
|
+
declare const exportedLogin: typeof login & {
|
|
110
|
+
default: typeof login;
|
|
111
|
+
login: typeof login;
|
|
112
|
+
createFcaClient: typeof createFcaClient;
|
|
113
|
+
MessengerBot: typeof MessengerBot;
|
|
114
|
+
createMessengerBot: typeof createMessengerBot;
|
|
115
|
+
MessengerContext: typeof MessengerContext;
|
|
116
|
+
attachThreadInfoRealtimeSync: typeof attachThreadInfoRealtimeSync;
|
|
117
|
+
applyThreadInfoRealtimeEvent: typeof applyThreadInfoRealtimeEvent;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export = exportedLogin;
|
package/module/loginHelper.js
CHANGED
|
@@ -1179,11 +1179,28 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1179
1179
|
// the bot (via emitAuth) and force a brand new cookie every
|
|
1180
1180
|
// time instead of just continuing on the still-good session.
|
|
1181
1181
|
try {
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1182
|
+
// [Fixed by xalman] retry up to 3x - a transient network
|
|
1183
|
+
// hiccup during THIS check alone used to be treated the same
|
|
1184
|
+
// as a dead session and fall through to requiring credentials.
|
|
1185
|
+
let stillCheckpointed = true;
|
|
1186
|
+
let uid = null;
|
|
1187
|
+
for (let attempt = 0; attempt < 3 && !uid; attempt++) {
|
|
1188
|
+
try {
|
|
1189
|
+
const check = await get("https://www.facebook.com/", jar, null, globalOptions).then(saveCookies(jar));
|
|
1190
|
+
const html = check && check.data ? String(check.data) : "";
|
|
1191
|
+
stillCheckpointed = html.includes("/checkpoint/block/?next") || html.includes("XCheckpointFBScrapingWarningController");
|
|
1192
|
+
const uidMatch = html.match(/"USER_ID"\s*:\s*"(\d+)"/);
|
|
1193
|
+
if (!stillCheckpointed && uidMatch && uidMatch[1] && uidMatch[1] !== "0") {
|
|
1194
|
+
uid = uidMatch[1];
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
} catch {
|
|
1198
|
+
// network hiccup on this attempt - retry below instead of
|
|
1199
|
+
// immediately assuming the session is dead
|
|
1200
|
+
}
|
|
1201
|
+
if (!uid && attempt < 2) await new Promise((r) => setTimeout(r, 1500 * (attempt + 1)));
|
|
1202
|
+
}
|
|
1203
|
+
if (uid) {
|
|
1187
1204
|
logger("performAutoLogin: existing cookie session is still valid, continuing without re-login", "info");
|
|
1188
1205
|
return true;
|
|
1189
1206
|
}
|
|
@@ -1345,13 +1362,27 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1345
1362
|
// messages even after E2EE finished connecting moments later.
|
|
1346
1363
|
api.listen = api.listenE2EE;
|
|
1347
1364
|
api.listenMqtt = api.listenE2EE;
|
|
1348
|
-
|
|
1349
|
-
|
|
1365
|
+
|
|
1366
|
+
// [Fixed by xalman] Retry E2EE auto-connect with backoff instead of
|
|
1367
|
+
// giving up forever after one failed attempt - a transient network
|
|
1368
|
+
// blip or momentary FB rate-limit on device registration used to
|
|
1369
|
+
// leave the bot stuck in group-only mode until a full restart.
|
|
1370
|
+
const connectE2EEWithRetry = async (attempt = 0) => {
|
|
1371
|
+
try {
|
|
1372
|
+
await api.connectE2EE();
|
|
1350
1373
|
logger("E2EE auto-connected and merged into api.listen()/api.listenMqtt()");
|
|
1351
|
-
})
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1374
|
+
} catch (e) {
|
|
1375
|
+
const msg = e && e.message ? e.message : String(e);
|
|
1376
|
+
if (attempt < 3) {
|
|
1377
|
+
const delayMs = 5000 * Math.pow(3, attempt); // 5s, 15s, 45s
|
|
1378
|
+
logger(`E2EE auto-connect failed (attempt ${attempt + 1}/4): ${msg} - retrying in ${Math.round(delayMs / 1000)}s`, "warn");
|
|
1379
|
+
setTimeout(() => connectE2EEWithRetry(attempt + 1), delayMs);
|
|
1380
|
+
} else {
|
|
1381
|
+
logger(`E2EE auto-connect failed after 4 attempts (non-fatal, continuing without E2EE): ${msg}`, "warn");
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
connectE2EEWithRetry();
|
|
1355
1386
|
} catch (e) {
|
|
1356
1387
|
logger(`E2EE init failed (non-fatal): ${e && e.message ? e.message : String(e)}`, "warn");
|
|
1357
1388
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fca-nx",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.2",
|
|
4
4
|
"description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,9 +17,7 @@
|
|
|
17
17
|
"module/",
|
|
18
18
|
"func/",
|
|
19
19
|
"src/",
|
|
20
|
-
"
|
|
21
|
-
"README.md",
|
|
22
|
-
"src/app/"
|
|
20
|
+
"README.md"
|
|
23
21
|
],
|
|
24
22
|
"scripts": {
|
|
25
23
|
"test": "mocha",
|
|
@@ -84,19 +82,25 @@
|
|
|
84
82
|
"mime": "^3.0.0",
|
|
85
83
|
"mqtt": "^5.10.1",
|
|
86
84
|
"protobufjs": "^8.4.0",
|
|
87
|
-
"
|
|
85
|
+
"form-data": "^4.0.4",
|
|
88
86
|
"sequelize": "^6.37.8",
|
|
89
|
-
"sqlite3": "^
|
|
87
|
+
"sqlite3": "^6.0.1",
|
|
90
88
|
"totp-generator": "^1.0.0",
|
|
91
89
|
"tough-cookie": "^4.1.4",
|
|
92
90
|
"ws": "^8.18.0"
|
|
93
91
|
},
|
|
94
92
|
"devDependencies": {
|
|
95
|
-
"eslint": "^8.
|
|
96
|
-
"mocha": "^10.2
|
|
93
|
+
"eslint": "^8.57.1",
|
|
94
|
+
"mocha": "^10.8.2"
|
|
97
95
|
},
|
|
98
96
|
"publishConfig": {
|
|
99
97
|
"access": "public",
|
|
100
98
|
"registry": "https://registry.npmjs.org/"
|
|
99
|
+
},
|
|
100
|
+
"pnpm": {
|
|
101
|
+
"onlyBuiltDependencies": [
|
|
102
|
+
"@signalapp/libsignal-client",
|
|
103
|
+
"sqlite3"
|
|
104
|
+
]
|
|
101
105
|
}
|
|
102
106
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const log = require("../../../func/logAdapter");
|
|
4
3
|
const { getFrom } = require("../../utils/constants");
|
|
5
4
|
const { get } = require("../../utils/request")
|
|
6
5
|
const { getType } = require("../../utils/format");
|
|
@@ -12,7 +11,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
12
11
|
}
|
|
13
12
|
if (!obj) obj = {};
|
|
14
13
|
if (getType(obj) !== "Object") {
|
|
15
|
-
throw new
|
|
14
|
+
throw new TypeError("The first parameter must be an object or a callback function");
|
|
16
15
|
}
|
|
17
16
|
let resolveFunc, rejectFunc;
|
|
18
17
|
const returnPromise = new Promise((resolve, reject) => {
|
|
@@ -61,6 +61,9 @@ function respFinalUrl(res) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function detectCheckpoint(res) {
|
|
64
|
+
// [Fixed by xalman] res.body -> res.data (axios response shape), same
|
|
65
|
+
// root cause as the parseAndCheckLogin fix in src/utils/utils.js - this
|
|
66
|
+
// was silently always reading undefined and never detecting checkpoints.
|
|
64
67
|
const url = String(respFinalUrl(res) || "");
|
|
65
68
|
const body = typeof res?.data === "string" ? res.data : "";
|
|
66
69
|
const hit =
|
|
@@ -9,6 +9,7 @@ const { getSessionIdentity } = require("../../../utils/clientIdentity");
|
|
|
9
9
|
const DEFAULT_RECONNECT_DELAY_MS = 2000;
|
|
10
10
|
const MAX_RECONNECT_DELAY_MS = 60000;
|
|
11
11
|
const MAX_RECONNECT_ATTEMPTS = 10; // cap consecutive network-failure reconnects; does not apply to confirmed auth failures (those never reconnect)
|
|
12
|
+
const MAX_RECONNECT_COOLDOWN_MS = 10 * 60 * 1000; // after exhausting fast retries, wait this long before trying again (never give up permanently)
|
|
12
13
|
const T_MS_WAIT_TIMEOUT_MS = 5000;
|
|
13
14
|
|
|
14
15
|
// Exponential backoff with jitter, based on how many *consecutive* reconnect
|
|
@@ -44,8 +45,20 @@ module.exports = function createListenMqtt(deps) {
|
|
|
44
45
|
}
|
|
45
46
|
ctx._reconnectAttempts = (ctx._reconnectAttempts || 0) + 1;
|
|
46
47
|
if (ctx._reconnectAttempts > MAX_RECONNECT_ATTEMPTS) {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// [Fixed by xalman] Don't give up forever - a run of consecutive failures is usually a
|
|
49
|
+
// temporary outage (hosting network blip, FB-side hiccup), not a
|
|
50
|
+
// dead account. Back off to a long, FB-friendly cooldown and reset
|
|
51
|
+
// the counter so normal exponential backoff resumes after that.
|
|
52
|
+
const cooldownMs = MAX_RECONNECT_COOLDOWN_MS;
|
|
53
|
+
logger(`mqtt reconnect attempts exceeded (${MAX_RECONNECT_ATTEMPTS}); backing off ${Math.round(cooldownMs / 60000)}min before trying again (not giving up)`, "error");
|
|
54
|
+
globalCallback({ type: "stop_listen", error: "Max reconnect attempts exceeded - will retry after cooldown" }, null);
|
|
55
|
+
ctx._reconnectAttempts = 0;
|
|
56
|
+
ctx._reconnectTimer = setTimeout(() => {
|
|
57
|
+
ctx._reconnectTimer = null;
|
|
58
|
+
if (!ctx._ending) {
|
|
59
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
|
60
|
+
}
|
|
61
|
+
}, cooldownMs);
|
|
49
62
|
return;
|
|
50
63
|
}
|
|
51
64
|
const ms = typeof delayMs === "number" ? delayMs : computeBackoff(ctx, base);
|
|
@@ -285,7 +285,12 @@ module.exports = function createGetSeqID(deps) {
|
|
|
285
285
|
return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
|
|
286
286
|
}
|
|
287
287
|
logger(`getSeqID: network error persisted after ${MAX_RETRIES} retries, giving up for now: ${msg}`, "error");
|
|
288
|
-
|
|
288
|
+
// [Fixed by xalman] throw instead of silently returning undefined -
|
|
289
|
+
// a bare return here made the caller think this call SUCCEEDED.
|
|
290
|
+
const giveUpErr = new Error(`getSeqID network error persisted after ${MAX_RETRIES} retries: ${msg}`);
|
|
291
|
+
giveUpErr.error = msg;
|
|
292
|
+
giveUpErr.isNetworkError = true;
|
|
293
|
+
throw giveUpErr;
|
|
289
294
|
}
|
|
290
295
|
|
|
291
296
|
if (isAuthError) {
|
|
@@ -18,9 +18,15 @@
|
|
|
18
18
|
|
|
19
19
|
const path = require("path");
|
|
20
20
|
const logger = require("../../../utils/logger");
|
|
21
|
+
const requestHttp = require("../../../utils/request");
|
|
21
22
|
|
|
22
23
|
function loadFBClient() {
|
|
23
24
|
try {
|
|
25
|
+
// [Fixed by xalman] see comment above loadFBClient - Node < 22 has no
|
|
26
|
+
// global WebSocket, but fb-e2ee.cjs unconditionally does `new WebSocket(...)`.
|
|
27
|
+
if (typeof global.WebSocket === "undefined") {
|
|
28
|
+
global.WebSocket = require("ws");
|
|
29
|
+
}
|
|
24
30
|
const vendorPath = path.join(__dirname, "vendor", "fb-e2ee.cjs");
|
|
25
31
|
return require(vendorPath).FBClient;
|
|
26
32
|
} catch (err) {
|
|
@@ -103,17 +109,31 @@ class E2EEBridge {
|
|
|
103
109
|
fb_dtsg: _ctx.fb_dtsg,
|
|
104
110
|
getCurrentUserID: () => _fcanxApi.getCurrentUserID(),
|
|
105
111
|
getAppState: () => _fcanxApi.getAppState(),
|
|
112
|
+
// [Fixed by xalman] httpPost always returns a string now - axios
|
|
113
|
+
// auto-parses JSON responses into objects, but the vendored engine
|
|
114
|
+
// (fetchCAT/icdc_fetch/icdc_register) expects raw text and calls
|
|
115
|
+
// .replace()/JSON.parse() on it itself. This was crashing E2EE
|
|
116
|
+
// auto-connect with "resText.replace is not a function".
|
|
106
117
|
httpPost: async function (url, form) {
|
|
107
118
|
var merged = Object.assign({}, form);
|
|
108
119
|
if (!merged.fb_dtsg && _ctx.fb_dtsg) merged.fb_dtsg = _ctx.fb_dtsg;
|
|
109
120
|
if (!merged.__user) merged.__user = _ctx.userID;
|
|
110
121
|
const res = _defaultFuncs
|
|
111
122
|
? await _defaultFuncs.post(url, _ctx.jar, merged)
|
|
112
|
-
: await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
: await requestHttp.post(url, _ctx.jar, merged, {}, _ctx);
|
|
124
|
+
const body = res && (res.data !== undefined ? res.data : res.body);
|
|
125
|
+
if (body == null) return body;
|
|
126
|
+
if (typeof body === "string") return body;
|
|
127
|
+
if (Buffer.isBuffer(body)) return body.toString("utf8");
|
|
128
|
+
// axios auto-parses JSON bodies into an object/array, but the
|
|
129
|
+
// vendored engine always expects a raw string (it strips
|
|
130
|
+
// Facebook's "for (;;);" prefix and JSON.parses it itself).
|
|
131
|
+
// Re-serialize so callers doing resText.replace(...) still work.
|
|
132
|
+
try {
|
|
133
|
+
return JSON.stringify(body);
|
|
134
|
+
} catch {
|
|
135
|
+
return String(body);
|
|
136
|
+
}
|
|
117
137
|
},
|
|
118
138
|
// listenMqtt — fb-e2ee.cjs calls this to route non-E2EE MQTT events.
|
|
119
139
|
// FCA-NX has its own separate MQTT listener so we provide a no-op stub
|
|
@@ -24,6 +24,7 @@ const CYCLE_MS_DEFAULT = 60 * 60 * 1000;
|
|
|
24
24
|
const RECONNECT_DELAY_MS_DEFAULT = 3000;
|
|
25
25
|
const UNSUB_ALL_TIMEOUT_MS = 5000;
|
|
26
26
|
const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
|
|
27
|
+
const MAX_MQTT_RECONNECT_COOLDOWN_MS = 10 * 60 * 1000; // long cooldown after exhausting fast retries - never give up permanently
|
|
27
28
|
const MAX_MQTT_RECONNECT_ATTEMPTS = 10;
|
|
28
29
|
const HEARTBEAT_INTERVAL_MS = 30000;
|
|
29
30
|
const HEARTBEAT_TIMEOUT_MS = 10000;
|
|
@@ -154,8 +155,16 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
154
155
|
const maxAttempts = conf.maxReconnectAttempts || MAX_MQTT_RECONNECT_ATTEMPTS;
|
|
155
156
|
|
|
156
157
|
if (reconnectAttempts > maxAttempts) {
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
const cooldownMs = MAX_MQTT_RECONNECT_COOLDOWN_MS;
|
|
159
|
+
logger(`mqtt getSeqID: max reconnect attempts exceeded, backing off ${Math.round(cooldownMs / 60000)}min before trying again (not giving up)`, "error");
|
|
160
|
+
globalCallback({ type: "stop_listen", error: "Max reconnect attempts exceeded - will retry after cooldown" }, null);
|
|
161
|
+
reconnectAttempts = 0;
|
|
162
|
+
ctx._reconnectTimer = setTimeout(() => {
|
|
163
|
+
if (!ctx._ending) {
|
|
164
|
+
isReconnecting = false;
|
|
165
|
+
getSeqIDWrapper();
|
|
166
|
+
}
|
|
167
|
+
}, cooldownMs);
|
|
159
168
|
return;
|
|
160
169
|
}
|
|
161
170
|
|
|
@@ -103,7 +103,20 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (status === 404)
|
|
106
|
+
if (status === 404) {
|
|
107
|
+
const url = buildUrl(res?.config);
|
|
108
|
+
const method = String(res?.config?.method || "GET").toUpperCase();
|
|
109
|
+
const err = new Error(
|
|
110
|
+
`parseAndCheckLogin got status code: 404. [${method}] ${url || "(no url)"} was not found - the endpoint may have changed or been removed by Facebook.`
|
|
111
|
+
);
|
|
112
|
+
err.statusCode = 404;
|
|
113
|
+
err.res = res?.data;
|
|
114
|
+
logger(
|
|
115
|
+
`parseAndCheckLogin: [${method}] ${url || "(no url)"} -> 404 Not Found`,
|
|
116
|
+
"error"
|
|
117
|
+
);
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
107
120
|
if (status !== 200) {
|
|
108
121
|
const err = new Error(
|
|
109
122
|
"parseAndCheckLogin got status code: " +
|
package/src/utils/utils.js
CHANGED
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var url = require("url");
|
|
4
4
|
var stream = require("stream");
|
|
5
|
-
var bluebird = require("bluebird");
|
|
6
5
|
var querystring = require("querystring");
|
|
7
|
-
var
|
|
6
|
+
var CookieJar = require("tough-cookie").CookieJar;
|
|
7
|
+
var requestHttp = require("./request");
|
|
8
8
|
|
|
9
9
|
function setProxy(proxyUrl) {
|
|
10
|
-
|
|
11
|
-
request = bluebird.promisify(require("request").defaults({ jar: true }));
|
|
12
|
-
} else {
|
|
13
|
-
request = bluebird.promisify(require("request").defaults({ jar: true, proxy: proxyUrl }));
|
|
14
|
-
}
|
|
10
|
+
requestHttp.setProxy(proxyUrl);
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
function sanitizeHeaderValue(value) {
|
|
@@ -103,53 +99,31 @@ function get(reqUrl, jar, qs, options, ctx) {
|
|
|
103
99
|
if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
|
|
104
100
|
}
|
|
105
101
|
}
|
|
106
|
-
|
|
107
|
-
headers: getHeaders(reqUrl, options, ctx),
|
|
108
|
-
timeout: 60000,
|
|
109
|
-
qs: qs,
|
|
110
|
-
url: reqUrl,
|
|
111
|
-
method: "GET",
|
|
112
|
-
jar: jar,
|
|
113
|
-
gzip: true
|
|
114
|
-
};
|
|
115
|
-
return request(op);
|
|
102
|
+
return requestHttp.get(reqUrl, jar, qs, options, ctx);
|
|
116
103
|
}
|
|
117
104
|
|
|
118
105
|
function post(reqUrl, jar, form, options, ctx, customHeader) {
|
|
119
|
-
|
|
120
|
-
headers: getHeaders(reqUrl, options, ctx, customHeader),
|
|
121
|
-
timeout: 60000,
|
|
122
|
-
url: reqUrl,
|
|
123
|
-
method: "POST",
|
|
124
|
-
form: form,
|
|
125
|
-
jar: jar,
|
|
126
|
-
gzip: true
|
|
127
|
-
};
|
|
128
|
-
return request(op);
|
|
106
|
+
return requestHttp.post(reqUrl, jar, form, options, ctx, customHeader);
|
|
129
107
|
}
|
|
130
108
|
|
|
131
109
|
function postFormData(reqUrl, jar, form, qs, options, ctx) {
|
|
132
|
-
|
|
133
|
-
headers["Content-Type"] = "multipart/form-data";
|
|
134
|
-
var op = {
|
|
135
|
-
headers: headers,
|
|
136
|
-
timeout: 60000,
|
|
137
|
-
url: reqUrl,
|
|
138
|
-
method: "POST",
|
|
139
|
-
formData: form,
|
|
140
|
-
qs: qs,
|
|
141
|
-
jar: jar,
|
|
142
|
-
gzip: true
|
|
143
|
-
};
|
|
144
|
-
return request(op);
|
|
110
|
+
return requestHttp.postFormData(reqUrl, jar, form, qs, options, ctx);
|
|
145
111
|
}
|
|
146
112
|
|
|
147
113
|
function getJar() {
|
|
148
|
-
return
|
|
114
|
+
return new CookieJar();
|
|
149
115
|
}
|
|
150
116
|
|
|
151
117
|
function getAppState(jar) {
|
|
152
|
-
|
|
118
|
+
if (!jar || typeof jar.getCookies !== "function") return [];
|
|
119
|
+
var cookies;
|
|
120
|
+
if (typeof jar.getCookiesSync === "function") {
|
|
121
|
+
cookies = jar.getCookiesSync("https://www.facebook.com");
|
|
122
|
+
} else {
|
|
123
|
+
cookies = jar.getCookies("https://www.facebook.com");
|
|
124
|
+
}
|
|
125
|
+
if (!Array.isArray(cookies)) return [];
|
|
126
|
+
return cookies.map(c => ({
|
|
153
127
|
key: c.key,
|
|
154
128
|
value: c.value,
|
|
155
129
|
domain: c.domain,
|
|
@@ -166,7 +140,13 @@ function saveCookies(jar) {
|
|
|
166
140
|
if (cookies) {
|
|
167
141
|
if (!Array.isArray(cookies)) cookies = [cookies];
|
|
168
142
|
cookies.forEach(c => {
|
|
169
|
-
try {
|
|
143
|
+
try {
|
|
144
|
+
if (typeof jar.setCookieSync === "function") {
|
|
145
|
+
jar.setCookieSync(c, "https://www.facebook.com");
|
|
146
|
+
} else if (typeof jar.setCookie === "function") {
|
|
147
|
+
jar.setCookie(c, "https://www.facebook.com");
|
|
148
|
+
}
|
|
149
|
+
} catch (_) { }
|
|
170
150
|
});
|
|
171
151
|
}
|
|
172
152
|
return res;
|
|
@@ -245,7 +225,7 @@ function decodeClientPayload(payload) {
|
|
|
245
225
|
|
|
246
226
|
function parseAndCheckLogin(ctx, defaultFuncs) {
|
|
247
227
|
return function (res) {
|
|
248
|
-
//
|
|
228
|
+
// [Fixed by xalman] this used to read res.statusCode/res.body, which are the old
|
|
249
229
|
// `request`/`request-promise` library's property names. The actual
|
|
250
230
|
// HTTP client here (src/utils/request) is axios-based, whose
|
|
251
231
|
// responses use res.status/res.data instead - res.body was always
|