@resolveio/server-lib 1.0.17 → 1.0.19
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.
|
@@ -6,13 +6,17 @@ export declare class SupportManager {
|
|
|
6
6
|
private _mailer;
|
|
7
7
|
private _aws;
|
|
8
8
|
private serverConfig;
|
|
9
|
+
private clientDir;
|
|
9
10
|
private _sendQueue;
|
|
10
11
|
private _runningQueue;
|
|
11
|
-
constructor(mainServer: any, serverConfig: any);
|
|
12
|
+
constructor(mainServer: any, serverConfig: any, clientDir: any);
|
|
12
13
|
getMainServer(): ResolveIOMainServer;
|
|
13
14
|
supportMethods(supportMethod: SupportMethodModel): void;
|
|
14
15
|
callSupportMethod(ws: WebSocket, messageId: any, supportMethod: any, ...methodData: any[]): void;
|
|
15
|
-
|
|
16
|
+
callSupportMethodInternal(supportMethod: any, ...methodData: any[]): Promise<any>;
|
|
17
|
+
callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
|
|
16
18
|
private sendWS;
|
|
17
19
|
sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[]): void;
|
|
20
|
+
readFile(fileName: any): Promise<{}>;
|
|
21
|
+
readImage(fileName: any): Promise<{}>;
|
|
18
22
|
}
|
|
@@ -8,14 +8,18 @@ var counters_1 = require("../support-methods/counters");
|
|
|
8
8
|
var mongoose_1 = require("mongoose");
|
|
9
9
|
var common_1 = require("../util/common");
|
|
10
10
|
var log_collection_1 = require("../collections/log.collection");
|
|
11
|
+
var method_manager_1 = require("./method.manager");
|
|
12
|
+
var path = require("path");
|
|
13
|
+
var fs = require("fs");
|
|
11
14
|
var SupportManager = /** @class */ (function () {
|
|
12
|
-
function SupportManager(mainServer, serverConfig) {
|
|
15
|
+
function SupportManager(mainServer, serverConfig, clientDir) {
|
|
13
16
|
var _this = this;
|
|
14
17
|
this._supportMethods = {};
|
|
15
18
|
this._sendQueue = [];
|
|
16
19
|
this._runningQueue = false;
|
|
17
20
|
this._mainServer = mainServer;
|
|
18
21
|
this.serverConfig = serverConfig;
|
|
22
|
+
this.clientDir = clientDir;
|
|
19
23
|
collections_1.loadSupportCollectionMethods(this);
|
|
20
24
|
support_1.loadSupportMethods(this);
|
|
21
25
|
counters_1.loadCounterMethods(this);
|
|
@@ -180,7 +184,7 @@ var SupportManager = /** @class */ (function () {
|
|
|
180
184
|
_this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
181
185
|
});
|
|
182
186
|
};
|
|
183
|
-
SupportManager.prototype.
|
|
187
|
+
SupportManager.prototype.callSupportMethodInternal = function (supportMethod) {
|
|
184
188
|
var methodData = [];
|
|
185
189
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
186
190
|
methodData[_i - 1] = arguments[_i];
|
|
@@ -207,6 +211,33 @@ var SupportManager = /** @class */ (function () {
|
|
|
207
211
|
}
|
|
208
212
|
return promise;
|
|
209
213
|
};
|
|
214
|
+
SupportManager.prototype.callMethodInternal = function (method) {
|
|
215
|
+
var methodData = [];
|
|
216
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
217
|
+
methodData[_i - 1] = arguments[_i];
|
|
218
|
+
}
|
|
219
|
+
var _a;
|
|
220
|
+
var that = this;
|
|
221
|
+
if (!that._mainServer.getMethodManager()._methods[method]) {
|
|
222
|
+
console.log('No Method: ' + method);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that._mainServer.getMethodManager()._methods[method].skipValidation) {
|
|
226
|
+
if (!that._mainServer.getMethodManager()._methods[method].check) {
|
|
227
|
+
console.error('No Check Function For Method ' + method);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
else if (!that._mainServer.getMethodManager()._methods[method].check._schema) {
|
|
231
|
+
console.error('No Check Schema For Method ' + method);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var promise = (_a = that._mainServer.getMethodManager()._methods[method].function).call.apply(_a, [Object.assign({}, that, method_manager_1.MethodManager.prototype)].concat(methodData));
|
|
236
|
+
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
237
|
+
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
238
|
+
}
|
|
239
|
+
return promise;
|
|
240
|
+
};
|
|
210
241
|
SupportManager.prototype.sendWS = function (ws, method, methodData, data) {
|
|
211
242
|
this._sendQueue.splice(0, 0, {
|
|
212
243
|
id_ws: ws['id_socket'],
|
|
@@ -230,6 +261,60 @@ var SupportManager = /** @class */ (function () {
|
|
|
230
261
|
}
|
|
231
262
|
});
|
|
232
263
|
};
|
|
264
|
+
SupportManager.prototype.readFile = function (fileName) {
|
|
265
|
+
var _this = this;
|
|
266
|
+
return new Promise(function (resolve, reject) {
|
|
267
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
268
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
|
|
269
|
+
if (err) {
|
|
270
|
+
reject(err);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
resolve(res);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
279
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
|
|
280
|
+
if (err) {
|
|
281
|
+
reject(err);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
resolve(res);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
SupportManager.prototype.readImage = function (fileName) {
|
|
292
|
+
var _this = this;
|
|
293
|
+
return new Promise(function (resolve, reject) {
|
|
294
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
295
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
|
|
296
|
+
if (err) {
|
|
297
|
+
reject(err);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
resolve(res);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
306
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
|
|
307
|
+
if (err) {
|
|
308
|
+
reject(err);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
resolve(res);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
};
|
|
233
318
|
return SupportManager;
|
|
234
319
|
}());
|
|
235
320
|
exports.SupportManager = SupportManager;
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -206,7 +206,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
206
206
|
// Start Managers
|
|
207
207
|
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
|
|
208
208
|
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
|
|
209
|
-
this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig);
|
|
209
|
+
this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig, this._clientDir);
|
|
210
210
|
this._cronManager = new cron_manager_1.CronManager(this);
|
|
211
211
|
this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
|
|
212
212
|
this.listen();
|
|
@@ -59,7 +59,7 @@ function loadSupportCronJobMethods(methodManager) {
|
|
|
59
59
|
count = 0;
|
|
60
60
|
interval = setInterval(function () {
|
|
61
61
|
var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
|
|
62
|
-
_this.
|
|
62
|
+
_this.callSupportMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
|
|
63
63
|
count++;
|
|
64
64
|
if (count * 10 > users.length) {
|
|
65
65
|
clearInterval(interval);
|