@dongdev/fca-unofficial 3.0.10 → 3.0.12
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 +6 -0
- package/module/loginHelper.js +82 -37
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/module/loginHelper.js
CHANGED
|
@@ -281,13 +281,34 @@ function sort(obj) {
|
|
|
281
281
|
async function setJarCookies(j, appstate) {
|
|
282
282
|
const tasks = [];
|
|
283
283
|
for (const c of appstate) {
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
284
|
+
const cookieName = c.name || c.key;
|
|
285
|
+
const cookieValue = c.value;
|
|
286
|
+
if (!cookieName || cookieValue === undefined) continue;
|
|
287
|
+
|
|
288
|
+
const cookieDomain = c.domain || ".facebook.com";
|
|
289
|
+
const cookiePath = c.path || "/";
|
|
290
|
+
const dom = cookieDomain.replace(/^\./, "");
|
|
291
|
+
|
|
292
|
+
// Format expires if provided
|
|
293
|
+
let expiresStr = "";
|
|
294
|
+
if (c.expires) {
|
|
295
|
+
const expiresDate = typeof c.expires === "number" ? new Date(c.expires) : new Date(c.expires);
|
|
296
|
+
expiresStr = `; expires=${expiresDate.toUTCString()}`;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Build cookie string
|
|
300
|
+
const str = `${cookieName}=${cookieValue}${expiresStr}; Domain=${cookieDomain}; Path=${cookiePath};`;
|
|
301
|
+
|
|
302
|
+
// Set cookie for both http and https, with and without www
|
|
303
|
+
const base1 = `http://${dom}${cookiePath}`;
|
|
304
|
+
const base2 = `https://${dom}${cookiePath}`;
|
|
305
|
+
const base3 = `http://www.${dom}${cookiePath}`;
|
|
306
|
+
const base4 = `https://www.${dom}${cookiePath}`;
|
|
307
|
+
|
|
308
|
+
tasks.push(j.setCookie(str, base1).catch(() => { }));
|
|
309
|
+
tasks.push(j.setCookie(str, base2).catch(() => { }));
|
|
310
|
+
tasks.push(j.setCookie(str, base3).catch(() => { }));
|
|
311
|
+
tasks.push(j.setCookie(str, base4).catch(() => { }));
|
|
291
312
|
}
|
|
292
313
|
await Promise.all(tasks);
|
|
293
314
|
}
|
|
@@ -570,41 +591,65 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
570
591
|
return null;
|
|
571
592
|
};
|
|
572
593
|
let userIDFromAppState = extractUIDFromAppState(appState);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
594
|
+
(async () => {
|
|
595
|
+
try {
|
|
596
|
+
if (appState) {
|
|
597
|
+
// Check and convert cookie to appState format
|
|
598
|
+
if (Array.isArray(appState) && appState.some(c => c.name)) {
|
|
599
|
+
// Convert name to key if needed
|
|
600
|
+
appState = appState.map(c => {
|
|
601
|
+
if (c.name && !c.key) {
|
|
602
|
+
c.key = c.name;
|
|
603
|
+
delete c.name;
|
|
604
|
+
}
|
|
605
|
+
return c;
|
|
606
|
+
});
|
|
607
|
+
} else if (typeof appState === "string") {
|
|
608
|
+
// Try to parse as JSON first
|
|
609
|
+
let parsed = appState;
|
|
610
|
+
try {
|
|
611
|
+
parsed = JSON.parse(appState);
|
|
612
|
+
} catch { }
|
|
613
|
+
|
|
614
|
+
if (Array.isArray(parsed)) {
|
|
615
|
+
// Already parsed as array, use it
|
|
616
|
+
appState = parsed;
|
|
617
|
+
} else {
|
|
618
|
+
// Parse string cookie format (key=value; key2=value2)
|
|
619
|
+
const arrayAppState = [];
|
|
620
|
+
appState.split(';').forEach(c => {
|
|
621
|
+
const [key, value] = c.split('=');
|
|
622
|
+
if (key && value) {
|
|
623
|
+
arrayAppState.push({
|
|
624
|
+
key: key.trim(),
|
|
625
|
+
value: value.trim(),
|
|
626
|
+
domain: ".facebook.com",
|
|
627
|
+
path: "/",
|
|
628
|
+
expires: new Date().getTime() + 1000 * 60 * 60 * 24 * 365
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
appState = arrayAppState;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Set cookies into jar with individual domain/path
|
|
637
|
+
if (Array.isArray(appState)) {
|
|
638
|
+
await setJarCookies(jar, appState);
|
|
587
639
|
} else {
|
|
588
640
|
throw new Error("Invalid appState format");
|
|
589
641
|
}
|
|
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
642
|
}
|
|
643
|
+
if (Cookie) {
|
|
644
|
+
let cookiePairs = [];
|
|
645
|
+
if (typeof Cookie === "string") cookiePairs = normalizeCookieHeaderString(Cookie);
|
|
646
|
+
else if (Array.isArray(Cookie)) cookiePairs = Cookie.map(String).filter(Boolean);
|
|
647
|
+
else if (Cookie && typeof Cookie === "object") cookiePairs = Object.entries(Cookie).map(([k, v]) => `${k}=${v}`);
|
|
648
|
+
if (cookiePairs.length) setJarFromPairs(jar, cookiePairs, domain);
|
|
649
|
+
}
|
|
650
|
+
} catch (e) {
|
|
651
|
+
return callback(e);
|
|
596
652
|
}
|
|
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
653
|
const ctx = { globalOptions, options: globalOptions, reconnectAttempts: 0 };
|
|
609
654
|
ctx.bypassAutomation = async function (resp, j) {
|
|
610
655
|
global.fca = global.fca || {};
|
package/package.json
CHANGED