fca-arif-babu 1.0.21 → 8.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 (152) hide show
  1. package/Extra/Balancer.js +49 -0
  2. package/Extra/Bypass/956/index.js +234 -0
  3. package/Extra/Bypass/test/aaaa.json +169 -0
  4. package/Extra/Bypass/test/index.js +188 -0
  5. package/Extra/Database/index.js +469 -0
  6. package/Extra/ExtraAddons.js +82 -0
  7. package/Extra/ExtraFindUID.js +62 -0
  8. package/Extra/ExtraGetThread.js +365 -0
  9. package/Extra/ExtraScreenShot.js +430 -0
  10. package/Extra/ExtraUptimeRobot.js +38 -0
  11. package/Extra/Html/Classic/script.js +119 -0
  12. package/Extra/Html/Classic/style.css +8 -0
  13. package/Extra/Security/AES_256_GCM/index.js +1 -0
  14. package/Extra/Security/Base/Step_1.js +6 -0
  15. package/Extra/Security/Base/Step_2.js +22 -0
  16. package/Extra/Security/Base/Step_3.js +22 -0
  17. package/Extra/Security/Base/index.js +191 -0
  18. package/Extra/Security/Step_1.js +6 -0
  19. package/Extra/Security/Step_2.js +22 -0
  20. package/Extra/Security/Step_3.js +22 -0
  21. package/Extra/Security/index.js +5 -0
  22. package/Extra/Src/Change_Environment.js +24 -0
  23. package/Extra/Src/Check_Update.js +67 -0
  24. package/Extra/Src/History.js +115 -0
  25. package/Extra/Src/Instant_Update.js +65 -0
  26. package/Extra/Src/Last-Run.js +65 -0
  27. package/Extra/Src/Premium.js +81 -0
  28. package/Extra/Src/Release_Memory.js +160 -0
  29. package/Extra/Src/Websocket.js +213 -0
  30. package/Extra/Src/image/62518eafb0670b697788ce4f9a4f71d1.jpg +0 -0
  31. package/Extra/Src/test.js +28 -0
  32. package/Extra/Src/uuid.js +137 -0
  33. package/Func/AcceptAgreement.js +31 -0
  34. package/Func/ClearCache.js +64 -0
  35. package/Func/ReportV1.js +54 -0
  36. package/{LICENSE-MIT → LICENSE.txt} +6 -6
  37. package/Language/index.json +228 -0
  38. package/Main.js +1290 -0
  39. package/README.md +8 -6
  40. package/SECURITY.md +17 -0
  41. package/broadcast.js +44 -0
  42. package/index.js +424 -465
  43. package/logger.js +66 -0
  44. package/package.json +91 -42
  45. package/src/Dev_Horizon_Data.js +125 -0
  46. package/src/Dev_getThreadInfoOLD.js +422 -0
  47. package/src/Dev_shareTest2.js +68 -0
  48. package/src/Dev_shareTest3.js +71 -0
  49. package/src/Premium.js +25 -0
  50. package/src/Screenshot.js +83 -0
  51. package/src/addExternalModule.js +5 -14
  52. package/src/addUserToGroup.js +21 -57
  53. package/src/changeAdminStatus.js +22 -46
  54. package/src/changeArchivedStatus.js +12 -26
  55. package/src/{changeAvatarV2.js → changeAvt.js} +2 -3
  56. package/src/changeBio.js +15 -26
  57. package/src/changeBlockedStatus.js +9 -22
  58. package/src/changeGroupImage.js +26 -55
  59. package/src/changeNickname.js +14 -28
  60. package/src/changeThreadColor.js +19 -22
  61. package/src/changeThreadEmoji.js +12 -25
  62. package/src/createNewGroup.js +18 -36
  63. package/src/createPoll.js +17 -28
  64. package/src/deleteMessage.js +14 -25
  65. package/src/deleteThread.js +13 -26
  66. package/src/editMessage.js +50 -56
  67. package/src/forwardAttachment.js +16 -28
  68. package/src/getAccessToken.js +28 -0
  69. package/src/getCurrentUserID.js +3 -3
  70. package/src/getEmojiUrl.js +8 -10
  71. package/src/getFriendsList.js +15 -25
  72. package/src/getMessage.js +81 -813
  73. package/src/getThreadHistory.js +98 -241
  74. package/src/getThreadInfo.js +286 -89
  75. package/src/getThreadInfoOLD.js +422 -0
  76. package/src/getThreadList.js +158 -215
  77. package/src/getThreadMain.js +220 -0
  78. package/src/getThreadPictures.js +20 -40
  79. package/src/getUID.js +49 -112
  80. package/src/getUserID.js +14 -18
  81. package/src/getUserInfo.js +75 -34
  82. package/src/getUserInfoMain.js +65 -0
  83. package/src/getUserInfoV2.js +32 -0
  84. package/src/getUserInfoV3.js +63 -0
  85. package/src/getUserInfoV4.js +55 -0
  86. package/src/getUserInfoV5.js +61 -0
  87. package/src/handleFriendRequest.js +14 -25
  88. package/src/handleMessageRequest.js +21 -37
  89. package/src/httpGet.js +22 -37
  90. package/src/httpPost.js +20 -36
  91. package/src/httpPostFormData.js +23 -52
  92. package/src/listenMqtt.js +667 -414
  93. package/src/listenMqttV1.js +846 -0
  94. package/src/logout.js +17 -24
  95. package/src/markAsDelivered.js +16 -23
  96. package/src/markAsRead.js +28 -43
  97. package/src/markAsReadAll.js +14 -21
  98. package/src/markAsSeen.js +19 -29
  99. package/src/muteThread.js +13 -18
  100. package/src/removeUserFromGroup.js +18 -48
  101. package/src/resolvePhotoUrl.js +14 -22
  102. package/src/searchForThread.js +13 -23
  103. package/src/sendMessage.js +125 -181
  104. package/src/sendMqttMessage.js +71 -0
  105. package/src/sendTypingIndicator.js +80 -28
  106. package/src/setMessageReaction.js +20 -33
  107. package/src/setPostReaction.js +95 -105
  108. package/src/setTitle.js +19 -35
  109. package/src/shareContact.js +37 -92
  110. package/src/shareLink.js +5 -6
  111. package/src/threadColors.js +17 -109
  112. package/src/unfriend.js +11 -20
  113. package/src/unsendMessage.js +33 -30
  114. package/src/unsendMqttMessage.js +66 -0
  115. package/test/data/shareAttach.js +146 -0
  116. package/test/data/something.mov +1 -0
  117. package/test/data/test.png +1 -0
  118. package/test/data/test.txt +1 -0
  119. package/test/env/.env +1 -0
  120. package/test/example-config.json +18 -0
  121. package/test/test-page.js +140 -0
  122. package/test/test.js +385 -0
  123. package/test/testv2.js +3 -0
  124. package/utils.js +2908 -1247
  125. package/replit.nix +0 -3
  126. package/src/changeAvatar.js +0 -136
  127. package/src/changeBlockedStatusMqtt.js +0 -80
  128. package/src/changeCover.js +0 -72
  129. package/src/changeName.js +0 -78
  130. package/src/changeUsername.js +0 -58
  131. package/src/createCommentPost.js +0 -229
  132. package/src/createPost.js +0 -275
  133. package/src/data/getThreadInfo.json +0 -1
  134. package/src/editMessageOld.js +0 -67
  135. package/src/follow.js +0 -74
  136. package/src/getAccess.js +0 -112
  137. package/src/getAvatarUser.js +0 -78
  138. package/src/getBotInitialData.js +0 -42
  139. package/src/getRegion.js +0 -7
  140. package/src/getThreadHistoryDeprecated.js +0 -93
  141. package/src/getThreadInfoDeprecated.js +0 -80
  142. package/src/getThreadListDeprecated.js +0 -75
  143. package/src/listenNotification.js +0 -85
  144. package/src/pinMessage.js +0 -59
  145. package/src/refreshFb_dtsg.js +0 -89
  146. package/src/searchStickers.js +0 -53
  147. package/src/sendMessageMqtt.js +0 -316
  148. package/src/setMessageReactionMqtt.js +0 -62
  149. package/src/setProfileGuard.js +0 -44
  150. package/src/setStoryReaction.js +0 -64
  151. package/src/stopListenMqtt.js +0 -23
  152. package/src/uploadAttachment.js +0 -94
@@ -1,316 +0,0 @@
1
- var utils = require("../utils");
2
-
3
- module.exports = function (defaultFuncs, api, ctx) {
4
- function uploadAttachment(attachments, callback) {
5
- callback = callback || function () {};
6
- var uploads = [];
7
-
8
- // create an array of promises
9
- for (var i = 0; i < attachments.length; i++) {
10
- if (!utils.isReadableStream(attachments[i])) {
11
- throw {
12
- error:
13
- "Attachment should be a readable stream and not " +
14
- utils.getType(attachments[i]) +
15
- ".",
16
- };
17
- }
18
-
19
- var form = {
20
- upload_1024: attachments[i],
21
- voice_clip: "true",
22
- };
23
-
24
- uploads.push(
25
- defaultFuncs
26
- .postFormData(
27
- "https://upload.facebook.com/ajax/mercury/upload.php",
28
- ctx.jar,
29
- form,
30
- {},
31
- )
32
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
33
- .then(function (resData) {
34
- if (resData.error) {
35
- throw resData;
36
- }
37
-
38
- // We have to return the data unformatted unless we want to change it
39
- // back in sendMessage.
40
- return resData.payload.metadata[0];
41
- }),
42
- );
43
- }
44
-
45
- // resolve all promises
46
- Promise.all(uploads)
47
- .then(function (resData) {
48
- callback(null, resData);
49
- })
50
- .catch(function (err) {
51
- console.error("uploadAttachment", err);
52
- return callback(err);
53
- });
54
- }
55
-
56
- let variance = 0;
57
- const epoch_id = () =>
58
- Math.floor(Date.now() * (4194304 + (variance = (variance + 0.1) % 5)));
59
- const emojiSizes = {
60
- small: 1,
61
- medium: 2,
62
- large: 3,
63
- };
64
-
65
- function handleEmoji(msg, form, callback, cb) {
66
- if (msg.emojiSize != null && msg.emoji == null) {
67
- return callback({ error: "emoji property is empty" });
68
- }
69
- if (msg.emoji) {
70
- if (!msg.emojiSize) {
71
- msg.emojiSize = "small";
72
- }
73
- if (
74
- msg.emojiSize !== "small" &&
75
- msg.emojiSize !== "medium" &&
76
- msg.emojiSize !== "large" &&
77
- (isNaN(msg.emojiSize) || msg.emojiSize < 1 || msg.emojiSize > 3)
78
- ) {
79
- return callback({ error: "emojiSize property is invalid" });
80
- }
81
-
82
- form.payload.tasks[0].payload.send_type = 1;
83
- form.payload.tasks[0].payload.text = msg.emoji;
84
- form.payload.tasks[0].payload.hot_emoji_size = !isNaN(msg.emojiSize)
85
- ? msg.emojiSize
86
- : emojiSizes[msg.emojiSize];
87
- }
88
- cb();
89
- }
90
-
91
- function handleSticker(msg, form, callback, cb) {
92
- if (msg.sticker) {
93
- form.payload.tasks[0].payload.send_type = 2;
94
- form.payload.tasks[0].payload.sticker_id = msg.sticker;
95
- }
96
- cb();
97
- }
98
-
99
- function handleAttachment(msg, form, callback, cb) {
100
- if (msg.attachment) {
101
- form.payload.tasks[0].payload.send_type = 3;
102
- form.payload.tasks[0].payload.attachment_fbids = [];
103
- if (form.payload.tasks[0].payload.text == "")
104
- form.payload.tasks[0].payload.text = null;
105
- if (utils.getType(msg.attachment) !== "Array") {
106
- msg.attachment = [msg.attachment];
107
- }
108
-
109
- uploadAttachment(msg.attachment, function (err, files) {
110
- if (err) {
111
- return callback(err);
112
- }
113
-
114
- files.forEach(function (file) {
115
- var key = Object.keys(file);
116
- var type = key[0]; // image_id, file_id, etc
117
- form.payload.tasks[0].payload.attachment_fbids.push(file[type]); // push the id
118
- });
119
- cb();
120
- });
121
- } else {
122
- cb();
123
- }
124
- }
125
-
126
- function handleMention(msg, form, callback, cb) {
127
- if (msg.mentions) {
128
- form.payload.tasks[0].payload.send_type = 1;
129
-
130
- const arrayIds = [];
131
- const arrayOffsets = [];
132
- const arrayLengths = [];
133
- const mention_types = [];
134
-
135
- for (let i = 0; i < msg.mentions.length; i++) {
136
- const mention = msg.mentions[i];
137
-
138
- const tag = mention.tag;
139
- if (typeof tag !== "string") {
140
- return callback({ error: "Mention tags must be strings." });
141
- }
142
-
143
- const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
144
-
145
- if (offset < 0) {
146
- console.warn(
147
- "handleMention",
148
- 'Mention for "' + tag + '" not found in message string.',
149
- );
150
- }
151
-
152
- if (mention.id == null) {
153
- console.warn("handleMention", "Mention id should be non-null.");
154
- }
155
-
156
- const id = mention.id || 0;
157
- arrayIds.push(id);
158
- arrayOffsets.push(offset);
159
- arrayLengths.push(tag.length);
160
- mention_types.push("p");
161
- }
162
-
163
- form.payload.tasks[0].payload.mention_data = {
164
- mention_ids: arrayIds.join(","),
165
- mention_offsets: arrayOffsets.join(","),
166
- mention_lengths: arrayLengths.join(","),
167
- mention_types: mention_types.join(","),
168
- };
169
- }
170
- cb();
171
- }
172
-
173
- function handleLocation(msg, form, callback, cb) {
174
- // this is not working yet
175
- if (msg.location) {
176
- if (msg.location.latitude == null || msg.location.longitude == null) {
177
- return callback({
178
- error: "location property needs both latitude and longitude",
179
- });
180
- }
181
-
182
- form.payload.tasks[0].payload.send_type = 1;
183
- form.payload.tasks[0].payload.location_data = {
184
- coordinates: {
185
- latitude: msg.location.latitude,
186
- longitude: msg.location.longitude,
187
- },
188
- is_current_location: !!msg.location.current,
189
- is_live_location: !!msg.location.live,
190
- };
191
- }
192
-
193
- cb();
194
- }
195
-
196
- function send(form, threadID, callback, replyToMessage) {
197
- if (replyToMessage) {
198
- form.payload.tasks[0].payload.reply_metadata = {
199
- reply_source_id: replyToMessage,
200
- reply_source_type: 1,
201
- reply_type: 0,
202
- };
203
- }
204
- const mqttClient = ctx.mqttClient;
205
- form.payload.tasks.forEach((task) => {
206
- task.payload = JSON.stringify(task.payload);
207
- });
208
- form.payload = JSON.stringify(form.payload);
209
- return mqttClient.publish(
210
- "/ls_req",
211
- JSON.stringify(form),
212
- function (err, data) {
213
- if (err) {
214
- console.error("Error publishing message: ", err);
215
- callback(err);
216
- } else {
217
- callback(null, data);
218
- }
219
- },
220
- );
221
- }
222
-
223
- return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
224
- if (
225
- !callback &&
226
- (utils.getType(threadID) === "Function" ||
227
- utils.getType(threadID) === "AsyncFunction")
228
- ) {
229
- return threadID({ error: "Pass a threadID as a second argument." });
230
- }
231
- if (!replyToMessage && utils.getType(callback) === "String") {
232
- replyToMessage = callback;
233
- callback = function () {};
234
- }
235
-
236
- if (!callback) {
237
- callback = function (err, friendList) {};
238
- }
239
-
240
- var msgType = utils.getType(msg);
241
- var threadIDType = utils.getType(threadID);
242
- var messageIDType = utils.getType(replyToMessage);
243
-
244
- if (msgType !== "String" && msgType !== "Object") {
245
- return callback({
246
- error:
247
- "Message should be of type string or object and not " + msgType + ".",
248
- });
249
- }
250
-
251
- if (msgType === "String") {
252
- msg = { body: msg };
253
- }
254
-
255
- const timestamp = Date.now();
256
- // get full date time
257
- const epoch = timestamp << 22;
258
- //const otid = epoch + 0; // TODO replace with randomInt(0, 2**22)
259
- const otid = epoch + Math.floor(Math.random() * 4194304);
260
-
261
- const form = {
262
- app_id: "2220391788200892",
263
- payload: {
264
- tasks: [
265
- {
266
- label: "46",
267
- payload: {
268
- thread_id: threadID.toString(),
269
- otid: otid.toString(),
270
- source: 0,
271
- send_type: 1,
272
- sync_group: 1,
273
- text:
274
- msg.body != null && msg.body != undefined
275
- ? msg.body.toString()
276
- : "",
277
- initiating_source: 1,
278
- skip_url_preview_gen: 0,
279
- },
280
- queue_name: threadID.toString(),
281
- task_id: 0,
282
- failure_count: null,
283
- },
284
- {
285
- label: "21",
286
- payload: {
287
- thread_id: threadID.toString(),
288
- last_read_watermark_ts: Date.now(),
289
- sync_group: 1,
290
- },
291
- queue_name: threadID.toString(),
292
- task_id: 1,
293
- failure_count: null,
294
- },
295
- ],
296
- epoch_id: epoch_id(),
297
- version_id: "6120284488008082",
298
- data_trace_id: null,
299
- },
300
- request_id: 1,
301
- type: 3,
302
- };
303
-
304
- handleEmoji(msg, form, callback, function () {
305
- handleLocation(msg, form, callback, function () {
306
- handleMention(msg, form, callback, function () {
307
- handleSticker(msg, form, callback, function () {
308
- handleAttachment(msg, form, callback, function () {
309
- send(form, threadID, callback, replyToMessage);
310
- });
311
- });
312
- });
313
- });
314
- });
315
- };
316
- };
@@ -1,62 +0,0 @@
1
-
2
- 'use strict';
3
-
4
- const { generateOfflineThreadingID } = require('../utils');
5
-
6
- function isCallable(func) {
7
- try {
8
- Reflect.apply(func, null, []);
9
- return true;
10
- } catch (error) {
11
- return false;
12
- }
13
- }
14
-
15
- module.exports = function (defaultFuncs, api, ctx) {
16
- return function setMessageReactionMqtt(reaction, messageID, threadID, callback) {
17
- if (!ctx.mqttClient) {
18
- throw new Error('Not connected to MQTT');
19
- }
20
-
21
-
22
- ctx.wsReqNumber += 1;
23
- ctx.wsTaskNumber += 1;
24
-
25
- const taskPayload = {
26
- thread_key: threadID,
27
- timestamp_ms: Date.now(),
28
- message_id: messageID,
29
- reaction: reaction,
30
- actor_id: ctx.userID,
31
- reaction_style: null,
32
- sync_group: 1,
33
- send_attribution: Math.random() < 0.5 ? 65537 : 524289
34
- };
35
-
36
- const task = {
37
- failure_count: null,
38
- label: '29',
39
- payload: JSON.stringify(taskPayload),
40
- queue_name: JSON.stringify(['reaction', messageID]),
41
- task_id: ctx.wsTaskNumber,
42
- };
43
-
44
- const content = {
45
- app_id: '2220391788200892',
46
- payload: JSON.stringify({
47
- data_trace_id: null,
48
- epoch_id: parseInt(generateOfflineThreadingID()),
49
- tasks: [task],
50
- version_id: '7158486590867448',
51
- }),
52
- request_id: ctx.wsReqNumber,
53
- type: 3,
54
- };
55
-
56
- if (isCallable(callback)) {
57
- ctx.reqCallbacks[ctx.wsReqNumber] = callback;
58
- }
59
-
60
- ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
61
- };
62
- };
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- // @NethWs3Dev
5
- module.exports = (defaultFuncs, api, ctx) => {
6
- return (guard, callback = () => {}) => {
7
- if (utils.getType(guard) !== "Boolean") {
8
- throw {
9
- error: "Please pass a boolean as a second argument.",
10
- };
11
- }
12
- const uid = ctx.userID;
13
- const form = {
14
- av: uid,
15
- variables: JSON.stringify({
16
- input: {
17
- is_shielded: guard ? true : false,
18
- actor_id: uid,
19
- client_mutation_id: "1"
20
- },
21
- scale: 1
22
- }),
23
- doc_id: "1477043292367183",
24
- fb_api_req_friendly_name: "IsShieldedSetMutation",
25
- fb_api_caller_class: "IsShieldedSetMutation"
26
- }
27
-
28
- return defaultFuncs
29
- .post("https://www.facebook.com/api/graphql", ctx.jar, form)
30
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
31
- .then(function(resData) {
32
- if (resData.err) {
33
- throw {
34
- err: resData.err
35
- };
36
- }
37
- return callback();
38
- })
39
- .catch(err => {
40
- console.error("setProfileGuard", err);
41
- return callback(err);
42
- });;
43
- };
44
- };
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('../utils.js');
4
- var log = require('npmlog');
5
-
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function setStoryReaction(storyID, react, callback) {
8
- var cb;
9
- var returnPromise = new Promise(function(resolve, reject) {
10
- cb = error => error ? reject(error) : resolve();
11
- });
12
-
13
- if (typeof react == 'function') {
14
- callback = react;
15
- react = 1;
16
- }
17
- if (typeof callback == 'function') cb = callback;
18
- if (typeof Number(react) != 'number') react = 1;
19
-
20
- var map = {
21
- 1: '👍',
22
- 2: '❤️',
23
- 3: '🤗',
24
- 4: '😆',
25
- 5: '😮',
26
- 6: '😢',
27
- 7: '😡'
28
- }
29
- var form = {
30
- fb_api_req_friendly_name: 'useStoriesSendReplyMutation',
31
- variables: JSON.stringify({
32
- input: {
33
- attribution_id_v2: `StoriesCometSuspenseRoot.react,comet.stories.viewer,unexpected,${Date.now()},538296,,;CometHomeRoot.react,comet.home,via_cold_start,${Date.now()},850302,4748854339,`,
34
- lightweight_reaction_actions: {
35
- offsets: [0],
36
- reaction: map[react] || map[1]
37
- },
38
- message: map[react] || map[1],
39
- story_id: storyID,
40
- story_reply_type: "LIGHT_WEIGHT",
41
- actor_id: ctx.userID,
42
- client_mutation_id: String(parseInt(Math.random() * 16))
43
- }
44
- }),
45
- doc_id: '4826141330837571'
46
- }
47
-
48
- defaultFuncs
49
- .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
50
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
- .then(function(res) {
52
- if (res.errors) throw res;
53
- return cb();
54
- })
55
- .catch(function(err) {
56
- console.error('setPostReaction', err);
57
- return cb(err);
58
- });
59
-
60
- return returnPromise;
61
- }
62
- }
63
-
64
- //new update version 1.0.9
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- /*
4
- @NethWs3Dev
5
- */
6
-
7
- // @NethWs3Dev
8
- module.exports = function (defaultFuncs, api, ctx){
9
- return function stopListenMqtt() {
10
- if (!ctx.mqttClient) {
11
- throw new Error("Not connected to MQTT");
12
- }
13
- console.log("stopListenMqtt", "Stopping...");
14
- ctx.mqttClient.unsubscribe("/webrtc");
15
- ctx.mqttClient.unsubscribe("/rtc_multi");
16
- ctx.mqttClient.unsubscribe("/onevc");
17
- ctx.mqttClient.publish("/browser_close", "{}");
18
- ctx.mqttClient.end(false, (...data) => {
19
- console.log("stopListenMqtt", "Stopped");
20
- ctx.mqttClient = null;
21
- });
22
- }
23
- };
@@ -1,94 +0,0 @@
1
- const utils = require("../utils");
2
- // @NethWs3Dev
3
-
4
- module.exports = function (defaultFuncs, api, ctx) {
5
- function upload(attachments, callback) {
6
- callback = callback || function () {};
7
- const uploads = [];
8
-
9
- // create an array of promises
10
- for (let i = 0; i < attachments.length; i++) {
11
- if (!utils.isReadableStream(attachments[i])) {
12
- throw {
13
- error:
14
- "Attachment should be a readable stream and not " +
15
- utils.getType(attachments[i]) +
16
- ".",
17
- };
18
- }
19
-
20
- const form = {
21
- upload_1024: attachments[i],
22
- voice_clip: "true",
23
- };
24
-
25
- uploads.push(
26
- defaultFuncs
27
- .postFormData(
28
- "https://upload.facebook.com/ajax/mercury/upload.php",
29
- ctx.jar,
30
- form,
31
- {},
32
- )
33
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
- .then(function (resData) {
35
- if (resData.error) {
36
- throw resData;
37
- }
38
-
39
- // We have to return the data unformatted unless we want to change it
40
- // back in sendMessage.
41
- return resData.payload.metadata[0];
42
- }),
43
- );
44
- }
45
-
46
- // resolve all promises
47
- Promise.all(uploads)
48
- .then(function (resData) {
49
- callback(null, resData);
50
- })
51
- .catch(function (err) {
52
- console.error("uploadAttachment", err);
53
- return callback(err);
54
- });
55
- }
56
-
57
- return function uploadAttachment(attachments, callback) {
58
- if (
59
- !attachments &&
60
- !utils.isReadableStream(attachments) &&
61
- !utils.getType(attachments) === "Array" &&
62
- utils.getType(attachments) === "Array" &&
63
- !attachments.length
64
- )
65
- throw { error: "Please pass an attachment or an array of attachments." };
66
-
67
- let resolveFunc = function () {};
68
- let rejectFunc = function () {};
69
- const returnPromise = new Promise(function (resolve, reject) {
70
- resolveFunc = resolve;
71
- rejectFunc = reject;
72
- });
73
-
74
- if (!callback) {
75
- callback = function (err, info) {
76
- if (err) {
77
- return rejectFunc(err);
78
- }
79
- resolveFunc(info);
80
- };
81
- }
82
-
83
- if (utils.getType(attachments) !== "Array") attachments = [attachments];
84
-
85
- upload(attachments, (err, info) => {
86
- if (err) {
87
- return callback(err);
88
- }
89
- callback(null, info);
90
- });
91
-
92
- return returnPromise;
93
- };
94
- };