@dongdev/fca-unofficial 3.0.11 → 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 +3 -0
- package/module/loginHelper.js +59 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/module/loginHelper.js
CHANGED
|
@@ -284,14 +284,31 @@ async function setJarCookies(j, appstate) {
|
|
|
284
284
|
const cookieName = c.name || c.key;
|
|
285
285
|
const cookieValue = c.value;
|
|
286
286
|
if (!cookieName || cookieValue === undefined) continue;
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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(() => { }));
|
|
295
312
|
}
|
|
296
313
|
await Promise.all(tasks);
|
|
297
314
|
}
|
|
@@ -577,23 +594,47 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
577
594
|
(async () => {
|
|
578
595
|
try {
|
|
579
596
|
if (appState) {
|
|
580
|
-
|
|
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
|
|
581
609
|
let parsed = appState;
|
|
582
610
|
try {
|
|
583
611
|
parsed = JSON.parse(appState);
|
|
584
612
|
} catch { }
|
|
613
|
+
|
|
585
614
|
if (Array.isArray(parsed)) {
|
|
586
|
-
//
|
|
587
|
-
|
|
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);
|
|
615
|
+
// Already parsed as array, use it
|
|
616
|
+
appState = parsed;
|
|
592
617
|
} else {
|
|
593
|
-
|
|
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;
|
|
594
633
|
}
|
|
595
|
-
}
|
|
596
|
-
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Set cookies into jar with individual domain/path
|
|
637
|
+
if (Array.isArray(appState)) {
|
|
597
638
|
await setJarCookies(jar, appState);
|
|
598
639
|
} else {
|
|
599
640
|
throw new Error("Invalid appState format");
|
package/package.json
CHANGED