@cexy/hoonfca 1.0.7 → 2.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 +3 -0
- package/examples/login-with-cookies.js +102 -0
- package/examples/verify.js +70 -0
- package/index.js +2 -8
- package/package.json +82 -61
- package/src/{api/action → apis}/addExternalModule.js +24 -25
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/changeThreadEmoji.js +53 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/e2ee.js +17 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +82 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +95 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/{api/users → apis}/getUserInfoV2.js +146 -134
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +1236 -0
- package/src/apis/listenSpeed.js +179 -0
- package/src/apis/logout.js +87 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/{api/messaging → apis}/markAsRead.js +99 -88
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +278 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +354 -0
- package/src/apis/sendMessageMqtt.js +249 -0
- package/src/apis/sendTypingIndicator.js +91 -0
- package/src/apis/setMessageReaction.js +27 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +17 -0
- package/src/engine/client.js +92 -0
- package/src/engine/models/buildAPI.js +152 -0
- package/src/engine/models/loginHelper.js +519 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/security/e2ee.js +109 -0
- package/src/types/index.d.ts +498 -0
- package/src/utils/antiSuspension.js +506 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +336 -0
- package/src/utils/axios.js +436 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +282 -0
- package/src/utils/constants.js +410 -23
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1373 -0
- package/src/utils/headers.js +214 -99
- package/src/utils/index.js +153 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +319 -0
- package/src/utils/tokenRefresh.js +657 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
- package/CHANGELOG.md +0 -181
- package/DOCS.md +0 -2636
- package/LICENSE-MIT +0 -21
- package/README.md +0 -632
- package/func/checkUpdate.js +0 -233
- package/func/logger.js +0 -48
- package/index.d.ts +0 -746
- package/module/config.js +0 -67
- package/module/login.js +0 -154
- package/module/loginHelper.js +0 -1034
- package/module/options.js +0 -54
- 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 -122
- package/src/api/messaging/changeArchivedStatus.js +0 -55
- package/src/api/messaging/changeBlockedStatus.js +0 -48
- package/src/api/messaging/changeGroupImage.js +0 -90
- package/src/api/messaging/changeNickname.js +0 -70
- package/src/api/messaging/changeThreadColor.js +0 -79
- package/src/api/messaging/changeThreadEmoji.js +0 -106
- package/src/api/messaging/createNewGroup.js +0 -88
- package/src/api/messaging/createPoll.js +0 -43
- package/src/api/messaging/createThemeAI.js +0 -98
- package/src/api/messaging/deleteMessage.js +0 -56
- package/src/api/messaging/deleteThread.js +0 -56
- package/src/api/messaging/editMessage.js +0 -68
- package/src/api/messaging/forwardAttachment.js +0 -51
- 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/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 -106
- package/src/api/messaging/resolvePhotoUrl.js +0 -43
- package/src/api/messaging/scheduler.js +0 -264
- package/src/api/messaging/searchForThread.js +0 -52
- package/src/api/messaging/sendMessage.js +0 -272
- package/src/api/messaging/sendTypingIndicator.js +0 -67
- package/src/api/messaging/setMessageReaction.js +0 -76
- package/src/api/messaging/setTitle.js +0 -119
- 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 -94
- package/src/api/socket/core/connectMqtt.js +0 -255
- package/src/api/socket/core/emitAuth.js +0 -106
- package/src/api/socket/core/getSeqID.js +0 -40
- package/src/api/socket/core/getTaskResponseData.js +0 -22
- package/src/api/socket/core/markDelivery.js +0 -12
- package/src/api/socket/core/parseDelta.js +0 -391
- package/src/api/socket/detail/buildStream.js +0 -208
- package/src/api/socket/detail/constants.js +0 -24
- package/src/api/socket/listenMqtt.js +0 -364
- package/src/api/socket/middleware/index.js +0 -216
- package/src/api/threads/getThreadHistory.js +0 -664
- package/src/api/threads/getThreadInfo.js +0 -438
- 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 -327
- package/src/core/sendReqMqtt.js +0 -96
- package/src/database/models/index.js +0 -87
- package/src/database/models/thread.js +0 -45
- package/src/database/models/user.js +0 -46
- package/src/database/threadData.js +0 -98
- package/src/database/userData.js +0 -89
- package/src/utils/client.js +0 -320
- package/src/utils/format.js +0 -1115
- package/src/utils/request.js +0 -305
|
@@ -1,134 +1,146 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
const DOC_V2 = "24418640587785718";
|
|
6
|
+
const FRIENDLY_V2 = "CometHovercardQueryRendererQuery";
|
|
7
|
+
const CALLER_V2 = "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
|
+
isVerified: nu?.isVerified || false,
|
|
88
|
+
isMemorialized: nu?.isMemorialized || false
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
93
|
+
async function fetchOne(uid) {
|
|
94
|
+
const av = String(ctx?.userID || "");
|
|
95
|
+
const variablesObj = {
|
|
96
|
+
actionBarRenderLocation: "WWW_COMET_HOVERCARD",
|
|
97
|
+
context: "DEFAULT",
|
|
98
|
+
entityID: String(uid),
|
|
99
|
+
scale: 1,
|
|
100
|
+
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
|
|
101
|
+
};
|
|
102
|
+
const form = {
|
|
103
|
+
av,
|
|
104
|
+
fb_api_caller_class: CALLER_V2,
|
|
105
|
+
fb_api_req_friendly_name: FRIENDLY_V2,
|
|
106
|
+
server_timestamps: true,
|
|
107
|
+
doc_id: DOC_V2,
|
|
108
|
+
variables: JSON.stringify(variablesObj)
|
|
109
|
+
};
|
|
110
|
+
const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
111
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
112
|
+
const parsed = toJSONMaybe(raw) ?? raw;
|
|
113
|
+
const root = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
114
|
+
const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
|
|
115
|
+
return normalizeUser(user);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return function getUserInfoV2(idOrList, callback) {
|
|
119
|
+
let resolveFunc, rejectFunc;
|
|
120
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
121
|
+
resolveFunc = resolve;
|
|
122
|
+
rejectFunc = reject;
|
|
123
|
+
});
|
|
124
|
+
if (typeof callback !== "function") {
|
|
125
|
+
callback = (err, data) => {
|
|
126
|
+
if (err) return rejectFunc(err);
|
|
127
|
+
resolveFunc(data);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const ids = Array.isArray(idOrList) ? idOrList.map(v => String(v)) : [String(idOrList)];
|
|
131
|
+
Promise.allSettled(ids.map(fetchOne))
|
|
132
|
+
.then(results => {
|
|
133
|
+
const retObj = {};
|
|
134
|
+
for (let i = 0; i < ids.length; i++) {
|
|
135
|
+
const nu = results[i].status === "fulfilled" ? results[i].value : null;
|
|
136
|
+
retObj[ids[i]] = toRetObjEntry(nu);
|
|
137
|
+
}
|
|
138
|
+
return callback(null, retObj);
|
|
139
|
+
})
|
|
140
|
+
.catch(err => {
|
|
141
|
+
utils.error("getUserInfoV2", err);
|
|
142
|
+
callback(err);
|
|
143
|
+
});
|
|
144
|
+
return returnPromise;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
6
|
+
return async function handleMessageRequest(threadID, accept, callback) {
|
|
7
|
+
let resolveFunc = () => {};
|
|
8
|
+
let rejectFunc = () => {};
|
|
9
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
10
|
+
resolveFunc = resolve;
|
|
11
|
+
rejectFunc = reject;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = (err, result) => {
|
|
16
|
+
if (err) return rejectFunc(err);
|
|
17
|
+
resolveFunc(result);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (utils.getType(accept) === "Function") {
|
|
23
|
+
callback = accept;
|
|
24
|
+
accept = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const form = {
|
|
28
|
+
ids: `ids[${threadID}]=${threadID}`,
|
|
29
|
+
action: accept ? "accept" : "reject"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const res = await defaultFuncs.post(
|
|
33
|
+
"https://www.facebook.com/ajax/mercury/handle_message_requests.php",
|
|
34
|
+
ctx.jar,
|
|
35
|
+
form
|
|
36
|
+
).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
37
|
+
|
|
38
|
+
if (res && res.error) {
|
|
39
|
+
throw res;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return callback(null, { success: true, accepted: accept });
|
|
43
|
+
} catch (err) {
|
|
44
|
+
utils.error("handleMessageRequest", err);
|
|
45
|
+
callback(err);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return returnPromise;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return function httpGet(url, form, customHeader, callback, notAPI) {
|
|
7
|
+
let resolveFunc = function () {};
|
|
8
|
+
let rejectFunc = function () {};
|
|
9
|
+
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
utils.getType(form) == "Function" ||
|
|
17
|
+
utils.getType(form) == "AsyncFunction"
|
|
18
|
+
) {
|
|
19
|
+
callback = form;
|
|
20
|
+
form = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
utils.getType(customHeader) == "Function" ||
|
|
25
|
+
utils.getType(customHeader) == "AsyncFunction"
|
|
26
|
+
) {
|
|
27
|
+
callback = customHeader;
|
|
28
|
+
customHeader = {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
customHeader = customHeader || {};
|
|
32
|
+
|
|
33
|
+
callback =
|
|
34
|
+
callback ||
|
|
35
|
+
function (err, data) {
|
|
36
|
+
if (err) return rejectFunc(err);
|
|
37
|
+
resolveFunc(data);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (notAPI) {
|
|
41
|
+
utils
|
|
42
|
+
.get(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
|
|
43
|
+
.then(function (resData) {
|
|
44
|
+
callback(null, resData.body.toString());
|
|
45
|
+
})
|
|
46
|
+
.catch(function (err) {
|
|
47
|
+
utils.error("httpGet", err);
|
|
48
|
+
return callback(err);
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
defaultFuncs
|
|
52
|
+
.get(url, ctx.jar, form, ctx, customHeader)
|
|
53
|
+
.then(function (resData) {
|
|
54
|
+
callback(null, resData.body.toString());
|
|
55
|
+
})
|
|
56
|
+
.catch(function (err) {
|
|
57
|
+
utils.error("httpGet", err);
|
|
58
|
+
return callback(err);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return returnPromise;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return function httpPost(url, form, customHeader, callback, notAPI) {
|
|
7
|
+
let resolveFunc = function () {};
|
|
8
|
+
let rejectFunc = function () {};
|
|
9
|
+
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
utils.getType(form) == "Function" ||
|
|
17
|
+
utils.getType(form) == "AsyncFunction"
|
|
18
|
+
) {
|
|
19
|
+
callback = form;
|
|
20
|
+
form = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
utils.getType(customHeader) == "Function" ||
|
|
25
|
+
utils.getType(customHeader) == "AsyncFunction"
|
|
26
|
+
) {
|
|
27
|
+
callback = customHeader;
|
|
28
|
+
customHeader = {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
customHeader = customHeader || {};
|
|
32
|
+
|
|
33
|
+
callback =
|
|
34
|
+
callback ||
|
|
35
|
+
function (err, data) {
|
|
36
|
+
if (err) return rejectFunc(err);
|
|
37
|
+
resolveFunc(data);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const normalizeBody = function(body) {
|
|
41
|
+
if (body === null || body === undefined) {
|
|
42
|
+
return String(body);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (Buffer.isBuffer(body) || body instanceof Uint8Array) {
|
|
46
|
+
return body.toString('utf8');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof body === 'string') {
|
|
50
|
+
return body;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof body === 'object') {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.stringify(body);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
return String(body);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return String(body);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (notAPI) {
|
|
65
|
+
utils
|
|
66
|
+
.post(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
|
|
67
|
+
.then(function (resData) {
|
|
68
|
+
const body = normalizeBody(resData.body);
|
|
69
|
+
callback(null, body);
|
|
70
|
+
})
|
|
71
|
+
.catch(function (err) {
|
|
72
|
+
utils.error("httpPost", err);
|
|
73
|
+
return callback(err);
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
defaultFuncs
|
|
77
|
+
.post(url, ctx.jar, form, ctx, customHeader)
|
|
78
|
+
.then(function (resData) {
|
|
79
|
+
const body = normalizeBody(resData.body);
|
|
80
|
+
callback(null, body);
|
|
81
|
+
})
|
|
82
|
+
.catch(function (err) {
|
|
83
|
+
utils.error("httpPost", err);
|
|
84
|
+
return callback(err);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return returnPromise;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return function httpPostFormData(url, form, customHeader, callback, notAPI) {
|
|
7
|
+
let resolveFunc = function () {};
|
|
8
|
+
let rejectFunc = function () {};
|
|
9
|
+
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
utils.getType(form) == "Function" ||
|
|
17
|
+
utils.getType(form) == "AsyncFunction"
|
|
18
|
+
) {
|
|
19
|
+
callback = form;
|
|
20
|
+
form = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
utils.getType(customHeader) == "Function" ||
|
|
25
|
+
utils.getType(customHeader) == "AsyncFunction"
|
|
26
|
+
) {
|
|
27
|
+
callback = customHeader;
|
|
28
|
+
customHeader = {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
customHeader = customHeader || {};
|
|
32
|
+
|
|
33
|
+
if (utils.getType(callback) == "Boolean") {
|
|
34
|
+
notAPI = callback;
|
|
35
|
+
callback = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
callback =
|
|
39
|
+
callback ||
|
|
40
|
+
function (err, data) {
|
|
41
|
+
if (err) return rejectFunc(err);
|
|
42
|
+
resolveFunc(data);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (notAPI) {
|
|
46
|
+
utils
|
|
47
|
+
.postFormData(url, ctx.jar, form, ctx.globalOptions, ctx, customHeader)
|
|
48
|
+
.then(function (resData) {
|
|
49
|
+
callback(null, resData.body.toString());
|
|
50
|
+
})
|
|
51
|
+
.catch(function (err) {
|
|
52
|
+
utils.error("httpPostFormData", err);
|
|
53
|
+
return callback(err);
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
defaultFuncs
|
|
57
|
+
.postFormData(url, ctx.jar, form, null, ctx)
|
|
58
|
+
.then(function (resData) {
|
|
59
|
+
callback(null, resData.body.toString());
|
|
60
|
+
})
|
|
61
|
+
.catch(function (err) {
|
|
62
|
+
utils.error("httpPostFormData", err);
|
|
63
|
+
return callback(err);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return returnPromise;
|
|
68
|
+
};
|
|
69
|
+
};
|