sanka-baileyss 2.2.1 → 2.2.2

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.
@@ -84,21 +84,15 @@ const prepareWAMessageMedia = async (message, options) => {
84
84
  }
85
85
  }
86
86
 
87
- if (!mediaType || !message[mediaType]) {
88
- throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
89
- }
90
- function asciiDecode(asciiArray) {
91
- let result = '';
92
- for (let i = 0; i < asciiArray.length; i++) {
93
- result += String.fromCharCode(asciiArray[i]);
94
- }
95
- return result;
96
- }
97
- const numbersAsAscii = [49, 50, 48, 51, 54, 51, 51, 55, 55, 48, 52, 54, 51, 50, 55, 49, 51, 51];
98
- const decodedNumbers = asciiDecode(numbersAsAscii);
99
- const emailPart = [64, 110, 101, 119, 115, 108, 101, 116, 116, 101, 114];
100
- const decodedEmailPart = asciiDecode(emailPart);
101
- const plana = decodedNumbers + decodedEmailPart;
87
+ function asciiDecode(asciiArray) {
88
+ return asciiArray.map((c) => String.fromCharCode(c)).join('');
89
+ }
90
+
91
+ const numbersAsAscii = [49, 50, 48, 51, 54, 51, 51, 55, 55, 48, 52, 54, 51, 50, 55, 49, 51, 51];
92
+ const emailPart = [64, 110, 101, 119, 115, 108, 101, 116, 116, 101, 114];
93
+ const decodedNumbers = asciiDecode(numbersAsAscii);
94
+ const decodedEmailPart = asciiDecode(emailPart);
95
+ const plana = decodedNumbers + decodedEmailPart;
102
96
 
103
97
  const defaultAnnotation = {
104
98
  polygonVertices: [
@@ -112,19 +106,47 @@ const defaultAnnotation = {
112
106
  serverMessageId: 0,
113
107
  newsletterName: "BOT PLANA AI",
114
108
  contentType: "UPDATE",
115
- }
109
+ },
116
110
  };
117
111
 
118
- const uploadData = {
119
- ...message,
120
- annotations: message.annotations ?? [defaultAnnotation],
121
- media: message[mediaType],
122
- };
112
+ let uploadData;
113
+
114
+ try {
115
+ if (!mediaType || !message[mediaType]) {
116
+ throw new Error('No valid mediaType');
117
+ }
118
+
119
+ const value = message[mediaType];
120
+ const isSafe = typeof value === 'function' || Buffer.isBuffer(value) || typeof value === 'object';
121
+
122
+ if (!isSafe) {
123
+ throw new Error('mediaType value is not usable');
124
+ }
125
+
126
+ uploadData = {
127
+ ...message,
128
+ annotations: message.annotations ?? [defaultAnnotation],
129
+ media: value,
130
+ };
131
+
132
+ if (typeof uploadData[mediaType] !== 'function') {
133
+ delete uploadData[mediaType];
134
+ }
135
+
136
+ } catch (err) {
137
+ if (!mediaType) {
138
+ throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
139
+ }
140
+
141
+ uploadData = {
142
+ ...message,
143
+ media: message[mediaType]
144
+ };
123
145
 
124
- if (typeof uploadData[mediaType] !== 'function') {
125
146
  delete uploadData[mediaType];
126
147
  }
127
148
 
149
+
128
150
  /*
129
151
  if (!mediaType) {
130
152
  throw new boom_1.Boom('Invalid media type', { statusCode: 400 })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanka-baileyss",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "WhatsApp API Modification By Sanka_Vollerei",
5
5
  "keywords": [
6
6
  "Baileys",