fca-nx 6.8.8 → 7.0.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.
Files changed (79) hide show
  1. package/README.md +24 -10
  2. package/func/checkUpdate.js +1 -1
  3. package/func/logAdapter.js +2 -0
  4. package/index.js +3 -0
  5. package/module/config.js +5 -3
  6. package/module/login.js +38 -13
  7. package/module/loginHelper.js +207 -148
  8. package/module/options.js +7 -1
  9. package/package.json +2 -2
  10. package/src/api/action/addfriend.js +9 -3
  11. package/src/api/action/changeAvatar.js +1 -0
  12. package/src/api/action/changeCover.js +3 -1
  13. package/src/api/action/enableAutoSaveAppState.js +18 -5
  14. package/src/api/action/refreshFb_dtsg.js +18 -76
  15. package/src/api/http/httpGet.js +6 -2
  16. package/src/api/http/httpPost.js +7 -2
  17. package/src/api/messaging/createNewGroup.js +1 -1
  18. package/src/api/messaging/deleteMessage.js +1 -1
  19. package/src/api/messaging/forwardMessage.js +9 -1
  20. package/src/api/messaging/getEmojiUrl.js +5 -1
  21. package/src/api/messaging/getMessage.js +4 -2
  22. package/src/api/messaging/getThemePictures.js +7 -0
  23. package/src/api/messaging/markAsRead.js +1 -0
  24. package/src/api/messaging/muteThread.js +1 -1
  25. package/src/api/messaging/pinMessage.js +10 -1
  26. package/src/api/messaging/scheduler.js +71 -4
  27. package/src/api/messaging/sendBroadcast.js +15 -0
  28. package/src/api/messaging/sendMessage.js +23 -1
  29. package/src/api/messaging/sendTypingIndicator.js +0 -15
  30. package/src/api/messaging/sessionGuard.js +45 -9
  31. package/src/api/messaging/setMessageReaction.js +2 -1
  32. package/src/api/messaging/threadColors.js +45 -12
  33. package/src/api/messaging/uploadAttachment.js +37 -3
  34. package/src/api/socket/OldMessage.js +7 -2
  35. package/src/api/socket/core/connectMqtt.js +68 -81
  36. package/src/api/socket/core/emitAuth.js +11 -2
  37. package/src/api/socket/core/getSeqID.js +52 -56
  38. package/src/api/socket/core/getTaskResponseData.js +3 -1
  39. package/src/api/socket/core/parseDelta.js +1 -1
  40. package/src/api/socket/detail/buildStream.js +4 -1
  41. package/src/api/socket/detail/constants.js +4 -1
  42. package/src/api/socket/e2ee/crypto.js +40 -2
  43. package/src/api/socket/e2ee/index.js +123 -10
  44. package/src/api/socket/e2ee/protocol.js +32 -1
  45. package/src/api/socket/e2ee/ratchet.js +44 -10
  46. package/src/api/socket/e2ee/store.js +13 -1
  47. package/src/api/socket/listenE2EE.js +25 -1
  48. package/src/api/socket/listenMqtt.js +94 -110
  49. package/src/api/socket/middleware/index.js +61 -7
  50. package/src/api/socket/sendMessage.js +19 -2
  51. package/src/api/socket/sendMessageMqtt.js +6 -0
  52. package/src/api/threads/getThreadHistory.js +68 -38
  53. package/src/api/threads/getThreadInfo.js +4 -3
  54. package/src/api/threads/getThreadList.js +34 -31
  55. package/src/api/threads/getThreadPictures.js +1 -1
  56. package/src/api/users/getUserInfo.js +5 -2
  57. package/src/api/users/getUserInfoV2.js +9 -3
  58. package/src/app/createFcaClient.js +2 -2
  59. package/src/core/sendReqMqtt.js +2 -1
  60. package/src/database/helpers.js +12 -0
  61. package/src/database/models/index.js +8 -9
  62. package/src/utils/broadcast.js +1 -1
  63. package/src/utils/clientIdentity.js +50 -3
  64. package/src/utils/cookies.js +4 -2
  65. package/src/utils/format/utils.js +10 -0
  66. package/src/utils/headers.js +26 -12
  67. package/src/utils/loginParser/autoLogin.js +12 -0
  68. package/src/utils/loginParser/parseAndCheckLogin.js +7 -0
  69. package/src/utils/loginParser/textUtils.js +6 -0
  70. package/src/utils/request/config.js +4 -1
  71. package/src/utils/request/methods.js +0 -13
  72. package/src/utils/request/proxy.js +13 -0
  73. package/src/utils/request/retry.js +0 -10
  74. package/src/utils/request/sanitize.js +1 -1
  75. package/src/utils/sendThrottle.js +14 -1
  76. package/src/utils/textEffects.js +92 -0
  77. package/src/utils/utils.js +17 -3
  78. package/src/utils/instanceLock.js +0 -35
  79. package/src/utils/ipGuard.js +0 -58
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const STALE_MS = 120000;
6
- let timer = null;
7
-
8
- function acquire(userID) {
9
- if (/^(off|0|false)$/i.test(String(process.env.FCA_NX_INSTANCE_LOCK || ""))) return { ok: true };
10
- const dir = process.env.FCA_NX_STATE_DIR || path.join(process.cwd(), ".fca-nx");
11
- const file = path.join(dir, "instance_" + String(userID || "default") + ".lock");
12
- try {
13
- fs.mkdirSync(dir, { recursive: true });
14
- try {
15
- const cur = JSON.parse(fs.readFileSync(file, "utf8"));
16
- if (cur && cur.pid !== process.pid && Date.now() - cur.at < STALE_MS) {
17
- let alive = true;
18
- try { process.kill(cur.pid, 0); } catch (e) { alive = e.code === "EPERM"; }
19
-
20
- if (alive || Date.now() - cur.at < 45000) return { ok: false, pid: cur.pid };
21
- }
22
- } catch (_) {}
23
- const beat = () => { try { fs.writeFileSync(file, JSON.stringify({ pid: process.pid, at: Date.now() })); } catch (_) {} };
24
- beat();
25
- if (timer) clearInterval(timer);
26
- timer = setInterval(beat, 30000);
27
- if (timer.unref) timer.unref();
28
- const release = () => { try { const c = JSON.parse(fs.readFileSync(file, "utf8")); if (c.pid === process.pid) fs.unlinkSync(file); } catch (_) {} };
29
- process.once("exit", release);
30
- for (const sig of ["SIGINT", "SIGTERM"]) process.once(sig, () => { release(); process.exit(0); });
31
- } catch (_) { }
32
- return { ok: true };
33
- }
34
-
35
- module.exports = { acquire };
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const logger = require("../../func/logger");
6
-
7
- const ENDPOINTS = [
8
- "https://api.ipify.org?format=json",
9
- "https://ipinfo.io/json"
10
- ];
11
-
12
- function stateFile() {
13
- const dir = process.env.FCA_NX_STATE_DIR || path.join(process.cwd(), ".fca-nx");
14
- return { dir, file: path.join(dir, "last_login_ip.json") };
15
- }
16
-
17
- async function lookupIP(client) {
18
- for (const url of ENDPOINTS) {
19
- try {
20
- const res = await client.get(url, { timeout: 5000, headers: { Accept: "application/json" } });
21
- const ip = res && res.data && (res.data.ip || res.data.query);
22
- if (typeof ip === "string" && ip) return { ip, country: res.data.country || null, region: res.data.region || null };
23
- } catch (_) { }
24
- }
25
- return null;
26
- }
27
-
28
- async function checkLoginIP(client, userID) {
29
- const mode = String(process.env.FCA_NX_IP_GUARD || "warn").toLowerCase();
30
- if (mode === "off" || mode === "0" || mode === "false") return { ok: true, changed: false, ip: null, previous: null };
31
- const now = await lookupIP(client);
32
- if (!now) {
33
- logger("ipGuard: could not determine public IP (continuing)", "warn");
34
- return { ok: true, changed: false, ip: null, previous: null };
35
- }
36
- const { dir, file } = stateFile();
37
- let all = {};
38
- try { all = JSON.parse(fs.readFileSync(file, "utf8")) || {}; } catch (_) {}
39
- const key = String(userID || "default");
40
- const prev = all[key] && all[key].ip ? all[key] : null;
41
- const changed = !!prev && prev.ip !== now.ip;
42
- if (changed) {
43
- const msg = `ipGuard: login IP changed ${prev.ip} -> ${now.ip}. Logging into the same account from different IPs/locations is a top cause of "automated behaviour", checkpoints and suspensions. Use ONE host with a fixed IP (or a static proxy via the 'proxy' option).`;
44
- if (mode === "block") {
45
- logger(msg + " Login refused (FCA_NX_IP_GUARD=block). Set FCA_NX_IP_GUARD=warn to override.", "error");
46
- return { ok: false, changed: true, ip: now.ip, previous: prev.ip };
47
- }
48
- logger(msg, "warn");
49
- }
50
- try {
51
- fs.mkdirSync(dir, { recursive: true });
52
- all[key] = { ip: now.ip, country: now.country, region: now.region, at: new Date().toISOString() };
53
- fs.writeFileSync(file, JSON.stringify(all, null, 2));
54
- } catch (_) {}
55
- return { ok: true, changed, ip: now.ip, previous: prev ? prev.ip : null };
56
- }
57
-
58
- module.exports = { checkLoginIP, lookupIP };