@dongdev/fca-unofficial 3.0.10 → 3.0.11
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/CHANGELOG.md +3 -0
- package/module/loginHelper.js +35 -31
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/module/loginHelper.js
CHANGED
|
@@ -281,11 +281,15 @@ function sort(obj) {
|
|
|
281
281
|
async function setJarCookies(j, appstate) {
|
|
282
282
|
const tasks = [];
|
|
283
283
|
for (const c of appstate) {
|
|
284
|
+
const cookieName = c.name || c.key;
|
|
285
|
+
const cookieValue = c.value;
|
|
286
|
+
if (!cookieName || cookieValue === undefined) continue;
|
|
284
287
|
const dom = (c.domain || ".facebook.com").replace(/^\./, "");
|
|
285
288
|
const path = c.path || "/";
|
|
286
289
|
const base1 = `https://${dom}${path}`;
|
|
287
290
|
const base2 = `https://www.${dom}${path}`;
|
|
288
|
-
const
|
|
291
|
+
const domain = c.domain || ".facebook.com";
|
|
292
|
+
const str = `${cookieName}=${cookieValue}; Domain=${domain}; Path=${path};`;
|
|
289
293
|
tasks.push(j.setCookie(str, base1));
|
|
290
294
|
tasks.push(j.setCookie(str, base2));
|
|
291
295
|
}
|
|
@@ -570,41 +574,41 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
570
574
|
return null;
|
|
571
575
|
};
|
|
572
576
|
let userIDFromAppState = extractUIDFromAppState(appState);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
577
|
+
(async () => {
|
|
578
|
+
try {
|
|
579
|
+
if (appState) {
|
|
580
|
+
if (typeof appState === "string") {
|
|
581
|
+
let parsed = appState;
|
|
582
|
+
try {
|
|
583
|
+
parsed = JSON.parse(appState);
|
|
584
|
+
} catch { }
|
|
585
|
+
if (Array.isArray(parsed)) {
|
|
586
|
+
// Use setJarCookies to properly handle individual cookie domains/paths
|
|
587
|
+
await setJarCookies(jar, parsed);
|
|
588
|
+
} else if (typeof parsed === "string") {
|
|
589
|
+
const pairs = normalizeCookieHeaderString(parsed);
|
|
590
|
+
if (!pairs.length) throw new Error("Empty appState cookie header");
|
|
591
|
+
setJarFromPairs(jar, pairs, domain);
|
|
592
|
+
} else {
|
|
593
|
+
throw new Error("Invalid appState format");
|
|
594
|
+
}
|
|
595
|
+
} else if (Array.isArray(appState)) {
|
|
596
|
+
// Use setJarCookies to properly handle individual cookie domains/paths
|
|
597
|
+
await setJarCookies(jar, appState);
|
|
587
598
|
} else {
|
|
588
599
|
throw new Error("Invalid appState format");
|
|
589
600
|
}
|
|
590
|
-
} else if (Array.isArray(appState)) {
|
|
591
|
-
const pairs = appState.map(c => [c.name || c.key, c.value].join("="));
|
|
592
|
-
setJarFromPairs(jar, pairs, domain);
|
|
593
|
-
} else {
|
|
594
|
-
throw new Error("Invalid appState format");
|
|
595
601
|
}
|
|
602
|
+
if (Cookie) {
|
|
603
|
+
let cookiePairs = [];
|
|
604
|
+
if (typeof Cookie === "string") cookiePairs = normalizeCookieHeaderString(Cookie);
|
|
605
|
+
else if (Array.isArray(Cookie)) cookiePairs = Cookie.map(String).filter(Boolean);
|
|
606
|
+
else if (Cookie && typeof Cookie === "object") cookiePairs = Object.entries(Cookie).map(([k, v]) => `${k}=${v}`);
|
|
607
|
+
if (cookiePairs.length) setJarFromPairs(jar, cookiePairs, domain);
|
|
608
|
+
}
|
|
609
|
+
} catch (e) {
|
|
610
|
+
return callback(e);
|
|
596
611
|
}
|
|
597
|
-
if (Cookie) {
|
|
598
|
-
let cookiePairs = [];
|
|
599
|
-
if (typeof Cookie === "string") cookiePairs = normalizeCookieHeaderString(Cookie);
|
|
600
|
-
else if (Array.isArray(Cookie)) cookiePairs = Cookie.map(String).filter(Boolean);
|
|
601
|
-
else if (Cookie && typeof Cookie === "object") cookiePairs = Object.entries(Cookie).map(([k, v]) => `${k}=${v}`);
|
|
602
|
-
if (cookiePairs.length) setJarFromPairs(jar, cookiePairs, domain);
|
|
603
|
-
}
|
|
604
|
-
} catch (e) {
|
|
605
|
-
return callback(e);
|
|
606
|
-
}
|
|
607
|
-
(async () => {
|
|
608
612
|
const ctx = { globalOptions, options: globalOptions, reconnectAttempts: 0 };
|
|
609
613
|
ctx.bypassAutomation = async function (resp, j) {
|
|
610
614
|
global.fca = global.fca || {};
|
package/package.json
CHANGED