alicezetion 1.8.2 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"nonce":4096392210141617973,"last_updated":{"seconds":1696933677,"nanos":84190000}}
1
+ {"nonce":2843687609344956274,"last_updated":{"seconds":1696934066,"nanos":547808000}}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+
7
+ module.exports = function(defaultFuncs, api, ctx) {
8
+
9
+ return function httpPostFormData(url, form, callback) {
10
+ var resolveFunc = function(){};
11
+ var rejectFunc = function(){};
12
+
13
+ var returnPromise = new Promise(function (resolve, reject) {
14
+ resolveFunc = resolve;
15
+ rejectFunc = reject;
16
+ });
17
+
18
+ if (!callback && (utils.getType(form) == "Function" || utils.getType(form) == "AsyncFunction")) {
19
+ callback = form;
20
+ form = {};
21
+ }
22
+
23
+ form = form || {};
24
+
25
+ callback = callback || function(err, data) {
26
+ if (err) return rejectFunc(err);
27
+ resolveFunc(data);
28
+ };
29
+
30
+ defaultFuncs
31
+ .postFormData(url, ctx.jar, form)
32
+ .then(function(resData) {
33
+ callback(null, resData.body.toString());
34
+ })
35
+ .catch(function(err) {
36
+ log.error("httpPostFormData", err);
37
+ return callback(err);
38
+ });
39
+
40
+ return returnPromise;
41
+ };
42
+ };
@@ -0,0 +1,96 @@
1
+ const utils = require("../utils");
2
+ const log = require("npmlog");
3
+ const bluebird = require("bluebird");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ function upload(attachments, callback) {
7
+ callback = callback || function () { };
8
+ const uploads = [];
9
+
10
+ // create an array of promises
11
+ for (let i = 0; i < attachments.length; i++) {
12
+ if (!utils.isReadableStream(attachments[i])) {
13
+ throw {
14
+ error:
15
+ "Attachment should be a readable stream and not " +
16
+ utils.getType(attachments[i]) +
17
+ "."
18
+ };
19
+ }
20
+
21
+ const form = {
22
+ upload_1024: attachments[i],
23
+ voice_clip: "true"
24
+ };
25
+
26
+ uploads.push(
27
+ defaultFuncs
28
+ .postFormData(
29
+ "https://upload.facebook.com/ajax/mercury/upload.php",
30
+ ctx.jar,
31
+ form,
32
+ {}
33
+ )
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function (resData) {
36
+ if (resData.error) {
37
+ throw resData;
38
+ }
39
+
40
+ // We have to return the data unformatted unless we want to change it
41
+ // back in sendMessage.
42
+ return resData.payload.metadata[0];
43
+ })
44
+ );
45
+ }
46
+
47
+ // resolve all promises
48
+ bluebird
49
+ .all(uploads)
50
+ .then(function (resData) {
51
+ callback(null, resData);
52
+ })
53
+ .catch(function (err) {
54
+ log.error("uploadAttachment", err);
55
+ return callback(err);
56
+ });
57
+ }
58
+
59
+ return function uploadAttachment(attachments, callback) {
60
+ if (
61
+ !attachments &&
62
+ !utils.isReadableStream(attachments) &&
63
+ !utils.getType(attachments) === "Array" &&
64
+ (utils.getType(attachments) === "Array" && !attachments.length)
65
+ )
66
+ throw { error: "Please pass an attachment or an array of attachments." };
67
+
68
+ let resolveFunc = function () { };
69
+ let rejectFunc = function () { };
70
+ const returnPromise = new Promise(function (resolve, reject) {
71
+ resolveFunc = resolve;
72
+ rejectFunc = reject;
73
+ });
74
+
75
+ if (!callback) {
76
+ callback = function (err, info) {
77
+ if (err) {
78
+ return rejectFunc(err);
79
+ }
80
+ resolveFunc(info);
81
+ };
82
+ }
83
+
84
+ if (utils.getType(attachments) !== "Array")
85
+ attachments = [attachments];
86
+
87
+ upload(attachments, (err, info) => {
88
+ if (err) {
89
+ return callback(err);
90
+ }
91
+ callback(null, info);
92
+ });
93
+
94
+ return returnPromise;
95
+ };
96
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alicezetion",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "start": "node index.js"