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.
- package/README.md +24 -10
- package/func/checkUpdate.js +1 -1
- package/func/logAdapter.js +2 -0
- package/index.js +3 -0
- package/module/config.js +5 -3
- package/module/login.js +38 -13
- package/module/loginHelper.js +207 -148
- package/module/options.js +7 -1
- package/package.json +2 -2
- package/src/api/action/addfriend.js +9 -3
- package/src/api/action/changeAvatar.js +1 -0
- package/src/api/action/changeCover.js +3 -1
- package/src/api/action/enableAutoSaveAppState.js +18 -5
- package/src/api/action/refreshFb_dtsg.js +18 -76
- package/src/api/http/httpGet.js +6 -2
- package/src/api/http/httpPost.js +7 -2
- package/src/api/messaging/createNewGroup.js +1 -1
- package/src/api/messaging/deleteMessage.js +1 -1
- package/src/api/messaging/forwardMessage.js +9 -1
- package/src/api/messaging/getEmojiUrl.js +5 -1
- package/src/api/messaging/getMessage.js +4 -2
- package/src/api/messaging/getThemePictures.js +7 -0
- package/src/api/messaging/markAsRead.js +1 -0
- package/src/api/messaging/muteThread.js +1 -1
- package/src/api/messaging/pinMessage.js +10 -1
- package/src/api/messaging/scheduler.js +71 -4
- package/src/api/messaging/sendBroadcast.js +15 -0
- package/src/api/messaging/sendMessage.js +23 -1
- package/src/api/messaging/sendTypingIndicator.js +0 -15
- package/src/api/messaging/sessionGuard.js +45 -9
- package/src/api/messaging/setMessageReaction.js +2 -1
- package/src/api/messaging/threadColors.js +45 -12
- package/src/api/messaging/uploadAttachment.js +37 -3
- package/src/api/socket/OldMessage.js +7 -2
- package/src/api/socket/core/connectMqtt.js +68 -81
- package/src/api/socket/core/emitAuth.js +11 -2
- package/src/api/socket/core/getSeqID.js +52 -56
- package/src/api/socket/core/getTaskResponseData.js +3 -1
- package/src/api/socket/core/parseDelta.js +1 -1
- package/src/api/socket/detail/buildStream.js +4 -1
- package/src/api/socket/detail/constants.js +4 -1
- package/src/api/socket/e2ee/crypto.js +40 -2
- package/src/api/socket/e2ee/index.js +123 -10
- package/src/api/socket/e2ee/protocol.js +32 -1
- package/src/api/socket/e2ee/ratchet.js +44 -10
- package/src/api/socket/e2ee/store.js +13 -1
- package/src/api/socket/listenE2EE.js +25 -1
- package/src/api/socket/listenMqtt.js +94 -110
- package/src/api/socket/middleware/index.js +61 -7
- package/src/api/socket/sendMessage.js +19 -2
- package/src/api/socket/sendMessageMqtt.js +6 -0
- package/src/api/threads/getThreadHistory.js +68 -38
- package/src/api/threads/getThreadInfo.js +4 -3
- package/src/api/threads/getThreadList.js +34 -31
- package/src/api/threads/getThreadPictures.js +1 -1
- package/src/api/users/getUserInfo.js +5 -2
- package/src/api/users/getUserInfoV2.js +9 -3
- package/src/app/createFcaClient.js +2 -2
- package/src/core/sendReqMqtt.js +2 -1
- package/src/database/helpers.js +12 -0
- package/src/database/models/index.js +8 -9
- package/src/utils/broadcast.js +1 -1
- package/src/utils/clientIdentity.js +50 -3
- package/src/utils/cookies.js +4 -2
- package/src/utils/format/utils.js +10 -0
- package/src/utils/headers.js +26 -12
- package/src/utils/loginParser/autoLogin.js +12 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +7 -0
- package/src/utils/loginParser/textUtils.js +6 -0
- package/src/utils/request/config.js +4 -1
- package/src/utils/request/methods.js +0 -13
- package/src/utils/request/proxy.js +13 -0
- package/src/utils/request/retry.js +0 -10
- package/src/utils/request/sanitize.js +1 -1
- package/src/utils/sendThrottle.js +14 -1
- package/src/utils/textEffects.js +92 -0
- package/src/utils/utils.js +17 -3
- package/src/utils/instanceLock.js +0 -35
- package/src/utils/ipGuard.js +0 -58
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
var logger = require("../../utils/logger");
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* sendBroadcast — Send a message to multiple threads in parallel
|
|
7
|
+
* with rate limiting and per-thread delivery tracking.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* api.sendBroadcast(msg, threadIDs, [options], [callback])
|
|
11
|
+
*
|
|
12
|
+
* Options:
|
|
13
|
+
* delay {number} ms between each send (default: 1000)
|
|
14
|
+
* parallel {number} max concurrent sends (default: 3)
|
|
15
|
+
* onEach {function(err, result, threadID)} called after each individual send
|
|
16
|
+
*
|
|
17
|
+
* Returns:
|
|
18
|
+
* Promise<{ sent: string[], failed: { id, error }[], total: number }>
|
|
19
|
+
*/
|
|
5
20
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
21
|
return function sendBroadcast(msg, threadIDs, options, callback) {
|
|
7
22
|
if (typeof options === "function") {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Created by Donix-VN (DongDev)
|
|
3
|
+
* Modified by MueidMursalinRifat & Xalman
|
|
4
|
+
* Send a message using MQTT.
|
|
5
|
+
* @param {string|object} msg - The message object or text to send.
|
|
6
|
+
* @param {string} threadID - The ID of the thread to send the message to.
|
|
7
|
+
* @param {function} [callback] - Optional. The callback function.
|
|
8
|
+
* @param {string} [replyToMessage] - Optional. Message ID to reply to.
|
|
9
|
+
* @returns {Promise<object>} A promise that resolves with the sent message metadata.
|
|
10
|
+
*/
|
|
2
11
|
|
|
3
12
|
"use strict";
|
|
4
13
|
const log = require("../../../func/logAdapter");
|
|
@@ -162,6 +171,19 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
162
171
|
metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
|
|
163
172
|
};
|
|
164
173
|
|
|
174
|
+
// --- TEXT EFFECTS SUPPORT FOR MQTT ---
|
|
175
|
+
if (m.text_effect_ids) {
|
|
176
|
+
let effectArray = [];
|
|
177
|
+
if (Array.isArray(m.text_effect_ids)) {
|
|
178
|
+
effectArray = m.text_effect_ids;
|
|
179
|
+
} else if (typeof m.text_effect_ids === "string" || typeof m.text_effect_ids === "number") {
|
|
180
|
+
effectArray = [m.text_effect_ids];
|
|
181
|
+
}
|
|
182
|
+
if (effectArray.length > 0) {
|
|
183
|
+
payload0.text_effect_ids = effectArray.map(id => String(id));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
165
187
|
const mentionData = buildMentionData(m, baseBody);
|
|
166
188
|
if (mentionData) payload0.mention_data = mentionData;
|
|
167
189
|
|
|
@@ -8,7 +8,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
8
8
|
resolveFunc = resolve;
|
|
9
9
|
rejectFunc = reject;
|
|
10
10
|
});
|
|
11
|
-
returnPromise.catch(function () { });
|
|
12
11
|
if (getType(options) == "Function" || getType(options) == "AsyncFunction") {
|
|
13
12
|
callback = options;
|
|
14
13
|
options = {};
|
|
@@ -23,20 +22,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
23
22
|
if (!threadID) {
|
|
24
23
|
return callback(new Error("threadID is required"));
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
if (typeof threadID === "string" || typeof threadID === "number") {
|
|
28
|
-
var _tid = String(threadID);
|
|
29
|
-
if (ctx.threadTypes && ctx.threadTypes[_tid] === "dm" && ctx.e2ee &&
|
|
30
|
-
typeof ctx.e2ee.isConnected === "function" && ctx.e2ee.isConnected()) {
|
|
31
|
-
ctx.e2ee.sendTyping(_tid, !!isTyping).catch(function () { });
|
|
32
|
-
if (isTyping && options.autoStop !== false) {
|
|
33
|
-
var _t = setTimeout(function () { ctx.e2ee.sendTyping(_tid, false).catch(function () { }); }, options.duration || 10000);
|
|
34
|
-
if (_t.unref) _t.unref();
|
|
35
|
-
}
|
|
36
|
-
callback(null, true);
|
|
37
|
-
return returnPromise;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
25
|
if (!ctx.mqttClient) {
|
|
41
26
|
const err = new Error("Not connected to MQTT");
|
|
42
27
|
callback(err);
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* SessionGuard — Protects the appstate (session) from corruption and silent logouts.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* • Auto-saves appstate to disk periodically (default every 5 min)
|
|
8
|
+
* • Saves on every successful message send (debounced, 30s cooldown)
|
|
9
|
+
* • Backs up the previous appstate before overwriting (.bak file)
|
|
10
|
+
* • Detects logout/checkpoint events from listen stream and alerts
|
|
11
|
+
* • Provides api.saveSession([path]) for manual save at any time
|
|
12
|
+
* • Never overwrites with a shorter/smaller appstate (corruption guard)
|
|
13
|
+
*/
|
|
14
|
+
|
|
3
15
|
var fs = require("fs");
|
|
4
16
|
var path = require("path");
|
|
5
17
|
var logger = require("../../utils/logger");
|
|
6
18
|
|
|
7
|
-
var SAVE_INTERVAL_MS = 5 * 60 * 1000;
|
|
8
|
-
var DEBOUNCE_MS = 30 * 1000;
|
|
9
|
-
var MIN_COOKIES = 5;
|
|
10
|
-
var REQUIRED_COOKIE_KEYS = ["c_user", "xs"];
|
|
19
|
+
var SAVE_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
20
|
+
var DEBOUNCE_MS = 30 * 1000; // 30 seconds cooldown between auto-saves
|
|
21
|
+
var MIN_COOKIES = 5; // minimum cookie count we consider "valid"
|
|
22
|
+
var REQUIRED_COOKIE_KEYS = ["c_user", "xs"]; // a session isn't usable without these
|
|
11
23
|
|
|
24
|
+
// Validate that an appstate array actually looks like a usable, well-formed
|
|
25
|
+
// Facebook session before it's allowed to overwrite anything on disk.
|
|
26
|
+
// Guards against persisting a partial/corrupt state (e.g. captured mid-logout)
|
|
27
|
+
// that would replace a good appstate with a broken one.
|
|
12
28
|
function isValidAppState(state) {
|
|
13
29
|
if (!state || !Array.isArray(state) || state.length < MIN_COOKIES) return false;
|
|
14
30
|
var keys = {};
|
|
@@ -27,6 +43,11 @@ function isValidAppState(state) {
|
|
|
27
43
|
|
|
28
44
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
29
45
|
|
|
46
|
+
// sessionGuard() attaches by monkey-patching api.sendMessage. If it's
|
|
47
|
+
// invoked more than once for the same api instance (e.g. accidentally
|
|
48
|
+
// called twice), that patch would stack, causing double-saves and,
|
|
49
|
+
// eventually, wrapping api.sendMessage in itself repeatedly. Guard
|
|
50
|
+
// against that here instead of relying on callers not to do it.
|
|
30
51
|
if (ctx._sessionGuardAttached) {
|
|
31
52
|
logger.warn("SessionGuard", "Already active for this session — ignoring duplicate init.");
|
|
32
53
|
return function alreadyActive() {
|
|
@@ -43,6 +64,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
43
64
|
try { return api.getAppState(); } catch (_) { return null; }
|
|
44
65
|
}
|
|
45
66
|
|
|
67
|
+
// Serializes all writes to a given path so a periodic save and a
|
|
68
|
+
// debounced on-send save can never interleave their writes to the same
|
|
69
|
+
// file (the previous version had no such lock, so two concurrent
|
|
70
|
+
// fs.writeFileSync calls to the same path could race).
|
|
46
71
|
var writeLocks = Object.create(null);
|
|
47
72
|
|
|
48
73
|
function withWriteLock(filePath, fn) {
|
|
@@ -53,7 +78,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
53
78
|
}
|
|
54
79
|
|
|
55
80
|
function atomicWriteFileSync(filePath, data) {
|
|
56
|
-
|
|
81
|
+
// Write to a temp file in the same directory, then rename. rename()
|
|
82
|
+
// is atomic on the same filesystem, so a crash/kill mid-write can
|
|
83
|
+
// never leave a partially-written, corrupt appstate.json behind -
|
|
84
|
+
// readers either see the old complete file or the new complete file.
|
|
57
85
|
var dir = path.dirname(filePath);
|
|
58
86
|
var tmpPath = path.join(dir, "." + path.basename(filePath) + "." + process.pid + "." + Date.now() + ".tmp");
|
|
59
87
|
fs.writeFileSync(tmpPath, data, "utf8");
|
|
@@ -67,6 +95,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
67
95
|
return false;
|
|
68
96
|
}
|
|
69
97
|
|
|
98
|
+
// Corruption guard: never write a smaller appstate than what's already on disk
|
|
70
99
|
if (fs.existsSync(filePath)) {
|
|
71
100
|
try {
|
|
72
101
|
var existing = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
@@ -74,7 +103,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
74
103
|
logger.warn("SessionGuard", "Skipped save — new state has " + state.length + " cookies vs " + existing.length + " on disk (possible truncation).");
|
|
75
104
|
return false;
|
|
76
105
|
}
|
|
77
|
-
|
|
106
|
+
// Backup the current valid state before overwriting (also atomic).
|
|
78
107
|
atomicWriteFileSync(filePath + ".bak", JSON.stringify(existing, null, 2));
|
|
79
108
|
} catch (_) {}
|
|
80
109
|
}
|
|
@@ -85,7 +114,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
function saveToDisk(filePath) {
|
|
88
|
-
|
|
117
|
+
// Run the actual save inside the per-path lock so concurrent callers
|
|
118
|
+
// (periodic timer vs. post-send debounce) are serialized.
|
|
89
119
|
var result;
|
|
90
120
|
return withWriteLock(filePath, function () {
|
|
91
121
|
try {
|
|
@@ -108,19 +138,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
108
138
|
var lastSave = 0;
|
|
109
139
|
var intervalRef = null;
|
|
110
140
|
|
|
141
|
+
// Periodic save
|
|
111
142
|
if (interval > 0) {
|
|
112
143
|
intervalRef = setInterval(function () {
|
|
113
144
|
logger.info("SessionGuard", "Periodic save...");
|
|
114
145
|
saveToDisk(appStatePath);
|
|
115
146
|
lastSave = Date.now();
|
|
116
147
|
}, interval);
|
|
117
|
-
if (intervalRef.unref) intervalRef.unref();
|
|
148
|
+
if (intervalRef.unref) intervalRef.unref(); // don't block process exit
|
|
118
149
|
}
|
|
119
150
|
|
|
151
|
+
// Debounced on-send save
|
|
152
|
+
// Patch sendMessage to auto-save appstate after a successful send
|
|
120
153
|
var originalSendMessage = api.sendMessage;
|
|
121
154
|
api.sendMessage = function () {
|
|
122
155
|
var result = originalSendMessage.apply(this, arguments);
|
|
123
|
-
|
|
156
|
+
// After send, debounce-save
|
|
124
157
|
Promise.resolve(result).then(function () {
|
|
125
158
|
if (Date.now() - lastSave > debounce) {
|
|
126
159
|
saveToDisk(appStatePath);
|
|
@@ -130,10 +163,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
130
163
|
return result;
|
|
131
164
|
};
|
|
132
165
|
|
|
166
|
+
// Expose manual save
|
|
133
167
|
api.saveSession = function (customPath) {
|
|
134
168
|
return saveToDisk(customPath || appStatePath);
|
|
135
169
|
};
|
|
136
170
|
|
|
171
|
+
// Expose restore from backup
|
|
137
172
|
api.restoreSessionBackup = function (customPath) {
|
|
138
173
|
var bakPath = (customPath || appStatePath) + ".bak";
|
|
139
174
|
if (!fs.existsSync(bakPath)) {
|
|
@@ -151,6 +186,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
151
186
|
}
|
|
152
187
|
};
|
|
153
188
|
|
|
189
|
+
// Expose stop
|
|
154
190
|
api.stopSessionGuard = function () {
|
|
155
191
|
if (intervalRef) clearInterval(intervalRef);
|
|
156
192
|
api.sendMessage = originalSendMessage;
|
|
@@ -5,7 +5,7 @@ const { generateOfflineThreadingID, getCurrentTimestamp } = require("../../utils
|
|
|
5
5
|
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
7
|
return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
|
|
8
|
-
|
|
8
|
+
// ✅ MueidMursalinRifat Fix: threadID is now optional (backward compatible)
|
|
9
9
|
if (typeof threadID === "function") {
|
|
10
10
|
forceCustomReaction = callback;
|
|
11
11
|
callback = threadID;
|
|
@@ -20,6 +20,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
20
20
|
}
|
|
21
21
|
const cb = typeof callback === "function" ? callback : undefined;
|
|
22
22
|
|
|
23
|
+
// threadID না থাকলে ctx থেকে নেওয়ার চেষ্টা
|
|
23
24
|
const finalThreadID = threadID || ctx.lastThreadID || "0";
|
|
24
25
|
|
|
25
26
|
return new Promise((resolve, reject) => {
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
module.exports = function(_defaultFuncs, _api, _ctx) {
|
|
4
|
-
|
|
4
|
+
// Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
|
|
5
5
|
return {
|
|
6
|
+
//Old hex colors.
|
|
7
|
+
////MessengerBlue: null,
|
|
8
|
+
////Viking: "#44bec7",
|
|
9
|
+
////GoldenPoppy: "#ffc300",
|
|
10
|
+
////RadicalRed: "#fa3c4c",
|
|
11
|
+
////Shocking: "#d696bb",
|
|
12
|
+
////PictonBlue: "#6699cc",
|
|
13
|
+
////FreeSpeechGreen: "#13cf13",
|
|
14
|
+
////Pumpkin: "#ff7e29",
|
|
15
|
+
////LightCoral: "#e68585",
|
|
16
|
+
////MediumSlateBlue: "#7646ff",
|
|
17
|
+
////DeepSkyBlue: "#20cef5",
|
|
18
|
+
////Fern: "#67b868",
|
|
19
|
+
////Cameo: "#d4a88c",
|
|
20
|
+
////BrilliantRose: "#ff5ca1",
|
|
21
|
+
////BilobaFlower: "#a695c7"
|
|
6
22
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
//#region This part is for backward compatibly
|
|
24
|
+
//trying to match the color one-by-one. kill me plz
|
|
25
|
+
MessengerBlue: "196241301102133", //DefaultBlue
|
|
26
|
+
Viking: "1928399724138152", //TealBlue
|
|
27
|
+
GoldenPoppy: "174636906462322", //Yellow
|
|
28
|
+
RadicalRed: "2129984390566328", //Red
|
|
29
|
+
Shocking: "2058653964378557", //LavenderPurple
|
|
30
|
+
FreeSpeechGreen: "2136751179887052", //Green
|
|
31
|
+
Pumpkin: "175615189761153", //Orange
|
|
32
|
+
LightCoral: "980963458735625", //CoralPink
|
|
33
|
+
MediumSlateBlue: "234137870477637", //BrightPurple
|
|
34
|
+
DeepSkyBlue: "2442142322678320", //AquaBlue
|
|
35
|
+
BrilliantRose: "169463077092846", //HotPink
|
|
18
36
|
DefaultBlue: "196241301102133",
|
|
19
37
|
HotPink: "169463077092846",
|
|
20
38
|
AquaBlue: "2442142322678320",
|
|
@@ -32,6 +50,10 @@ module.exports = function(_defaultFuncs, _api, _ctx) {
|
|
|
32
50
|
Citrus: "370940413392601",
|
|
33
51
|
Candy: "205488546921017",
|
|
34
52
|
|
|
53
|
+
/**
|
|
54
|
+
* July 06, 2022
|
|
55
|
+
* added by @NTKhang
|
|
56
|
+
*/
|
|
35
57
|
Earth: "1833559466821043",
|
|
36
58
|
Support: "365557122117011",
|
|
37
59
|
Music: "339021464972092",
|
|
@@ -73,8 +95,16 @@ module.exports = function(_defaultFuncs, _api, _ctx) {
|
|
|
73
95
|
Kiwi: "3151463484918004",
|
|
74
96
|
Grape: "193497045377796",
|
|
75
97
|
|
|
98
|
+
/**
|
|
99
|
+
* July 15, 2022
|
|
100
|
+
* added by @NTKhang
|
|
101
|
+
*/
|
|
76
102
|
NonBinary: "737761000603635",
|
|
77
103
|
|
|
104
|
+
/**
|
|
105
|
+
* November 25, 2022
|
|
106
|
+
* added by @NTKhang
|
|
107
|
+
*/
|
|
78
108
|
ThankfulForFriends: "1318983195536293",
|
|
79
109
|
Transgender: "504518465021637",
|
|
80
110
|
TaylorSwift: "769129927636836",
|
|
@@ -82,6 +112,9 @@ module.exports = function(_defaultFuncs, _api, _ctx) {
|
|
|
82
112
|
Autumn: "822549609168155",
|
|
83
113
|
Cyberpunk2077: "780962576430091",
|
|
84
114
|
|
|
115
|
+
/**
|
|
116
|
+
* May 13, 2023
|
|
117
|
+
*/
|
|
85
118
|
MothersDay: "1288506208402340",
|
|
86
119
|
APAHM: "121771470870245",
|
|
87
120
|
Parenthood: "810978360551741",
|
|
@@ -11,11 +11,32 @@ const { URL } = require("url");
|
|
|
11
11
|
const log = require("../../../func/logAdapter");
|
|
12
12
|
const { getIdentity } = require("../../utils/clientIdentity");
|
|
13
13
|
|
|
14
|
+
// Resolved from the same centralized identity as every other subsystem
|
|
15
|
+
// (HTTP requests, MQTT) so upload requests never claim a different Chrome
|
|
16
|
+
// version/sec-ch-ua than the rest of the session. Do not hard-code a
|
|
17
|
+
// separate browser version here. This part is stateless/pure, so it's safe
|
|
18
|
+
// to keep at module scope - it's read-only and identical for every session
|
|
19
|
+
// using the default identity.
|
|
14
20
|
const DEFAULT_IDENTITY = getIdentity();
|
|
15
21
|
const DEFAULT_UA = DEFAULT_IDENTITY.userAgent;
|
|
16
22
|
|
|
17
23
|
const TOKEN_CACHE_TTL = 5 * 60 * 1000;
|
|
18
24
|
|
|
25
|
+
// NOTE ON SESSION ISOLATION:
|
|
26
|
+
// Previously `http` (the axios instance), `cookieJar`, and `tokenCache` were
|
|
27
|
+
// module-level `let` variables. Since a Node `require()` cache is a
|
|
28
|
+
// singleton, every account/session that called this module's exported
|
|
29
|
+
// factory in the same process was silently sharing (and overwriting) the
|
|
30
|
+
// SAME axios instance, cookie jar, and cached fb_dtsg/lsd tokens. Logging in
|
|
31
|
+
// a second account would clobber the first account's cookie jar and token
|
|
32
|
+
// cache mid-session - the same class of bug as the shared CookieJar issue
|
|
33
|
+
// fixed in module/loginHelper.js, but specific to the upload path.
|
|
34
|
+
//
|
|
35
|
+
// Fix: every piece of session-scoped state now lives on a `sess` object
|
|
36
|
+
// created fresh inside the exported factory (one per login()/session) and
|
|
37
|
+
// is passed explicitly to the helper functions below instead of being read
|
|
38
|
+
// from module scope.
|
|
39
|
+
|
|
19
40
|
function cleanJSON(x) {
|
|
20
41
|
if (typeof x !== "string") return x;
|
|
21
42
|
const s = x.replace(/^for\s*\(;;\);\s*/i, "");
|
|
@@ -40,7 +61,9 @@ function respFinalUrl(res) {
|
|
|
40
61
|
}
|
|
41
62
|
|
|
42
63
|
function detectCheckpoint(res) {
|
|
43
|
-
|
|
64
|
+
// [Fixed by xalman] res.body -> res.data (axios response shape), same
|
|
65
|
+
// root cause as the parseAndCheckLogin fix in src/utils/utils.js - this
|
|
66
|
+
// was silently always reading undefined and never detecting checkpoints.
|
|
44
67
|
const url = String(respFinalUrl(res) || "");
|
|
45
68
|
const body = typeof res?.data === "string" ? res.data : "";
|
|
46
69
|
const hit =
|
|
@@ -114,7 +137,7 @@ async function getTokens(sess, ua, forceRefresh = false) {
|
|
|
114
137
|
const rev = pick(/"__rev":(\d+)/, html) || "";
|
|
115
138
|
|
|
116
139
|
if (!fb_dtsg || !lsd) {
|
|
117
|
-
|
|
140
|
+
// Cố gắng fallback nếu regex fail, nhưng thường là do cookie die
|
|
118
141
|
if (!cache.data) throw new Error("Failed to fetch fb_dtsg or LSD from Facebook");
|
|
119
142
|
}
|
|
120
143
|
|
|
@@ -270,9 +293,10 @@ function pLimit(n) {
|
|
|
270
293
|
});
|
|
271
294
|
}
|
|
272
295
|
|
|
296
|
+
// Hàm upload core xử lý request
|
|
273
297
|
async function singleUpload(sess, urlBase, file, ua, tokens, retries = 2) {
|
|
274
298
|
const form = new FormData();
|
|
275
|
-
|
|
299
|
+
// QUAN TRỌNG: Chỉ append file, KHÔNG append fb_dtsg vào body nữa
|
|
276
300
|
form.append("farr", file.stream, { filename: file.filename, contentType: file.contentType });
|
|
277
301
|
|
|
278
302
|
const headers = {
|
|
@@ -306,6 +330,7 @@ async function singleUpload(sess, urlBase, file, ua, tokens, retries = 2) {
|
|
|
306
330
|
Connection: "keep-alive"
|
|
307
331
|
};
|
|
308
332
|
|
|
333
|
+
// Build URL với query string tokens
|
|
309
334
|
const finalUrl = new URL(urlBase);
|
|
310
335
|
finalUrl.searchParams.set("fb_dtsg", tokens.fb_dtsg);
|
|
311
336
|
finalUrl.searchParams.set("jazoest", tokens.jazoest);
|
|
@@ -336,12 +361,19 @@ async function singleUpload(sess, urlBase, file, ua, tokens, retries = 2) {
|
|
|
336
361
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
337
362
|
const ua = ctx?.options?.userAgent || DEFAULT_UA;
|
|
338
363
|
|
|
364
|
+
// One session object per factory call (i.e. per login()/account), instead
|
|
365
|
+
// of the old module-level `http`/`cookieJar`/`tokenCache` singletons that
|
|
366
|
+
// every session in the process used to share and clobber. `ctx.jar` is
|
|
367
|
+
// itself already per-session (see module/loginHelper.js), so reusing it
|
|
368
|
+
// here (instead of creating yet another jar) also keeps upload requests
|
|
369
|
+
// and the rest of the session's HTTP traffic consistent with each other.
|
|
339
370
|
const sessionJar = ctx.jar instanceof CookieJar ? ctx.jar : new CookieJar();
|
|
340
371
|
const sess = {
|
|
341
372
|
http: null,
|
|
342
373
|
tokenCache: { data: null, time: 0 }
|
|
343
374
|
};
|
|
344
375
|
|
|
376
|
+
// Axios instance
|
|
345
377
|
sess.http = wrapper(axios.create({
|
|
346
378
|
timeout: 60000,
|
|
347
379
|
headers: {
|
|
@@ -388,6 +420,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
388
420
|
let tokens = await getTokens(sess, ua);
|
|
389
421
|
const normAll = await Promise.all(inputsArr.map(x => normalizeOne(sess, x, ua)));
|
|
390
422
|
|
|
423
|
+
// Base QS setup
|
|
391
424
|
const qs = [];
|
|
392
425
|
const userId = (ctx && (ctx.userID || ctx.userId)) ? String(ctx.userID || ctx.userId) : "";
|
|
393
426
|
if (userId) qs.push(`__user=${encodeURIComponent(userId)}`);
|
|
@@ -425,6 +458,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
425
458
|
return;
|
|
426
459
|
}
|
|
427
460
|
|
|
461
|
+
// Parallel mode
|
|
428
462
|
const limit = pLimit(options.concurrency);
|
|
429
463
|
const tasks = normAll.map(f => () => singleUpload(sess, baseUrl, f, ua, tokens));
|
|
430
464
|
const results = await Promise.all(tasks.map(t => limit(t)));
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
var utils = require("../../utils/utils");
|
|
4
4
|
var logger = require("../../utils/logger");
|
|
5
5
|
var bluebird = require("bluebird");
|
|
6
|
+
var { getTextEffectId } = require("../../utils/textEffects");
|
|
6
7
|
|
|
7
8
|
var allowedProperties = {
|
|
8
9
|
attachment: true, url: true, sticker: true, emoji: true,
|
|
9
|
-
emojiSize: true, body: true, mentions: true, location: true
|
|
10
|
+
emojiSize: true, body: true, mentions: true, location: true, text_effect_ids: true,
|
|
11
|
+
textEffect: true, text_effect: true, text_effect_id: true, textEffectId: true,
|
|
12
|
+
textEffectID: true, effect: true, effect_id: true, effectID: true,
|
|
13
|
+
text_effect_name: true, effectName: true, effect_name: true,
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
@@ -114,7 +118,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
114
118
|
|
|
115
119
|
return function OldMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
|
|
116
120
|
if (typeof msg === "string") msg = { body: msg };
|
|
117
|
-
["text_effect_ids", "textEffect", "text_effect", "text_effect_id", "textEffectId", "textEffectID", "effect", "effect_id", "effectID", "text_effect_name", "effectName", "effect_name"].forEach(function (k) { delete msg[k]; });
|
|
118
121
|
|
|
119
122
|
if (msg.body && /(https?:\/\/|www\.|t\.me\/|fb\.me\/|youtu\.be\/|facebook\.com\/|youtube\.com\/)/i.test(msg.body)) {
|
|
120
123
|
return require('./sendMessage')(defaultFuncs, api, ctx)(msg, threadID, callback, replyToMessage, false);
|
|
@@ -135,6 +138,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
135
138
|
|
|
136
139
|
var form = {};
|
|
137
140
|
if (msg.body) form.body = msg.body;
|
|
141
|
+
var textEffectId = getTextEffectId(msg);
|
|
142
|
+
if (textEffectId) form.text_effect_id = textEffectId;
|
|
138
143
|
|
|
139
144
|
if (msg.mentions && Array.isArray(msg.mentions)) {
|
|
140
145
|
form.body = msg.body || "";
|