@dongdev/fca-unofficial 3.0.31 → 4.0.1
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/LICENSE +191 -0
- package/README.md +238 -398
- package/dist/cjs.cjs +9 -0
- package/dist/index.d.mts +1250 -0
- package/dist/index.d.ts +1250 -0
- package/dist/index.js +27772 -0
- package/dist/index.mjs +27735 -0
- package/docs/ARCHITECTURE.md +467 -0
- package/docs/DOCS.md +709 -0
- package/fca-config.example.json +33 -0
- package/package.json +32 -22
- package/test/fca.test.cjs +540 -0
- package/CHANGELOG.md +0 -296
- package/DOCS.md +0 -2712
- package/func/checkUpdate.js +0 -222
- package/func/logAdapter.js +0 -33
- package/func/logger.js +0 -48
- package/index.d.ts +0 -751
- package/index.js +0 -8
- package/module/config.js +0 -40
- package/module/login.js +0 -133
- package/module/loginHelper.js +0 -1296
- package/module/options.js +0 -44
- package/src/api/action/addExternalModule.js +0 -25
- package/src/api/action/changeAvatar.js +0 -137
- package/src/api/action/changeBio.js +0 -75
- package/src/api/action/enableAutoSaveAppState.js +0 -73
- package/src/api/action/getCurrentUserID.js +0 -7
- package/src/api/action/handleFriendRequest.js +0 -57
- package/src/api/action/logout.js +0 -76
- package/src/api/action/refreshFb_dtsg.js +0 -48
- package/src/api/action/setPostReaction.js +0 -106
- package/src/api/action/unfriend.js +0 -54
- package/src/api/http/httpGet.js +0 -46
- package/src/api/http/httpPost.js +0 -52
- package/src/api/http/postFormData.js +0 -47
- package/src/api/messaging/addUserToGroup.js +0 -68
- package/src/api/messaging/changeAdminStatus.js +0 -126
- package/src/api/messaging/changeArchivedStatus.js +0 -55
- package/src/api/messaging/changeBlockedStatus.js +0 -48
- package/src/api/messaging/changeGroupImage.js +0 -91
- package/src/api/messaging/changeNickname.js +0 -70
- package/src/api/messaging/changeThreadColor.js +0 -79
- package/src/api/messaging/changeThreadEmoji.js +0 -111
- package/src/api/messaging/createNewGroup.js +0 -88
- package/src/api/messaging/createPoll.js +0 -46
- package/src/api/messaging/createThemeAI.js +0 -98
- package/src/api/messaging/deleteMessage.js +0 -136
- package/src/api/messaging/deleteThread.js +0 -56
- package/src/api/messaging/editMessage.js +0 -68
- package/src/api/messaging/forwardAttachment.js +0 -57
- package/src/api/messaging/getEmojiUrl.js +0 -29
- package/src/api/messaging/getFriendsList.js +0 -82
- package/src/api/messaging/getMessage.js +0 -829
- package/src/api/messaging/getThemePictures.js +0 -62
- package/src/api/messaging/handleMessageRequest.js +0 -65
- package/src/api/messaging/markAsDelivered.js +0 -57
- package/src/api/messaging/markAsRead.js +0 -88
- package/src/api/messaging/markAsReadAll.js +0 -49
- package/src/api/messaging/markAsSeen.js +0 -61
- package/src/api/messaging/muteThread.js +0 -50
- package/src/api/messaging/removeUserFromGroup.js +0 -62
- package/src/api/messaging/resolvePhotoUrl.js +0 -43
- package/src/api/messaging/scheduler.js +0 -264
- package/src/api/messaging/searchForThread.js +0 -53
- package/src/api/messaging/sendMessage.js +0 -270
- package/src/api/messaging/sendTypingIndicator.js +0 -74
- package/src/api/messaging/setMessageReaction.js +0 -90
- package/src/api/messaging/setTitle.js +0 -124
- package/src/api/messaging/shareContact.js +0 -49
- package/src/api/messaging/threadColors.js +0 -128
- package/src/api/messaging/unsendMessage.js +0 -81
- package/src/api/messaging/uploadAttachment.js +0 -492
- package/src/api/socket/core/connectMqtt.js +0 -258
- package/src/api/socket/core/emitAuth.js +0 -103
- package/src/api/socket/core/getSeqID.js +0 -320
- package/src/api/socket/core/getTaskResponseData.js +0 -25
- package/src/api/socket/core/parseDelta.js +0 -377
- package/src/api/socket/detail/buildStream.js +0 -215
- package/src/api/socket/detail/constants.js +0 -28
- package/src/api/socket/listenMqtt.js +0 -377
- package/src/api/socket/middleware/index.js +0 -216
- package/src/api/threads/getThreadHistory.js +0 -664
- package/src/api/threads/getThreadInfo.js +0 -296
- package/src/api/threads/getThreadList.js +0 -293
- package/src/api/threads/getThreadPictures.js +0 -78
- package/src/api/users/getUserID.js +0 -65
- package/src/api/users/getUserInfo.js +0 -402
- package/src/api/users/getUserInfoV2.js +0 -134
- package/src/core/sendReqMqtt.js +0 -96
- package/src/database/helpers.js +0 -53
- package/src/database/models/index.js +0 -88
- package/src/database/models/thread.js +0 -50
- package/src/database/models/user.js +0 -46
- package/src/database/threadData.js +0 -94
- package/src/database/userData.js +0 -98
- package/src/remote/remoteClient.js +0 -123
- package/src/utils/broadcast.js +0 -51
- package/src/utils/client.js +0 -10
- package/src/utils/constants.js +0 -23
- package/src/utils/cookies.js +0 -68
- package/src/utils/format/attachment.js +0 -357
- package/src/utils/format/cookie.js +0 -9
- package/src/utils/format/date.js +0 -50
- package/src/utils/format/decode.js +0 -44
- package/src/utils/format/delta.js +0 -194
- package/src/utils/format/ids.js +0 -64
- package/src/utils/format/index.js +0 -64
- package/src/utils/format/message.js +0 -88
- package/src/utils/format/presence.js +0 -132
- package/src/utils/format/readTyp.js +0 -44
- package/src/utils/format/thread.js +0 -42
- package/src/utils/format/utils.js +0 -141
- package/src/utils/headers.js +0 -115
- package/src/utils/loginParser/autoLogin.js +0 -125
- package/src/utils/loginParser/helpers.js +0 -43
- package/src/utils/loginParser/index.js +0 -10
- package/src/utils/loginParser/parseAndCheckLogin.js +0 -220
- package/src/utils/loginParser/textUtils.js +0 -28
- package/src/utils/request/client.js +0 -26
- package/src/utils/request/config.js +0 -23
- package/src/utils/request/defaults.js +0 -46
- package/src/utils/request/helpers.js +0 -46
- package/src/utils/request/index.js +0 -17
- package/src/utils/request/methods.js +0 -163
- package/src/utils/request/proxy.js +0 -21
- package/src/utils/request/retry.js +0 -77
- package/src/utils/request/sanitize.js +0 -49
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const log = require("../../../func/logAdapter");
|
|
4
|
-
const { formatID } = require("../../utils/format");
|
|
5
|
-
function formatData(data) {
|
|
6
|
-
return {
|
|
7
|
-
userID: formatID(data.uid.toString()),
|
|
8
|
-
photoUrl: data.photo,
|
|
9
|
-
indexRank: data.index_rank,
|
|
10
|
-
name: data.text,
|
|
11
|
-
isVerified: data.is_verified,
|
|
12
|
-
profileUrl: data.path,
|
|
13
|
-
category: data.category,
|
|
14
|
-
score: data.score,
|
|
15
|
-
type: data.type
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
20
|
-
return function getUserID(name, callback) {
|
|
21
|
-
let resolveFunc = function() {};
|
|
22
|
-
let rejectFunc = function() {};
|
|
23
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
24
|
-
resolveFunc = resolve;
|
|
25
|
-
rejectFunc = reject;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (!callback) {
|
|
29
|
-
callback = function(err, friendList) {
|
|
30
|
-
if (err) {
|
|
31
|
-
return rejectFunc(err);
|
|
32
|
-
}
|
|
33
|
-
resolveFunc(friendList);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const form = {
|
|
38
|
-
value: name.toLowerCase(),
|
|
39
|
-
viewer: ctx.userID,
|
|
40
|
-
rsp: "search",
|
|
41
|
-
context: "search",
|
|
42
|
-
path: "/home.php",
|
|
43
|
-
request_id: ctx.clientId
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
defaultFuncs
|
|
47
|
-
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
|
48
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
49
|
-
.then(function(resData) {
|
|
50
|
-
if (resData.error) {
|
|
51
|
-
throw resData;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const data = resData.payload.entries;
|
|
55
|
-
|
|
56
|
-
callback(null, data.map(formatData));
|
|
57
|
-
})
|
|
58
|
-
.catch(function(err) {
|
|
59
|
-
log.error("getUserID", err);
|
|
60
|
-
return callback(err);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return returnPromise;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const log = require("../../../func/logAdapter");
|
|
6
|
-
const logger = require("../../../func/logger");
|
|
7
|
-
const { parseAndCheckLogin } = require("../../utils/client.js");
|
|
8
|
-
|
|
9
|
-
const DOC_PRIMARY = "5009315269112105";
|
|
10
|
-
const BATCH_PRIMARY = "MessengerParticipantsFetcher";
|
|
11
|
-
const DOC_V2 = "24418640587785718";
|
|
12
|
-
const FRIENDLY_V2 = "CometHovercardQueryRendererQuery";
|
|
13
|
-
const CALLER_V2 = "RelayModern";
|
|
14
|
-
|
|
15
|
-
function toJSONMaybe(s) {
|
|
16
|
-
if (!s) return null;
|
|
17
|
-
if (typeof s === "string") {
|
|
18
|
-
const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
|
|
19
|
-
try { return JSON.parse(t); } catch { return null; }
|
|
20
|
-
}
|
|
21
|
-
return s;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function usernameFromUrl(raw) {
|
|
25
|
-
if (!raw) return null;
|
|
26
|
-
try {
|
|
27
|
-
const u = new URL(raw);
|
|
28
|
-
if (/^www\.facebook\.com$/i.test(u.hostname)) {
|
|
29
|
-
const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
|
|
30
|
-
if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
|
|
31
|
-
}
|
|
32
|
-
} catch { }
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function pickMeta(u) {
|
|
37
|
-
let friendshipStatus = null;
|
|
38
|
-
let gender = null;
|
|
39
|
-
let shortName = u?.short_name || null;
|
|
40
|
-
const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
|
|
41
|
-
const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
|
|
42
|
-
const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
|
|
43
|
-
if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
|
|
44
|
-
const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
|
|
45
|
-
friendshipStatus = p?.friendship_status || null;
|
|
46
|
-
gender = p?.gender || gender;
|
|
47
|
-
shortName = p?.short_name || shortName;
|
|
48
|
-
}
|
|
49
|
-
if (!gender || !shortName) {
|
|
50
|
-
const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
|
|
51
|
-
const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
|
|
52
|
-
if (p2) {
|
|
53
|
-
gender = p2.gender || gender;
|
|
54
|
-
shortName = p2.short_name || shortName;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { friendshipStatus, gender, shortName };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function normalizeV2User(u) {
|
|
61
|
-
if (!u) return null;
|
|
62
|
-
const vanity = usernameFromUrl(u.profile_url || u.url);
|
|
63
|
-
const meta = pickMeta(u);
|
|
64
|
-
return {
|
|
65
|
-
id: u.id || null,
|
|
66
|
-
name: u.name || null,
|
|
67
|
-
firstName: meta.shortName || null,
|
|
68
|
-
vanity: vanity || u.username_for_profile || null,
|
|
69
|
-
thumbSrc: u.profile_picture?.uri || null,
|
|
70
|
-
profileUrl: u.profile_url || u.url || null,
|
|
71
|
-
gender: meta.gender || null,
|
|
72
|
-
type: "User",
|
|
73
|
-
isFriend: meta.friendshipStatus === "ARE_FRIENDS",
|
|
74
|
-
isMessengerUser: null,
|
|
75
|
-
isMessageBlockedByViewer: false,
|
|
76
|
-
workInfo: null,
|
|
77
|
-
messengerStatus: null
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function normalizePrimaryActor(a) {
|
|
82
|
-
if (!a) return null;
|
|
83
|
-
return {
|
|
84
|
-
id: a.id || null,
|
|
85
|
-
name: a.name || null,
|
|
86
|
-
firstName: a.short_name || null,
|
|
87
|
-
vanity: a.username || null,
|
|
88
|
-
thumbSrc: a.big_image_src?.uri || null,
|
|
89
|
-
profileUrl: a.url || null,
|
|
90
|
-
gender: a.gender || null,
|
|
91
|
-
type: a.__typename || null,
|
|
92
|
-
isFriend: !!a.is_viewer_friend,
|
|
93
|
-
isMessengerUser: !!a.is_messenger_user,
|
|
94
|
-
isMessageBlockedByViewer: !!a.is_message_blocked_by_viewer,
|
|
95
|
-
workInfo: a.work_info || null,
|
|
96
|
-
messengerStatus: a.messenger_account_status_category || null
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function mergeUserEntry(a, b) {
|
|
101
|
-
if (!a && !b) return null;
|
|
102
|
-
const x = a || {};
|
|
103
|
-
const y = b || {};
|
|
104
|
-
return {
|
|
105
|
-
id: x.id || y.id || null,
|
|
106
|
-
name: x.name || y.name || null,
|
|
107
|
-
firstName: x.firstName || y.firstName || null,
|
|
108
|
-
vanity: x.vanity || y.vanity || null,
|
|
109
|
-
thumbSrc: x.thumbSrc || y.thumbSrc || null,
|
|
110
|
-
profileUrl: x.profileUrl || y.profileUrl || null,
|
|
111
|
-
gender: x.gender || y.gender || null,
|
|
112
|
-
type: x.type || y.type || null,
|
|
113
|
-
isFriend: typeof x.isFriend === "boolean" ? x.isFriend : (typeof y.isFriend === "boolean" ? y.isFriend : false),
|
|
114
|
-
isMessengerUser: typeof x.isMessengerUser === "boolean" ? x.isMessengerUser : (typeof y.isMessengerUser === "boolean" ? y.isMessengerUser : null),
|
|
115
|
-
isMessageBlockedByViewer: typeof x.isMessageBlockedByViewer === "boolean" ? x.isMessageBlockedByViewer : (typeof y.isMessageBlockedByViewer === "boolean" ? y.isMessageBlockedByViewer : false),
|
|
116
|
-
workInfo: x.workInfo || y.workInfo || null,
|
|
117
|
-
messengerStatus: x.messengerStatus || y.messengerStatus || null
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
122
|
-
// Read FastConfig-style anti-get-info flag from global config (if available)
|
|
123
|
-
const cfg = global.fca && global.fca.config;
|
|
124
|
-
const antiCfg = cfg && cfg.antiGetInfo;
|
|
125
|
-
const disableAntiUserInfo = !!(antiCfg && antiCfg.AntiGetUserInfo === true);
|
|
126
|
-
|
|
127
|
-
// Lightweight, Horizon-style implementation without database/queue
|
|
128
|
-
if (disableAntiUserInfo) {
|
|
129
|
-
function formatLegacyData(data) {
|
|
130
|
-
const retObj = {};
|
|
131
|
-
for (const prop in data) {
|
|
132
|
-
if (!Object.prototype.hasOwnProperty.call(data, prop)) continue;
|
|
133
|
-
const innerObj = data[prop] || {};
|
|
134
|
-
retObj[prop] = {
|
|
135
|
-
name: innerObj.name || null,
|
|
136
|
-
firstName: innerObj.firstName || null,
|
|
137
|
-
vanity: innerObj.vanity || null,
|
|
138
|
-
thumbSrc: innerObj.thumbSrc || null,
|
|
139
|
-
profileUrl: innerObj.uri || innerObj.profileUrl || null,
|
|
140
|
-
gender: innerObj.gender || null,
|
|
141
|
-
type: innerObj.type || null,
|
|
142
|
-
isFriend: !!innerObj.is_friend,
|
|
143
|
-
isBirthday: !!innerObj.is_birthday
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return retObj;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return function getUserInfo(idsOrId, callback) {
|
|
150
|
-
let resolveFunc;
|
|
151
|
-
let rejectFunc;
|
|
152
|
-
const returnPromise = new Promise((resolve, reject) => {
|
|
153
|
-
resolveFunc = resolve;
|
|
154
|
-
rejectFunc = reject;
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
if (typeof callback !== "function") {
|
|
158
|
-
callback = (err, userInfo) => {
|
|
159
|
-
if (err) return rejectFunc(err);
|
|
160
|
-
resolveFunc(userInfo);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const ids = Array.isArray(idsOrId) ? idsOrId : [idsOrId];
|
|
165
|
-
const form = {};
|
|
166
|
-
ids.forEach((v, i) => {
|
|
167
|
-
form[`ids[${i}]`] = v;
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
defaultFuncs
|
|
171
|
-
.post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
|
|
172
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
173
|
-
.then(resData => {
|
|
174
|
-
if (resData.error) throw resData;
|
|
175
|
-
const profiles = resData?.payload?.profiles || {};
|
|
176
|
-
return callback(null, formatLegacyData(profiles));
|
|
177
|
-
})
|
|
178
|
-
.catch(err => {
|
|
179
|
-
log.error(
|
|
180
|
-
"getUserInfo",
|
|
181
|
-
"Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
|
|
182
|
-
);
|
|
183
|
-
return callback(err);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
return returnPromise;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const queue = [];
|
|
191
|
-
let isProcessingQueue = false;
|
|
192
|
-
const processingUsers = new Set();
|
|
193
|
-
const queuedUsers = new Set();
|
|
194
|
-
const cooldown = new Map();
|
|
195
|
-
|
|
196
|
-
const dbFiles = fs.readdirSync(path.join(__dirname, "../../database"))
|
|
197
|
-
.filter(f => path.extname(f) === ".js")
|
|
198
|
-
.reduce((acc, file) => {
|
|
199
|
-
const mod = require(path.join(__dirname, "../../database", file));
|
|
200
|
-
acc[path.basename(file, ".js")] = typeof mod === "function" ? mod(api) : mod;
|
|
201
|
-
return acc;
|
|
202
|
-
}, {});
|
|
203
|
-
const { userData } = dbFiles;
|
|
204
|
-
const { create, get, update, getAll } = userData;
|
|
205
|
-
|
|
206
|
-
async function fetchPrimary(ids) {
|
|
207
|
-
const form = {
|
|
208
|
-
queries: JSON.stringify({
|
|
209
|
-
o0: {
|
|
210
|
-
doc_id: DOC_PRIMARY,
|
|
211
|
-
query_params: { ids }
|
|
212
|
-
}
|
|
213
|
-
}),
|
|
214
|
-
batch_name: BATCH_PRIMARY
|
|
215
|
-
};
|
|
216
|
-
const resData = await defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form).then(parseAndCheckLogin(ctx, defaultFuncs));
|
|
217
|
-
if (!resData || resData.length === 0) throw new Error("Empty response");
|
|
218
|
-
const first = resData[0];
|
|
219
|
-
if (!first || !first.o0) throw new Error("Invalid batch payload");
|
|
220
|
-
if (first.o0.errors && first.o0.errors.length) throw new Error(first.o0.errors[0].message || "GraphQL error");
|
|
221
|
-
const result = first.o0.data;
|
|
222
|
-
if (!result || !Array.isArray(result.messaging_actors)) return {};
|
|
223
|
-
const out = {};
|
|
224
|
-
for (const actor of result.messaging_actors) {
|
|
225
|
-
const n = normalizePrimaryActor(actor);
|
|
226
|
-
if (n?.id) out[n.id] = n;
|
|
227
|
-
}
|
|
228
|
-
return out;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async function fetchV2One(uid) {
|
|
232
|
-
const av = String(ctx?.userID || "");
|
|
233
|
-
const variablesObj = {
|
|
234
|
-
actionBarRenderLocation: "WWW_COMET_HOVERCARD",
|
|
235
|
-
context: "DEFAULT",
|
|
236
|
-
entityID: String(uid),
|
|
237
|
-
scale: 1,
|
|
238
|
-
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
|
|
239
|
-
};
|
|
240
|
-
const form = {
|
|
241
|
-
av,
|
|
242
|
-
fb_api_caller_class: CALLER_V2,
|
|
243
|
-
fb_api_req_friendly_name: FRIENDLY_V2,
|
|
244
|
-
server_timestamps: true,
|
|
245
|
-
doc_id: DOC_V2,
|
|
246
|
-
variables: JSON.stringify(variablesObj)
|
|
247
|
-
};
|
|
248
|
-
const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", null, form).then(parseAndCheckLogin(ctx, defaultFuncs));
|
|
249
|
-
const parsed = toJSONMaybe(raw) ?? raw;
|
|
250
|
-
const root = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
251
|
-
const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
|
|
252
|
-
const n = normalizeV2User(user);
|
|
253
|
-
return n && n.id ? { [n.id]: n } : {};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async function upsertUser(id, entry) {
|
|
257
|
-
try {
|
|
258
|
-
const existing = await get(id);
|
|
259
|
-
if (existing) {
|
|
260
|
-
await update(id, { data: entry });
|
|
261
|
-
} else {
|
|
262
|
-
await create(id, { data: entry });
|
|
263
|
-
}
|
|
264
|
-
} catch (e) {
|
|
265
|
-
logger(`user upsert ${id} error: ${e?.message || e}`, "warn");
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
async function fetchAndPersist(ids, creating = false) {
|
|
270
|
-
const result = {};
|
|
271
|
-
try {
|
|
272
|
-
const primary = await fetchPrimary(ids);
|
|
273
|
-
for (const id of ids) result[id] = primary[id] || null;
|
|
274
|
-
} catch (e) {
|
|
275
|
-
logger(`primary fetch error: ${e?.message || e}`, "warn");
|
|
276
|
-
}
|
|
277
|
-
if (creating) {
|
|
278
|
-
const needFallback = ids.filter(id => !result[id]);
|
|
279
|
-
if (needFallback.length) {
|
|
280
|
-
const tasks = needFallback.map(id => fetchV2One(id).catch(() => ({})));
|
|
281
|
-
const r = await Promise.allSettled(tasks);
|
|
282
|
-
for (let i = 0; i < needFallback.length; i++) {
|
|
283
|
-
const id = needFallback[i];
|
|
284
|
-
const ok = r[i].status === "fulfilled" ? r[i].value : {};
|
|
285
|
-
const n = ok[id] || null;
|
|
286
|
-
result[id] = n || null;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
for (const id of ids) {
|
|
291
|
-
const merged = result[id] || null;
|
|
292
|
-
if (merged) await upsertUser(id, merged);
|
|
293
|
-
}
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async function refreshAUser(id) {
|
|
298
|
-
try {
|
|
299
|
-
const out = await fetchAndPersist([id], false);
|
|
300
|
-
if (!out[id]) cooldown.set(id, Date.now() + 5 * 60 * 1000);
|
|
301
|
-
} catch (e) {
|
|
302
|
-
cooldown.set(id, Date.now() + 5 * 60 * 1000);
|
|
303
|
-
logger(`refresh user ${id} error: ${e?.message || e}`, "warn");
|
|
304
|
-
} finally {
|
|
305
|
-
queuedUsers.delete(id);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
async function checkAndUpdateUsers() {
|
|
310
|
-
try {
|
|
311
|
-
const all = await getAll("userID");
|
|
312
|
-
const now = Date.now();
|
|
313
|
-
for (const row of all) {
|
|
314
|
-
const id = row.userID;
|
|
315
|
-
const cd = cooldown.get(id);
|
|
316
|
-
if (cd && now < cd) continue;
|
|
317
|
-
const lastUpdated = new Date(row.updatedAt).getTime();
|
|
318
|
-
if ((now - lastUpdated) / (1000 * 60) > 10 && !queuedUsers.has(id)) {
|
|
319
|
-
queuedUsers.add(id);
|
|
320
|
-
queue.push(() => refreshAUser(id));
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
} catch (e) {
|
|
324
|
-
logger(`checkAndUpdateUsers error: ${e?.message || e}`, "error");
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
async function processQueue() {
|
|
329
|
-
if (isProcessingQueue) return;
|
|
330
|
-
isProcessingQueue = true;
|
|
331
|
-
while (queue.length > 0) {
|
|
332
|
-
const task = queue.shift();
|
|
333
|
-
try {
|
|
334
|
-
await task();
|
|
335
|
-
} catch (e) {
|
|
336
|
-
logger(`user queue error: ${e?.message || e}`, "error");
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
isProcessingQueue = false;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Store interval reference for cleanup
|
|
343
|
-
const updateInterval = setInterval(() => {
|
|
344
|
-
checkAndUpdateUsers();
|
|
345
|
-
processQueue();
|
|
346
|
-
}, 10000);
|
|
347
|
-
|
|
348
|
-
// Store interval in ctx for cleanup on logout/stop
|
|
349
|
-
if (!ctx._userInfoIntervals) {
|
|
350
|
-
ctx._userInfoIntervals = [];
|
|
351
|
-
}
|
|
352
|
-
ctx._userInfoIntervals.push(updateInterval);
|
|
353
|
-
|
|
354
|
-
return function getUserInfo(idsOrId, callback) {
|
|
355
|
-
let resolveFunc, rejectFunc;
|
|
356
|
-
const returnPromise = new Promise((resolve, reject) => { resolveFunc = resolve; rejectFunc = reject; });
|
|
357
|
-
if (typeof callback !== "function") {
|
|
358
|
-
callback = (err, data) => { if (err) return rejectFunc(err); resolveFunc(data); };
|
|
359
|
-
}
|
|
360
|
-
const ids = Array.isArray(idsOrId) ? idsOrId.map(v => String(v)) : [String(idsOrId)];
|
|
361
|
-
Promise.all(ids.map(id => get(id).catch(() => null))).then(async cachedRows => {
|
|
362
|
-
const ret = {};
|
|
363
|
-
const needCreate = [];
|
|
364
|
-
for (let i = 0; i < ids.length; i++) {
|
|
365
|
-
const id = ids[i];
|
|
366
|
-
const row = cachedRows[i];
|
|
367
|
-
if (row?.data && row.data.id) {
|
|
368
|
-
ret[id] = row.data;
|
|
369
|
-
} else {
|
|
370
|
-
needCreate.push(id);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
if (needCreate.length) {
|
|
374
|
-
const fetched = await fetchAndPersist(needCreate, true);
|
|
375
|
-
for (const id of needCreate) ret[id] = fetched[id] || {
|
|
376
|
-
id,
|
|
377
|
-
name: null,
|
|
378
|
-
firstName: null,
|
|
379
|
-
vanity: null,
|
|
380
|
-
thumbSrc: null,
|
|
381
|
-
profileUrl: null,
|
|
382
|
-
gender: null,
|
|
383
|
-
type: null,
|
|
384
|
-
isFriend: false,
|
|
385
|
-
isMessengerUser: null,
|
|
386
|
-
isMessageBlockedByViewer: false,
|
|
387
|
-
workInfo: null,
|
|
388
|
-
messengerStatus: null
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
return callback(null, ret);
|
|
392
|
-
}).catch(err => {
|
|
393
|
-
// Horizon-style anti-get-info message to hint rate limiting / spam block
|
|
394
|
-
log.error(
|
|
395
|
-
"getUserInfo",
|
|
396
|
-
"Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
|
|
397
|
-
);
|
|
398
|
-
callback(err);
|
|
399
|
-
});
|
|
400
|
-
return returnPromise;
|
|
401
|
-
};
|
|
402
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parseAndCheckLogin } = require("../../utils/client.js");
|
|
4
|
-
const logger = require("../../../func/logger");
|
|
5
|
-
const DEFAULT_DOC_ID = "24418640587785718";
|
|
6
|
-
const DEFAULT_FRIENDLY_NAME = "CometHovercardQueryRendererQuery";
|
|
7
|
-
const DEFAULT_CALLER_CLASS = "RelayModern";
|
|
8
|
-
|
|
9
|
-
function toJSONMaybe(s) {
|
|
10
|
-
if (!s) return null;
|
|
11
|
-
if (typeof s === "string") {
|
|
12
|
-
const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
|
|
13
|
-
try { return JSON.parse(t); } catch { return null; }
|
|
14
|
-
}
|
|
15
|
-
return s;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function usernameFromUrl(raw) {
|
|
19
|
-
if (!raw) return null;
|
|
20
|
-
try {
|
|
21
|
-
const u = new URL(raw);
|
|
22
|
-
if (/^www\.facebook\.com$/i.test(u.hostname)) {
|
|
23
|
-
const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
|
|
24
|
-
if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
|
|
25
|
-
}
|
|
26
|
-
} catch { }
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function pickMeta(u) {
|
|
31
|
-
let friendshipStatus = null;
|
|
32
|
-
let gender = null;
|
|
33
|
-
let shortName = u?.short_name || null;
|
|
34
|
-
const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
|
|
35
|
-
const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
|
|
36
|
-
const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
|
|
37
|
-
if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
|
|
38
|
-
const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
|
|
39
|
-
friendshipStatus = p?.friendship_status || null;
|
|
40
|
-
gender = p?.gender || gender;
|
|
41
|
-
shortName = p?.short_name || shortName;
|
|
42
|
-
}
|
|
43
|
-
if (!gender || !shortName) {
|
|
44
|
-
const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
|
|
45
|
-
const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
|
|
46
|
-
if (p2) {
|
|
47
|
-
gender = p2.gender || gender;
|
|
48
|
-
shortName = p2.short_name || shortName;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return { friendshipStatus, gender, shortName };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function normalizeUser(u) {
|
|
55
|
-
if (!u) return null;
|
|
56
|
-
const vanity = usernameFromUrl(u.profile_url || u.url);
|
|
57
|
-
const meta = pickMeta(u);
|
|
58
|
-
return {
|
|
59
|
-
id: u.id || null,
|
|
60
|
-
name: u.name || null,
|
|
61
|
-
username: vanity || u.username_for_profile || null,
|
|
62
|
-
profileUrl: u.profile_url || u.url || null,
|
|
63
|
-
url: u.url || null,
|
|
64
|
-
isVerified: !!u.is_verified,
|
|
65
|
-
isMemorialized: !!u.is_visibly_memorialized,
|
|
66
|
-
avatar: u.profile_picture?.uri || null,
|
|
67
|
-
shortName: meta.shortName || null,
|
|
68
|
-
gender: meta.gender || null,
|
|
69
|
-
friendshipStatus: meta.friendshipStatus || null
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function toRetObjEntry(nu) {
|
|
74
|
-
return {
|
|
75
|
-
name: nu?.name || null,
|
|
76
|
-
firstName: nu?.shortName || null,
|
|
77
|
-
vanity: nu?.username || null,
|
|
78
|
-
thumbSrc: nu?.avatar || null,
|
|
79
|
-
profileUrl: nu?.profileUrl || null,
|
|
80
|
-
gender: nu?.gender || null,
|
|
81
|
-
type: "User",
|
|
82
|
-
isFriend: nu?.friendshipStatus === "ARE_FRIENDS",
|
|
83
|
-
isMessengerUser: null,
|
|
84
|
-
isMessageBlockedByViewer: false,
|
|
85
|
-
workInfo: null,
|
|
86
|
-
messengerStatus: null
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
91
|
-
async function fetchOne(uid) {
|
|
92
|
-
const av = String(ctx?.userID || "");
|
|
93
|
-
const variablesObj = {
|
|
94
|
-
actionBarRenderLocation: "WWW_COMET_HOVERCARD",
|
|
95
|
-
context: "DEFAULT",
|
|
96
|
-
entityID: String(uid),
|
|
97
|
-
scale: 1,
|
|
98
|
-
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
|
|
99
|
-
};
|
|
100
|
-
const form = {
|
|
101
|
-
av,
|
|
102
|
-
fb_api_caller_class: DEFAULT_CALLER_CLASS,
|
|
103
|
-
fb_api_req_friendly_name: DEFAULT_FRIENDLY_NAME,
|
|
104
|
-
server_timestamps: true,
|
|
105
|
-
doc_id: DEFAULT_DOC_ID,
|
|
106
|
-
variables: JSON.stringify(variablesObj)
|
|
107
|
-
};
|
|
108
|
-
const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", null, form).then(parseAndCheckLogin(ctx, defaultFuncs));
|
|
109
|
-
const parsed = toJSONMaybe(raw) ?? raw;
|
|
110
|
-
const root = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
111
|
-
const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
|
|
112
|
-
return normalizeUser(user);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return function getUserInfoV2(idOrList, callback) {
|
|
116
|
-
let resolveFunc, rejectFunc;
|
|
117
|
-
const returnPromise = new Promise((resolve, reject) => { resolveFunc = resolve; rejectFunc = reject; });
|
|
118
|
-
if (typeof callback !== "function") {
|
|
119
|
-
callback = (err, data) => { if (err) return rejectFunc(err); resolveFunc(data); };
|
|
120
|
-
}
|
|
121
|
-
const ids = Array.isArray(idOrList) ? idOrList.map(v => String(v)) : [String(idOrList)];
|
|
122
|
-
Promise.allSettled(ids.map(fetchOne))
|
|
123
|
-
.then(results => {
|
|
124
|
-
const retObj = {};
|
|
125
|
-
for (let i = 0; i < ids.length; i++) {
|
|
126
|
-
const nu = results[i].status === "fulfilled" ? results[i].value : null;
|
|
127
|
-
retObj[ids[i]] = toRetObjEntry(nu);
|
|
128
|
-
}
|
|
129
|
-
return callback(null, retObj);
|
|
130
|
-
})
|
|
131
|
-
.catch(err => { logger("getUserInfoV2" + err, "error"); callback(err); });
|
|
132
|
-
return returnPromise;
|
|
133
|
-
};
|
|
134
|
-
};
|
package/src/core/sendReqMqtt.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function sendReqMqtt(ctx, payload, options, callback) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const cb = typeof options === "function" ? options : callback;
|
|
6
|
-
const opts = typeof options === "object" && options ? options : {};
|
|
7
|
-
if (!ctx || !ctx.mqttClient) {
|
|
8
|
-
const err = new Error("Not connected to MQTT");
|
|
9
|
-
if (cb) cb(err);
|
|
10
|
-
return reject(err);
|
|
11
|
-
}
|
|
12
|
-
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
13
|
-
const reqID = typeof opts.request_id === "number" ? opts.request_id : ++ctx.wsReqNumber;
|
|
14
|
-
const timeoutMs = typeof opts.timeout === "number" ? opts.timeout : 20000;
|
|
15
|
-
const qos = typeof opts.qos === "number" ? opts.qos : 1;
|
|
16
|
-
const retain = !!opts.retain;
|
|
17
|
-
const reqTopic = "/ls_req";
|
|
18
|
-
const respTopic = opts.respTopic || "/ls_resp";
|
|
19
|
-
const form = JSON.stringify({
|
|
20
|
-
app_id: opts.app_id || "",
|
|
21
|
-
payload: typeof payload === "string" ? payload : JSON.stringify(payload),
|
|
22
|
-
request_id: reqID,
|
|
23
|
-
type: opts.type == null ? 3 : opts.type
|
|
24
|
-
});
|
|
25
|
-
let timer = null;
|
|
26
|
-
let cleaned = false;
|
|
27
|
-
|
|
28
|
-
// Cleanup function to ensure listeners and timers are always removed
|
|
29
|
-
const cleanup = () => {
|
|
30
|
-
if (cleaned) return;
|
|
31
|
-
cleaned = true;
|
|
32
|
-
try {
|
|
33
|
-
if (timer) {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
timer = null;
|
|
36
|
-
}
|
|
37
|
-
if (ctx.mqttClient && typeof ctx.mqttClient.removeListener === "function") {
|
|
38
|
-
ctx.mqttClient.removeListener("message", handleRes);
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
// Ignore cleanup errors
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const handleRes = (topic, message) => {
|
|
46
|
-
if (topic !== respTopic) return;
|
|
47
|
-
let msg;
|
|
48
|
-
try {
|
|
49
|
-
msg = JSON.parse(message.toString());
|
|
50
|
-
} catch {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (msg.request_id !== reqID) return;
|
|
54
|
-
if (typeof opts.filter === "function" && !opts.filter(msg)) return;
|
|
55
|
-
cleanup();
|
|
56
|
-
try {
|
|
57
|
-
msg.payload = typeof msg.payload === "string" ? JSON.parse(msg.payload) : msg.payload;
|
|
58
|
-
} catch { }
|
|
59
|
-
const out = { success: true, response: msg.payload, raw: msg };
|
|
60
|
-
if (cb) cb(null, out);
|
|
61
|
-
resolve(out);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
ctx.mqttClient.on("message", handleRes);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
cleanup();
|
|
68
|
-
const error = new Error("Failed to attach message listener");
|
|
69
|
-
if (cb) cb(error);
|
|
70
|
-
return reject(error);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
timer = setTimeout(() => {
|
|
74
|
-
cleanup();
|
|
75
|
-
const err = new Error("MQTT response timeout");
|
|
76
|
-
if (cb) cb(err);
|
|
77
|
-
reject(err);
|
|
78
|
-
}, timeoutMs);
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
ctx.mqttClient.publish(reqTopic, form, { qos, retain }, (err) => {
|
|
82
|
-
if (err) {
|
|
83
|
-
cleanup();
|
|
84
|
-
if (cb) cb(err);
|
|
85
|
-
reject(err);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
} catch (err) {
|
|
89
|
-
cleanup();
|
|
90
|
-
if (cb) cb(err);
|
|
91
|
-
reject(err);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
module.exports = sendReqMqtt;
|