fca-nx 7.3.5 → 7.5.0
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/README.md +9 -7
- package/module/loginHelper.js +71 -125
- package/package.json +1 -1
- package/src/api/action/acceptFriendRequest.js +126 -0
- package/src/api/socket/core/connectMqtt.js +56 -16
- package/src/api/socket/core/emitAuth.js +4 -1
- package/src/api/socket/core/getSeqID.js +106 -6
- package/src/api/socket/listenMqtt.js +14 -43
- package/src/api/users/getCoverPhoto.js +86 -0
- package/src/api/users/getUserInfoV2.js +15 -93
- package/src/app/createFcaClient.js +2 -0
- package/src/utils/loginParser/autoLogin.js +30 -0
- package/src/utils/sendThrottle.js +7 -14
- package/src/utils/sessionStatus.js +112 -0
|
@@ -8,7 +8,7 @@ module.exports = function createEmitAuth({ logger }) {
|
|
|
8
8
|
// Clean up all timers
|
|
9
9
|
try {
|
|
10
10
|
if (ctx._autoCycleTimer) {
|
|
11
|
-
|
|
11
|
+
clearTimeout(ctx._autoCycleTimer);
|
|
12
12
|
ctx._autoCycleTimer = null;
|
|
13
13
|
}
|
|
14
14
|
} catch (_) { }
|
|
@@ -22,6 +22,9 @@ module.exports = function createEmitAuth({ logger }) {
|
|
|
22
22
|
try {
|
|
23
23
|
ctx._ending = true;
|
|
24
24
|
ctx._cycling = false;
|
|
25
|
+
if (reason === "verification_required" || reason === "login_blocked") {
|
|
26
|
+
ctx._sessionEnforcement = true;
|
|
27
|
+
}
|
|
25
28
|
} catch (_) { }
|
|
26
29
|
|
|
27
30
|
// Clean up MQTT client
|
|
@@ -8,6 +8,12 @@ const { getType } = require("../../../utils/format");
|
|
|
8
8
|
const { parseAndCheckLogin } = require("../../../utils/client");
|
|
9
9
|
const path = require("path");
|
|
10
10
|
const loginHelper = require("../../../../module/loginHelper");
|
|
11
|
+
const {
|
|
12
|
+
isSessionEnforcement,
|
|
13
|
+
isTransientTransportError,
|
|
14
|
+
createSessionEnforcementError,
|
|
15
|
+
isSessionEnforcementError
|
|
16
|
+
} = require("../../../utils/sessionStatus");
|
|
11
17
|
|
|
12
18
|
function getConfig() {
|
|
13
19
|
try {
|
|
@@ -62,6 +68,12 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
62
68
|
twofactor,
|
|
63
69
|
config.apiServer || null
|
|
64
70
|
);
|
|
71
|
+
if (isSessionEnforcement(result)) throw createSessionEnforcementError();
|
|
72
|
+
if (isTransientTransportError(result)) {
|
|
73
|
+
const error = new Error("The login service is temporarily unavailable.");
|
|
74
|
+
error.code = result.code || "ERR_NETWORK";
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
65
77
|
|
|
66
78
|
if (result && result.status) {
|
|
67
79
|
const normalizeCookieHeaderString = loginHelper.normalizeCookieHeaderString;
|
|
@@ -103,8 +115,8 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
103
115
|
} else if (typeof ctx.jar.setCookie === "function") {
|
|
104
116
|
await ctx.jar.setCookie(cookieStr, "https://www.facebook.com");
|
|
105
117
|
}
|
|
106
|
-
} catch
|
|
107
|
-
logger(
|
|
118
|
+
} catch {
|
|
119
|
+
logger("getSeqID: Failed to apply a session cookie to the cookie jar", "warn");
|
|
108
120
|
}
|
|
109
121
|
}
|
|
110
122
|
logger(`getSeqID: applied ${cookiePairs.length} API cookies to jar`, "info");
|
|
@@ -117,6 +129,7 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
117
129
|
|
|
118
130
|
let webResponse = null;
|
|
119
131
|
let htmlContent = "";
|
|
132
|
+
let lastTransportError = null;
|
|
120
133
|
const htmlUID = body => {
|
|
121
134
|
const s = typeof body === "string" ? body : String(body ?? "");
|
|
122
135
|
return s.match(/"USER_ID"\s*:\s*"(\d+)"/)?.[1] || s.match(/\["CurrentUserInitialData",\[\],\{.*?"USER_ID":"(\d+)".*?\},\d+\]/)?.[1];
|
|
@@ -130,6 +143,8 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
130
143
|
logger(`getSeqID: Refreshing ${urlToUse} (attempt ${attempt + 1}/3)...`, "info");
|
|
131
144
|
|
|
132
145
|
webResponse = await get(urlToUse, ctx.jar, null, ctx.globalOptions, ctx);
|
|
146
|
+
if (isSessionEnforcement(webResponse)) throw createSessionEnforcementError();
|
|
147
|
+
lastTransportError = null;
|
|
133
148
|
if (webResponse && webResponse.data) {
|
|
134
149
|
await saveWebCookies(ctx.jar)(webResponse);
|
|
135
150
|
htmlContent = typeof webResponse.data === "string" ? webResponse.data : String(webResponse.data || "");
|
|
@@ -144,6 +159,8 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
144
159
|
}
|
|
145
160
|
}
|
|
146
161
|
} catch (refreshErr) {
|
|
162
|
+
if (isSessionEnforcementError(refreshErr)) throw refreshErr;
|
|
163
|
+
if (isTransientTransportError(refreshErr)) lastTransportError = refreshErr;
|
|
147
164
|
logger(`getSeqID: Error refreshing session (attempt ${attempt + 1}/3): ${refreshErr && refreshErr.message ? refreshErr.message : String(refreshErr)}`, "warn");
|
|
148
165
|
if (attempt < 2) {
|
|
149
166
|
await new Promise(resolve => setTimeout(resolve, 1000 * (attempt + 1)));
|
|
@@ -151,6 +168,8 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
151
168
|
}
|
|
152
169
|
}
|
|
153
170
|
|
|
171
|
+
if (lastTransportError && !isValidUID(htmlUID(htmlContent))) throw lastTransportError;
|
|
172
|
+
|
|
154
173
|
if (webResponse && webResponse.data) {
|
|
155
174
|
const updatedCookies = await ctx.jar.getCookies("https://www.facebook.com");
|
|
156
175
|
logger(`getSeqID: refreshed session, now have ${updatedCookies.length} web cookies`, "info");
|
|
@@ -174,6 +193,7 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
174
193
|
logger("getSeqID: Failed to refresh web session after API login", "error");
|
|
175
194
|
}
|
|
176
195
|
} catch (refreshErr) {
|
|
196
|
+
if (isSessionEnforcementError(refreshErr) || isTransientTransportError(refreshErr)) throw refreshErr;
|
|
177
197
|
logger(`getSeqID: web session refresh failed - ${refreshErr && refreshErr.message ? refreshErr.message : String(refreshErr)}`, "warn");
|
|
178
198
|
}
|
|
179
199
|
|
|
@@ -183,6 +203,7 @@ async function tryAutoLogin(logger, config, ctx, defaultFuncs) {
|
|
|
183
203
|
|
|
184
204
|
logger(`getSeqID: auto re-login failed - ${result && result.message ? result.message : "unknown error"}`, "error");
|
|
185
205
|
} catch (loginErr) {
|
|
206
|
+
if (isSessionEnforcementError(loginErr) || isTransientTransportError(loginErr)) throw loginErr;
|
|
186
207
|
logger(`getSeqID: auto re-login error - ${loginErr && loginErr.message ? loginErr.message : String(loginErr)}`, "error");
|
|
187
208
|
}
|
|
188
209
|
|
|
@@ -195,6 +216,17 @@ module.exports = function createGetSeqID(deps) {
|
|
|
195
216
|
return function getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount = 0) {
|
|
196
217
|
const MAX_RETRIES = 3;
|
|
197
218
|
const RETRY_DELAY = 2000;
|
|
219
|
+
if (ctx._sessionEnforcement) {
|
|
220
|
+
if (ctx._ending) return;
|
|
221
|
+
return emitAuth(
|
|
222
|
+
ctx,
|
|
223
|
+
api,
|
|
224
|
+
globalCallback,
|
|
225
|
+
"verification_required",
|
|
226
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (ctx._ending) return;
|
|
198
230
|
ctx.t_mqttCalled = false;
|
|
199
231
|
|
|
200
232
|
// Ensure essential tokens are injected into GraphQL Batch Payload
|
|
@@ -225,6 +257,28 @@ module.exports = function createGetSeqID(deps) {
|
|
|
225
257
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
|
226
258
|
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
227
259
|
.then(async resData => {
|
|
260
|
+
if (isSessionEnforcement(resData)) {
|
|
261
|
+
if (ctx._ending) return;
|
|
262
|
+
return emitAuth(
|
|
263
|
+
ctx,
|
|
264
|
+
api,
|
|
265
|
+
globalCallback,
|
|
266
|
+
"verification_required",
|
|
267
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (ctx._sessionEnforcement) {
|
|
271
|
+
if (ctx._ending) return;
|
|
272
|
+
return emitAuth(
|
|
273
|
+
ctx,
|
|
274
|
+
api,
|
|
275
|
+
globalCallback,
|
|
276
|
+
"verification_required",
|
|
277
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (ctx._ending) return;
|
|
281
|
+
|
|
228
282
|
// Safe check for non-array responses (such as Error Objects from FB)
|
|
229
283
|
if (getType(resData) !== "Array") {
|
|
230
284
|
logger(`getSeqID: Response is not Array, received: ${getType(resData)}`, "warn");
|
|
@@ -237,7 +291,9 @@ module.exports = function createGetSeqID(deps) {
|
|
|
237
291
|
if (errCode === 1357032 || /Something Went Wrong/i.test(errorMsg)) {
|
|
238
292
|
logger("getSeqID: FB returned error 1357032. Using fallback seqID and continuing to MQTT.", "warn");
|
|
239
293
|
ctx.lastSeqId = ctx.lastSeqId || "0";
|
|
240
|
-
|
|
294
|
+
if (!ctx._ending && !ctx._sessionEnforcement) {
|
|
295
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
|
296
|
+
}
|
|
241
297
|
return;
|
|
242
298
|
}
|
|
243
299
|
|
|
@@ -248,7 +304,9 @@ module.exports = function createGetSeqID(deps) {
|
|
|
248
304
|
|
|
249
305
|
// Fallback if it's an unrecognized object
|
|
250
306
|
ctx.lastSeqId = ctx.lastSeqId || "0";
|
|
251
|
-
|
|
307
|
+
if (!ctx._ending && !ctx._sessionEnforcement) {
|
|
308
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
|
309
|
+
}
|
|
252
310
|
return;
|
|
253
311
|
}
|
|
254
312
|
|
|
@@ -264,9 +322,28 @@ module.exports = function createGetSeqID(deps) {
|
|
|
264
322
|
ctx.lastSeqId = ctx.lastSeqId || "0";
|
|
265
323
|
logger("getSeqID: sync_sequence_id not found, fallback lastSeqId=" + ctx.lastSeqId, "warn");
|
|
266
324
|
}
|
|
267
|
-
|
|
325
|
+
if (!ctx._ending && !ctx._sessionEnforcement) {
|
|
326
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
|
327
|
+
}
|
|
268
328
|
})
|
|
269
329
|
.catch(async err => {
|
|
330
|
+
if (
|
|
331
|
+
isSessionEnforcementError(err) ||
|
|
332
|
+
isSessionEnforcement(err) ||
|
|
333
|
+
isSessionEnforcement(err && err.originalResponse) ||
|
|
334
|
+
isSessionEnforcement(err && err.response)
|
|
335
|
+
) {
|
|
336
|
+
if (ctx._ending) return;
|
|
337
|
+
return emitAuth(
|
|
338
|
+
ctx,
|
|
339
|
+
api,
|
|
340
|
+
globalCallback,
|
|
341
|
+
"verification_required",
|
|
342
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
if (ctx._sessionEnforcement || ctx._ending) return;
|
|
346
|
+
|
|
270
347
|
const detail = (err && err.detail && err.detail.message) ? ` | detail=${err.detail.message}` : "";
|
|
271
348
|
const msg = ((err && err.error) || (err && err.message) || String(err || "")) + detail;
|
|
272
349
|
|
|
@@ -282,6 +359,7 @@ module.exports = function createGetSeqID(deps) {
|
|
|
282
359
|
const delay = RETRY_DELAY * (retryCount + 1);
|
|
283
360
|
logger(`getSeqID: network error, retry ${retryCount + 1}/${MAX_RETRIES} after ${delay}ms... (${msg})`, "warn");
|
|
284
361
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
362
|
+
if (ctx._sessionEnforcement || ctx._ending) return;
|
|
285
363
|
return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
|
|
286
364
|
}
|
|
287
365
|
logger(`getSeqID: network error persisted after ${MAX_RETRIES} retries, giving up for now: ${msg}`, "error");
|
|
@@ -298,14 +376,34 @@ module.exports = function createGetSeqID(deps) {
|
|
|
298
376
|
const delay = RETRY_DELAY * (retryCount + 1);
|
|
299
377
|
logger(`getSeqID: retry ${retryCount + 1}/${MAX_RETRIES} after ${delay}ms... (error: ${msg})`, "warn");
|
|
300
378
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
379
|
+
if (ctx._sessionEnforcement || ctx._ending) return;
|
|
301
380
|
|
|
302
381
|
if (retryCount === 0 && ctx.loggedIn) {
|
|
303
382
|
try {
|
|
304
383
|
logger("getSeqID: refreshing session before retry...", "info");
|
|
305
384
|
const { get } = require("../../../utils/request");
|
|
306
385
|
const { saveCookies } = require("../../../utils/client");
|
|
307
|
-
await get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, ctx)
|
|
386
|
+
const refreshed = await get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, ctx);
|
|
387
|
+
if (isSessionEnforcement(refreshed)) {
|
|
388
|
+
return emitAuth(
|
|
389
|
+
ctx,
|
|
390
|
+
api,
|
|
391
|
+
globalCallback,
|
|
392
|
+
"verification_required",
|
|
393
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
await saveCookies(ctx.jar)(refreshed);
|
|
308
397
|
} catch (refreshErr) {
|
|
398
|
+
if (isSessionEnforcementError(refreshErr) || isSessionEnforcement(refreshErr)) {
|
|
399
|
+
return emitAuth(
|
|
400
|
+
ctx,
|
|
401
|
+
api,
|
|
402
|
+
globalCallback,
|
|
403
|
+
"verification_required",
|
|
404
|
+
"Facebook requires manual account review; automatic login and reconnect stopped."
|
|
405
|
+
);
|
|
406
|
+
}
|
|
309
407
|
logger(`getSeqID: session refresh failed: ${refreshErr && refreshErr.message ? refreshErr.message : String(refreshErr)}`, "warn");
|
|
310
408
|
}
|
|
311
409
|
}
|
|
@@ -313,10 +411,12 @@ module.exports = function createGetSeqID(deps) {
|
|
|
313
411
|
return getSeqID(defaultFuncs, api, ctx, globalCallback, form, retryCount + 1);
|
|
314
412
|
}
|
|
315
413
|
|
|
414
|
+
if (ctx._sessionEnforcement || ctx._ending) return;
|
|
316
415
|
logger("getSeqID: all retries failed, attempting auto re-login...", "warn");
|
|
317
416
|
const config = getConfig();
|
|
318
417
|
const loginResult = await tryAutoLogin(logger, config, ctx, defaultFuncs);
|
|
319
418
|
|
|
419
|
+
if (ctx._sessionEnforcement || ctx._ending) return;
|
|
320
420
|
if (loginResult) {
|
|
321
421
|
logger("getSeqID: retrying with new session...", "info");
|
|
322
422
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
@@ -20,12 +20,6 @@ const getTaskResponseData = require("./core/getTaskResponseData");
|
|
|
20
20
|
const createEmitAuth = require("./core/emitAuth");
|
|
21
21
|
const createMiddlewareSystem = require("./middleware");
|
|
22
22
|
|
|
23
|
-
// 7.3.5: no hourly hard cycle (7.2.5 published /browser_close every hour and
|
|
24
|
-
// the session came back logged out) and no immortal socket (7.3.0 never
|
|
25
|
-
// cycled, and a custom /ping every 30s on that socket got accounts suspended).
|
|
26
|
-
// Soft-recycle the MQTT socket on a long jittered timer. Real keepalive is
|
|
27
|
-
// MQTT PINGREQ (connectMqtt keepalive). Set mqtt cycleMs to 0 to disable.
|
|
28
|
-
const CYCLE_MS_DEFAULT = 6 * 60 * 60 * 1000;
|
|
29
23
|
const RECONNECT_DELAY_MS_DEFAULT = 3000;
|
|
30
24
|
const UNSUB_ALL_TIMEOUT_MS = 5000;
|
|
31
25
|
const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
|
|
@@ -51,7 +45,6 @@ const listenMqtt = createListenMqtt({
|
|
|
51
45
|
const getSeqIDFactory = createGetSeqID({ parseAndCheckLogin, listenMqtt, logger, emitAuth });
|
|
52
46
|
|
|
53
47
|
const MQTT_DEFAULTS = {
|
|
54
|
-
cycleMs: CYCLE_MS_DEFAULT,
|
|
55
48
|
reconnectDelayMs: RECONNECT_DELAY_MS_DEFAULT,
|
|
56
49
|
autoReconnect: true,
|
|
57
50
|
reconnectAfterStop: false,
|
|
@@ -219,11 +212,8 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
219
212
|
return;
|
|
220
213
|
}
|
|
221
214
|
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
// signal. A JSON /ping every 30s on a socket that never closed
|
|
225
|
-
// is what 7.3.0 left running, and that pattern suspended accounts.
|
|
226
|
-
// Liveness is tracked from "packetreceive" above.
|
|
215
|
+
// MQTT keepalive is handled by the client. This timer only checks
|
|
216
|
+
// whether packets have arrived; it does not publish a custom ping.
|
|
227
217
|
}, conf.heartbeatInterval || HEARTBEAT_INTERVAL_MS);
|
|
228
218
|
}
|
|
229
219
|
|
|
@@ -305,9 +295,8 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
305
295
|
ctx.tasks.clear();
|
|
306
296
|
}
|
|
307
297
|
|
|
308
|
-
// Only a
|
|
309
|
-
//
|
|
310
|
-
// leave those running or the saved session goes stale (logout).
|
|
298
|
+
// Only a full stop tears down appstate autosave, user-info refresh
|
|
299
|
+
// timers, and the scheduler.
|
|
311
300
|
if (full) {
|
|
312
301
|
if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
|
|
313
302
|
ctx._userInfoIntervals.forEach(interval => {
|
|
@@ -337,9 +326,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
337
326
|
|
|
338
327
|
try {
|
|
339
328
|
if (ctx.mqttClient) {
|
|
340
|
-
//
|
|
341
|
-
// routine recycle is what 7.2.5 did every hour, and the account
|
|
342
|
-
// came back logged out. Only a real stop publishes it.
|
|
329
|
+
// Send the close event only for an explicit full stop.
|
|
343
330
|
if (full && isConnected()) {
|
|
344
331
|
try {
|
|
345
332
|
ctx.mqttClient.publish("/browser_close", "{}", { qos: 0 });
|
|
@@ -355,7 +342,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
355
342
|
}
|
|
356
343
|
|
|
357
344
|
function delayedReconnect() {
|
|
358
|
-
if (ctx._ending) return;
|
|
345
|
+
if (ctx._ending || ctx._sessionEnforcement) return;
|
|
359
346
|
const d = getReconnectDelay();
|
|
360
347
|
logger(`mqtt reconnect in ${d}ms`, "info");
|
|
361
348
|
|
|
@@ -365,31 +352,18 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
365
352
|
}
|
|
366
353
|
|
|
367
354
|
ctx._reconnectTimer = setTimeout(() => {
|
|
368
|
-
if (!ctx._ending) {
|
|
355
|
+
if (!ctx._ending && !ctx._sessionEnforcement) {
|
|
369
356
|
isReconnecting = false;
|
|
370
357
|
getSeqIDWrapper();
|
|
371
358
|
}
|
|
372
359
|
}, d);
|
|
373
360
|
}
|
|
374
361
|
|
|
375
|
-
function scheduleSoftCycle() {
|
|
376
|
-
if (ctx._autoCycleTimer) {
|
|
377
|
-
clearTimeout(ctx._autoCycleTimer);
|
|
378
|
-
ctx._autoCycleTimer = null;
|
|
379
|
-
}
|
|
380
|
-
const base = conf.cycleMs;
|
|
381
|
-
if (!base || base <= 0) return;
|
|
382
|
-
// ±20% so the reconnect is not a fixed cron-like interval.
|
|
383
|
-
const jitter = Math.floor((Math.random() - 0.5) * base * 0.4);
|
|
384
|
-
const wait = Math.max(30 * 60 * 1000, base + jitter);
|
|
385
|
-
ctx._autoCycleTimer = setTimeout(() => {
|
|
386
|
-
ctx._autoCycleTimer = null;
|
|
387
|
-
if (!ctx._ending && !ctx._cycling) forceCycle();
|
|
388
|
-
}, wait);
|
|
389
|
-
logger(`mqtt soft-cycle in ${Math.round(wait / 60000)}min`, "info");
|
|
390
|
-
}
|
|
391
|
-
|
|
392
362
|
function forceCycle() {
|
|
363
|
+
if (ctx._sessionEnforcement) {
|
|
364
|
+
logger("mqtt cycle skipped - manual account review is required", "warn");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
393
367
|
if (ctx._cycling) {
|
|
394
368
|
logger("mqtt force cycle already in progress", "warn");
|
|
395
369
|
return;
|
|
@@ -411,7 +385,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
411
385
|
ctx._cycling = false;
|
|
412
386
|
if (conf.reconnectAfterStop || conf.autoReconnect !== false) {
|
|
413
387
|
delayedReconnect();
|
|
414
|
-
scheduleSoftCycle();
|
|
415
388
|
}
|
|
416
389
|
}, false);
|
|
417
390
|
});
|
|
@@ -459,7 +432,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
459
432
|
ctx.mqttClient.once("close", () => {
|
|
460
433
|
logger("mqtt connection closed", "warn");
|
|
461
434
|
stopHeartbeat();
|
|
462
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
435
|
+
if (!ctx._ending && !ctx._sessionEnforcement && ctx.globalOptions.autoReconnect !== false) {
|
|
463
436
|
if (!isReconnecting) {
|
|
464
437
|
isReconnecting = true;
|
|
465
438
|
delayedReconnect();
|
|
@@ -469,7 +442,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
469
442
|
|
|
470
443
|
ctx.mqttClient.once("error", (err) => {
|
|
471
444
|
logger(`mqtt error: ${err.message}`, "error");
|
|
472
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
445
|
+
if (!ctx._ending && !ctx._sessionEnforcement && ctx.globalOptions.autoReconnect !== false) {
|
|
473
446
|
if (!isReconnecting) {
|
|
474
447
|
isReconnecting = true;
|
|
475
448
|
forceCycle();
|
|
@@ -491,7 +464,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
491
464
|
if (ctx._autoCycleTimer) {
|
|
492
465
|
clearTimeout(ctx._autoCycleTimer);
|
|
493
466
|
ctx._autoCycleTimer = null;
|
|
494
|
-
logger("mqtt
|
|
467
|
+
logger("mqtt legacy cycle timer cleared", "info");
|
|
495
468
|
}
|
|
496
469
|
|
|
497
470
|
if (ctx._reconnectTimer) {
|
|
@@ -549,8 +522,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
549
522
|
ctx._autoCycleTimer = null;
|
|
550
523
|
}
|
|
551
524
|
|
|
552
|
-
scheduleSoftCycle();
|
|
553
|
-
|
|
554
525
|
if (!ctx.firstListen || !ctx.lastSeqId) {
|
|
555
526
|
getSeqIDWrapper();
|
|
556
527
|
} else {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
|
|
5
|
+
// api.getCoverPhoto(profile, callback?)
|
|
6
|
+
// profile = username, profile URL, or numeric UID
|
|
7
|
+
// Resolves/calls back with { id, name, coverPhoto } where coverPhoto is a URL or null.
|
|
8
|
+
//
|
|
9
|
+
// Lookup goes through a third-party profile API (no session cookies are sent).
|
|
10
|
+
// Override the endpoint with FCA_NX_COVER_LOOKUP_URL (must end with "?profile=" style query base).
|
|
11
|
+
const DEFAULT_LOOKUP_BASE = "https://xalman-apis.vercel.app/api/fbstalk?profile=";
|
|
12
|
+
const LOOKUP_TIMEOUT_MS = 20000;
|
|
13
|
+
|
|
14
|
+
function parseProfileInput(raw) {
|
|
15
|
+
const input = String(raw === undefined || raw === null ? "" : raw).trim();
|
|
16
|
+
if (!input) return null;
|
|
17
|
+
|
|
18
|
+
const idMatch = input.match(/[?&]id=(\d{5,})/);
|
|
19
|
+
if (idMatch) return idMatch[1];
|
|
20
|
+
|
|
21
|
+
if (/^\d{5,}$/.test(input)) return input;
|
|
22
|
+
|
|
23
|
+
const urlMatch = input.match(/facebook\.com\/(?:people\/[^/]+\/)?([^/?#&]+)/i);
|
|
24
|
+
if (urlMatch) {
|
|
25
|
+
const slug = urlMatch[1];
|
|
26
|
+
if (/^\d{5,}$/.test(slug)) return slug;
|
|
27
|
+
if (!["profile.php", "people", "pages"].includes(slug.toLowerCase())) return slug;
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (/^[A-Za-z0-9.]{3,}$/.test(input)) return input;
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = function () {
|
|
37
|
+
return function getCoverPhoto(profile, callback) {
|
|
38
|
+
let resolveFunc = function () {};
|
|
39
|
+
let rejectFunc = function () {};
|
|
40
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
41
|
+
resolveFunc = resolve;
|
|
42
|
+
rejectFunc = reject;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (typeof callback !== "function") {
|
|
46
|
+
callback = function (err, data) {
|
|
47
|
+
if (err) return rejectFunc(err);
|
|
48
|
+
resolveFunc(data);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const target = parseProfileInput(profile);
|
|
53
|
+
if (!target) {
|
|
54
|
+
callback({ error: "getCoverPhoto: a username, profile URL or numeric UID is required" });
|
|
55
|
+
return returnPromise;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const base = process.env.FCA_NX_COVER_LOOKUP_URL || DEFAULT_LOOKUP_BASE;
|
|
59
|
+
|
|
60
|
+
axios
|
|
61
|
+
.get(base + encodeURIComponent(target), {
|
|
62
|
+
timeout: LOOKUP_TIMEOUT_MS,
|
|
63
|
+
validateStatus: () => true
|
|
64
|
+
})
|
|
65
|
+
.then(function (res) {
|
|
66
|
+
const data = res.data || {};
|
|
67
|
+
if (res.status !== 200 || data.status !== true || !data.data) {
|
|
68
|
+
return callback({
|
|
69
|
+
error: "getCoverPhoto: lookup failed: " + (data.message || "HTTP " + res.status)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return callback(null, {
|
|
73
|
+
id: data.data.entity_id || target,
|
|
74
|
+
name: data.data.name || null,
|
|
75
|
+
coverPhoto: data.data.cover_photo || null
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.catch(function (err) {
|
|
79
|
+
callback({ error: "getCoverPhoto: " + (err && err.message ? err.message : String(err)) });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return returnPromise;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports.parseProfileInput = parseProfileInput;
|