@wppconnect-team/wppconnect 1.41.3 → 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/CHANGELOG.md +12 -0
- package/dist/api/helpers/base64-mimetype.js +2 -2
- package/dist/api/helpers/decrypt.js +65 -72
- package/dist/api/helpers/download-file.js +31 -81
- package/dist/api/helpers/evaluate-and-return.js +98 -93
- package/dist/api/helpers/exposed.enum.d.ts +2 -1
- package/dist/api/helpers/exposed.enum.js +1 -0
- package/dist/api/helpers/file-to-base64.js +30 -81
- package/dist/api/helpers/filename-from-mimetype.js +4 -4
- package/dist/api/helpers/scrape-img-qr.js +37 -86
- package/dist/api/helpers/scrape-login.js +12 -57
- package/dist/api/helpers/select-sticker.js +35 -100
- package/dist/api/layers/business.layer.js +29 -134
- package/dist/api/layers/catalog.layer.js +59 -210
- package/dist/api/layers/community.layer.js +29 -120
- package/dist/api/layers/controls.layer.js +62 -262
- package/dist/api/layers/group.layer.js +126 -391
- package/dist/api/layers/host.layer.js +348 -702
- package/dist/api/layers/labels.layer.js +35 -131
- package/dist/api/layers/listener.layer.d.ts +9 -1
- package/dist/api/layers/listener.layer.js +392 -491
- package/dist/api/layers/newsletter.layer.js +20 -89
- package/dist/api/layers/profile.layer.js +73 -184
- package/dist/api/layers/retriever.layer.js +163 -468
- package/dist/api/layers/sender.layer.js +554 -1094
- package/dist/api/layers/status.layer.js +80 -179
- package/dist/api/layers/ui.layer.js +32 -129
- package/dist/api/model/enum/definitions.js +1 -1
- package/dist/api/whatsapp.js +200 -426
- package/dist/config/WAuserAgente.js +1 -1
- package/dist/config/create-config.js +1 -1
- package/dist/config/puppeteer.config.js +1 -1
- package/dist/controllers/auth.js +42 -110
- package/dist/controllers/browser.js +251 -411
- package/dist/controllers/initializer.js +171 -265
- package/dist/controllers/websocket.js +29 -28
- package/dist/controllers/welcome.js +38 -88
- package/dist/lib/wapi/wapi.js +1 -1
- package/dist/token-store/fileTokenStore.js +83 -173
- package/dist/token-store/isValidSessionToken.js +2 -2
- package/dist/token-store/isValidTokenStore.js +2 -2
- package/dist/token-store/memoryTokenStore.js +11 -14
- package/dist/utils/ffmpeg.js +75 -131
- package/dist/utils/logger.js +5 -5
- package/dist/utils/semver.js +6 -6
- package/dist/utils/sleep.js +1 -1
- package/package.json +8 -8
|
@@ -32,42 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
72
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
37
|
};
|
|
@@ -90,11 +54,11 @@ exports.FileTokenStore = exports.defaultFileTokenStoreOptions = void 0;
|
|
|
90
54
|
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
91
55
|
*/
|
|
92
56
|
/// <reference types="node" />
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
const fs = __importStar(require("fs"));
|
|
58
|
+
const path = __importStar(require("path"));
|
|
59
|
+
const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
|
|
60
|
+
const logger_1 = require("../utils/logger");
|
|
61
|
+
const isValidSessionToken_1 = require("./isValidSessionToken");
|
|
98
62
|
exports.defaultFileTokenStoreOptions = {
|
|
99
63
|
decodeFunction: JSON.parse,
|
|
100
64
|
encodeFunction: JSON.stringify,
|
|
@@ -128,9 +92,9 @@ exports.defaultFileTokenStoreOptions = {
|
|
|
128
92
|
* });
|
|
129
93
|
* ```
|
|
130
94
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
95
|
+
class FileTokenStore {
|
|
96
|
+
options;
|
|
97
|
+
constructor(options = {}) {
|
|
134
98
|
this.options = Object.assign({}, exports.defaultFileTokenStoreOptions, options);
|
|
135
99
|
}
|
|
136
100
|
/**
|
|
@@ -138,135 +102,81 @@ var FileTokenStore = /** @class */ (function () {
|
|
|
138
102
|
* @param sessionName Name of session
|
|
139
103
|
* @returns Full path of token file
|
|
140
104
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
105
|
+
resolverPath(sessionName) {
|
|
106
|
+
const filename = (0, sanitize_filename_1.default)(sessionName) + this.options.fileExtension;
|
|
143
107
|
return path.resolve(process.cwd(), path.join(this.options.path, filename));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
-
var filePath, text, error_1;
|
|
180
|
-
return __generator(this, function (_a) {
|
|
181
|
-
switch (_a.label) {
|
|
182
|
-
case 0:
|
|
183
|
-
if (!tokenData || !(0, isValidSessionToken_1.isValidSessionToken)(tokenData)) {
|
|
184
|
-
return [2 /*return*/, false];
|
|
185
|
-
}
|
|
186
|
-
if (!!fs.existsSync(this.options.path)) return [3 /*break*/, 2];
|
|
187
|
-
return [4 /*yield*/, fs.promises.mkdir(this.options.path, { recursive: true })];
|
|
188
|
-
case 1:
|
|
189
|
-
_a.sent();
|
|
190
|
-
_a.label = 2;
|
|
191
|
-
case 2:
|
|
192
|
-
filePath = this.resolverPath(sessionName);
|
|
193
|
-
_a.label = 3;
|
|
194
|
-
case 3:
|
|
195
|
-
_a.trys.push([3, 5, , 6]);
|
|
196
|
-
text = this.options.encodeFunction(tokenData);
|
|
197
|
-
return [4 /*yield*/, fs.promises.writeFile(filePath, text, {
|
|
198
|
-
encoding: this.options.encoding,
|
|
199
|
-
})];
|
|
200
|
-
case 4:
|
|
201
|
-
_a.sent();
|
|
202
|
-
return [2 /*return*/, true];
|
|
203
|
-
case 5:
|
|
204
|
-
error_1 = _a.sent();
|
|
205
|
-
logger_1.defaultLogger.debug(error_1);
|
|
206
|
-
return [2 /*return*/, false];
|
|
207
|
-
case 6: return [2 /*return*/];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
FileTokenStore.prototype.removeToken = function (sessionName) {
|
|
213
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
-
var filePath, error_2;
|
|
215
|
-
return __generator(this, function (_a) {
|
|
216
|
-
switch (_a.label) {
|
|
217
|
-
case 0:
|
|
218
|
-
filePath = this.resolverPath(sessionName);
|
|
219
|
-
if (!fs.existsSync(filePath)) {
|
|
220
|
-
return [2 /*return*/, false];
|
|
221
|
-
}
|
|
222
|
-
_a.label = 1;
|
|
223
|
-
case 1:
|
|
224
|
-
_a.trys.push([1, 3, , 4]);
|
|
225
|
-
return [4 /*yield*/, fs.promises.unlink(filePath)];
|
|
226
|
-
case 2:
|
|
227
|
-
_a.sent();
|
|
228
|
-
return [2 /*return*/, true];
|
|
229
|
-
case 3:
|
|
230
|
-
error_2 = _a.sent();
|
|
231
|
-
logger_1.defaultLogger.debug(error_2);
|
|
232
|
-
return [2 /*return*/, false];
|
|
233
|
-
case 4: return [2 /*return*/];
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
FileTokenStore.prototype.listTokens = function () {
|
|
239
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
-
var files, error_3;
|
|
241
|
-
var _this = this;
|
|
242
|
-
return __generator(this, function (_a) {
|
|
243
|
-
switch (_a.label) {
|
|
244
|
-
case 0:
|
|
245
|
-
if (!fs.existsSync(this.options.path)) {
|
|
246
|
-
return [2 /*return*/, []];
|
|
247
|
-
}
|
|
248
|
-
_a.label = 1;
|
|
249
|
-
case 1:
|
|
250
|
-
_a.trys.push([1, 3, , 4]);
|
|
251
|
-
return [4 /*yield*/, fs.promises.readdir(this.options.path)];
|
|
252
|
-
case 2:
|
|
253
|
-
files = _a.sent();
|
|
254
|
-
// Only sessions with same fileExtension
|
|
255
|
-
files = files.filter(function (file) { return file.endsWith(_this.options.fileExtension); });
|
|
256
|
-
// Return name only
|
|
257
|
-
files = files.map(function (file) {
|
|
258
|
-
return path.basename(file, _this.options.fileExtension);
|
|
259
|
-
});
|
|
260
|
-
return [2 /*return*/, files];
|
|
261
|
-
case 3:
|
|
262
|
-
error_3 = _a.sent();
|
|
263
|
-
logger_1.defaultLogger.debug(error_3);
|
|
264
|
-
return [2 /*return*/, []];
|
|
265
|
-
case 4: return [2 /*return*/];
|
|
266
|
-
}
|
|
108
|
+
}
|
|
109
|
+
async getToken(sessionName) {
|
|
110
|
+
const filePath = this.resolverPath(sessionName);
|
|
111
|
+
if (!fs.existsSync(filePath)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const text = await fs.promises
|
|
115
|
+
.readFile(filePath, {
|
|
116
|
+
encoding: this.options.encoding,
|
|
117
|
+
})
|
|
118
|
+
.catch(() => null);
|
|
119
|
+
if (!text) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return this.options.decodeFunction(text);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
logger_1.defaultLogger.debug(error);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async setToken(sessionName, tokenData) {
|
|
131
|
+
if (!tokenData || !(0, isValidSessionToken_1.isValidSessionToken)(tokenData)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
if (!fs.existsSync(this.options.path)) {
|
|
135
|
+
await fs.promises.mkdir(this.options.path, { recursive: true });
|
|
136
|
+
}
|
|
137
|
+
const filePath = this.resolverPath(sessionName);
|
|
138
|
+
try {
|
|
139
|
+
const text = this.options.encodeFunction(tokenData);
|
|
140
|
+
await fs.promises.writeFile(filePath, text, {
|
|
141
|
+
encoding: this.options.encoding,
|
|
267
142
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
logger_1.defaultLogger.debug(error);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async removeToken(sessionName) {
|
|
151
|
+
const filePath = this.resolverPath(sessionName);
|
|
152
|
+
if (!fs.existsSync(filePath)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
await fs.promises.unlink(filePath);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
logger_1.defaultLogger.debug(error);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async listTokens() {
|
|
165
|
+
if (!fs.existsSync(this.options.path)) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
let files = await fs.promises.readdir(this.options.path);
|
|
170
|
+
// Only sessions with same fileExtension
|
|
171
|
+
files = files.filter((file) => file.endsWith(this.options.fileExtension));
|
|
172
|
+
// Return name only
|
|
173
|
+
files = files.map((file) => path.basename(file, this.options.fileExtension));
|
|
174
|
+
return files;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
logger_1.defaultLogger.debug(error);
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
272
182
|
exports.FileTokenStore = FileTokenStore;
|
|
@@ -7,12 +7,12 @@ exports.isValidSessionToken = isValidSessionToken;
|
|
|
7
7
|
* @returns Token is valid
|
|
8
8
|
*/
|
|
9
9
|
function isValidSessionToken(token) {
|
|
10
|
-
|
|
10
|
+
const requiredAttribbutes = [
|
|
11
11
|
'WABrowserId',
|
|
12
12
|
'WASecretBundle',
|
|
13
13
|
'WAToken1',
|
|
14
14
|
'WAToken2',
|
|
15
15
|
];
|
|
16
16
|
return (token &&
|
|
17
|
-
requiredAttribbutes.every(
|
|
17
|
+
requiredAttribbutes.every((attr) => typeof token[attr] === 'string' && token[attr].length > 0));
|
|
18
18
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isValidTokenStore = isValidTokenStore;
|
|
4
|
-
|
|
4
|
+
const keys = ['getToken', 'setToken', 'removeToken', 'listTokens'];
|
|
5
5
|
/**
|
|
6
6
|
* Check and validate if the object implements the TokenStore interface
|
|
7
7
|
* @param object Object to check that implements the TokenStore interface
|
|
8
8
|
* @returns true if the object is a valid else false
|
|
9
9
|
*/
|
|
10
10
|
function isValidTokenStore(object) {
|
|
11
|
-
return keys.every(
|
|
11
|
+
return keys.every((k) => k in object && typeof object[k] === 'function');
|
|
12
12
|
}
|
|
@@ -21,27 +21,24 @@ exports.MemoryTokenStore = void 0;
|
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
MemoryTokenStore.prototype.getToken = function (sessionName) {
|
|
24
|
+
class MemoryTokenStore {
|
|
25
|
+
tokens = {};
|
|
26
|
+
getToken(sessionName) {
|
|
29
27
|
return this.tokens[sessionName];
|
|
30
|
-
}
|
|
31
|
-
|
|
28
|
+
}
|
|
29
|
+
setToken(sessionName, tokenData) {
|
|
32
30
|
if (!tokenData) {
|
|
33
31
|
return false;
|
|
34
32
|
}
|
|
35
33
|
this.tokens[sessionName] = tokenData;
|
|
36
34
|
return true;
|
|
37
|
-
}
|
|
38
|
-
|
|
35
|
+
}
|
|
36
|
+
removeToken(sessionName) {
|
|
39
37
|
delete this.tokens[sessionName];
|
|
40
38
|
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
39
|
+
}
|
|
40
|
+
listTokens() {
|
|
43
41
|
return Object.keys(this.tokens);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
47
44
|
exports.MemoryTokenStore = MemoryTokenStore;
|
package/dist/utils/ffmpeg.js
CHANGED
|
@@ -32,42 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
72
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
37
|
};
|
|
@@ -90,15 +54,15 @@ exports.convertToMP4GIF = convertToMP4GIF;
|
|
|
90
54
|
* You should have received a copy of the GNU Lesser General Public License
|
|
91
55
|
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
92
56
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
process.on('exit',
|
|
57
|
+
const execa_1 = __importDefault(require("execa"));
|
|
58
|
+
const fs = __importStar(require("fs"));
|
|
59
|
+
const path = __importStar(require("path"));
|
|
60
|
+
const rimraf_1 = __importDefault(require("rimraf"));
|
|
61
|
+
const tmp = __importStar(require("tmp"));
|
|
62
|
+
const lookpath_1 = require("lookpath");
|
|
63
|
+
const tmpDir = tmp.dirSync({});
|
|
64
|
+
let i = 0;
|
|
65
|
+
process.on('exit', () => {
|
|
102
66
|
// Remove only on exit signal
|
|
103
67
|
try {
|
|
104
68
|
// Use rimraf because it is synchronous
|
|
@@ -106,97 +70,77 @@ process.on('exit', function () {
|
|
|
106
70
|
}
|
|
107
71
|
catch (error) { }
|
|
108
72
|
});
|
|
109
|
-
function getFfmpegPath() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
case 2: return [4 /*yield*/, (0, lookpath_1.lookpath)('ffmpeg', {
|
|
128
|
-
include: [
|
|
129
|
-
'C:\\FFmpeg\\bin',
|
|
130
|
-
'C:\\FFmpeg\\FFmpeg\\bin',
|
|
131
|
-
'C:\\Program Files\\ffmpeg\\bin',
|
|
132
|
-
'C:\\Program Files (x86)\\ffmpeg\\bin',
|
|
133
|
-
],
|
|
134
|
-
})];
|
|
135
|
-
case 3:
|
|
136
|
-
ffmpegPath = _a.sent();
|
|
137
|
-
if (!ffmpegPath) {
|
|
138
|
-
try {
|
|
139
|
-
ffmpegPath = require('ffmpeg-static');
|
|
140
|
-
}
|
|
141
|
-
catch (error) { }
|
|
142
|
-
}
|
|
143
|
-
if (!ffmpegPath) {
|
|
144
|
-
throw new Error('Error: FFMPEG not found. Please install ffmpeg or define the env FFMPEG_PATH or install ffmpeg-static');
|
|
145
|
-
}
|
|
146
|
-
return [2 /*return*/, ffmpegPath];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
73
|
+
async function getFfmpegPath() {
|
|
74
|
+
let ffmpegPath = process.env['FFMPEG_PATH'];
|
|
75
|
+
if (ffmpegPath) {
|
|
76
|
+
const isExecutable = await fs.promises
|
|
77
|
+
.access(ffmpegPath, fs.constants.X_OK)
|
|
78
|
+
.then(() => true)
|
|
79
|
+
.catch(() => false);
|
|
80
|
+
if (isExecutable) {
|
|
81
|
+
return ffmpegPath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
ffmpegPath = await (0, lookpath_1.lookpath)('ffmpeg', {
|
|
85
|
+
include: [
|
|
86
|
+
'C:\\FFmpeg\\bin',
|
|
87
|
+
'C:\\FFmpeg\\FFmpeg\\bin',
|
|
88
|
+
'C:\\Program Files\\ffmpeg\\bin',
|
|
89
|
+
'C:\\Program Files (x86)\\ffmpeg\\bin',
|
|
90
|
+
],
|
|
149
91
|
});
|
|
92
|
+
if (!ffmpegPath) {
|
|
93
|
+
try {
|
|
94
|
+
ffmpegPath = require('ffmpeg-static');
|
|
95
|
+
}
|
|
96
|
+
catch (error) { }
|
|
97
|
+
}
|
|
98
|
+
if (!ffmpegPath) {
|
|
99
|
+
throw new Error('Error: FFMPEG not found. Please install ffmpeg or define the env FFMPEG_PATH or install ffmpeg-static');
|
|
100
|
+
}
|
|
101
|
+
return ffmpegPath;
|
|
150
102
|
}
|
|
151
103
|
/**
|
|
152
104
|
* Convert a file to a compatible MP4-GIF for WhatsApp
|
|
153
105
|
* @param inputBase64 Gif in base64 format
|
|
154
106
|
* @returns base64 of a MP4-GIF for WhatsApp
|
|
155
107
|
*/
|
|
156
|
-
function convertToMP4GIF(inputBase64) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
case 4:
|
|
195
|
-
(0, rimraf_1.default)(inputPath, function () { return null; });
|
|
196
|
-
(0, rimraf_1.default)(outputPath, function () { return null; });
|
|
197
|
-
return [7 /*endfinally*/];
|
|
198
|
-
case 5: return [2 /*return*/, ''];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
108
|
+
async function convertToMP4GIF(inputBase64) {
|
|
109
|
+
const inputPath = path.join(tmpDir.name, `${i++}`);
|
|
110
|
+
const outputPath = path.join(tmpDir.name, `${i++}.mp4`);
|
|
111
|
+
if (inputBase64.includes(',')) {
|
|
112
|
+
inputBase64 = inputBase64.split(',')[1];
|
|
113
|
+
}
|
|
114
|
+
fs.writeFileSync(inputPath, Buffer.from(inputBase64, 'base64'));
|
|
115
|
+
/**
|
|
116
|
+
* fluent-ffmpeg is a good alternative,
|
|
117
|
+
* but to work with MP4 you must use fisical file or ffmpeg will not work
|
|
118
|
+
* Because of that, I made the choice to use temporary file
|
|
119
|
+
*/
|
|
120
|
+
const ffmpegPath = await getFfmpegPath();
|
|
121
|
+
try {
|
|
122
|
+
const out = await (0, execa_1.default)(ffmpegPath, [
|
|
123
|
+
'-i',
|
|
124
|
+
inputPath,
|
|
125
|
+
'-movflags',
|
|
126
|
+
'faststart',
|
|
127
|
+
'-pix_fmt',
|
|
128
|
+
'yuv420p',
|
|
129
|
+
'-vf',
|
|
130
|
+
'scale=trunc(iw/2)*2:trunc(ih/2)*2',
|
|
131
|
+
'-f',
|
|
132
|
+
'mp4',
|
|
133
|
+
outputPath,
|
|
134
|
+
]);
|
|
135
|
+
if (out.exitCode === 0) {
|
|
136
|
+
const outputBase64 = fs.readFileSync(outputPath);
|
|
137
|
+
return 'data:video/mp4;base64,' + outputBase64.toString('base64');
|
|
138
|
+
}
|
|
139
|
+
throw out.stderr;
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
(0, rimraf_1.default)(inputPath, () => null);
|
|
143
|
+
(0, rimraf_1.default)(outputPath, () => null);
|
|
144
|
+
}
|
|
145
|
+
return '';
|
|
202
146
|
}
|
package/dist/utils/logger.js
CHANGED
|
@@ -17,9 +17,9 @@ exports.defaultLogger = exports.formatLabelSession = void 0;
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
exports.formatLabelSession = (0, winston_1.format)(
|
|
22
|
-
|
|
20
|
+
const winston_1 = require("winston");
|
|
21
|
+
exports.formatLabelSession = (0, winston_1.format)((info, opts) => {
|
|
22
|
+
const parts = [];
|
|
23
23
|
if (info.session) {
|
|
24
24
|
parts.push(info.session);
|
|
25
25
|
delete info.session;
|
|
@@ -29,8 +29,8 @@ exports.formatLabelSession = (0, winston_1.format)(function (info, opts) {
|
|
|
29
29
|
delete info.type;
|
|
30
30
|
}
|
|
31
31
|
if (parts.length) {
|
|
32
|
-
|
|
33
|
-
info.message =
|
|
32
|
+
let prefix = parts.join(':');
|
|
33
|
+
info.message = `[${prefix}] ${info.message}`;
|
|
34
34
|
}
|
|
35
35
|
return info;
|
|
36
36
|
});
|
package/dist/utils/semver.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.upToDate = upToDate;
|
|
20
|
-
|
|
20
|
+
const VPAT = /^\d+(\.\d+){0,2}$/;
|
|
21
21
|
/**
|
|
22
22
|
* Compares two versions
|
|
23
23
|
* @return true if local is up to date, false otherwise
|
|
@@ -30,15 +30,15 @@ function upToDate(local, remote) {
|
|
|
30
30
|
if (local == remote)
|
|
31
31
|
return true;
|
|
32
32
|
if (VPAT.test(local) && VPAT.test(remote)) {
|
|
33
|
-
|
|
33
|
+
const lparts = local.split('.');
|
|
34
34
|
while (lparts.length < 3)
|
|
35
35
|
lparts.push('0');
|
|
36
|
-
|
|
36
|
+
const rparts = remote.split('.');
|
|
37
37
|
while (rparts.length < 3)
|
|
38
38
|
rparts.push('0');
|
|
39
|
-
for (
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
for (let i = 0; i < 3; i++) {
|
|
40
|
+
const l = parseInt(lparts[i], 10);
|
|
41
|
+
const r = parseInt(rparts[i], 10);
|
|
42
42
|
if (l === r)
|
|
43
43
|
continue;
|
|
44
44
|
return l > r;
|
package/dist/utils/sleep.js
CHANGED
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.sleep = sleep;
|
|
20
20
|
function sleep(time) {
|
|
21
|
-
return new Promise(
|
|
21
|
+
return new Promise((resolve) => setTimeout(resolve, time));
|
|
22
22
|
}
|