@stemy/backend 2.9.6 → 3.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.
- package/bundles/stemy-backend.umd.js +339 -225
- package/bundles/stemy-backend.umd.js.map +1 -1
- package/bundles/stemy-backend.umd.min.js +1 -1
- package/bundles/stemy-backend.umd.min.js.map +1 -1
- package/common-types.d.ts +7 -5
- package/esm2015/common-types.js +1 -1
- package/esm2015/public_api.js +4 -16
- package/esm2015/rest-controllers/assets.controller.js +4 -2
- package/esm2015/services/asset-processor.js +2 -2
- package/esm2015/services/assets.js +23 -1
- package/esm2015/services/entities/asset.js +17 -24
- package/esm2015/services/entities/temp-asset.js +65 -0
- package/esm2015/services/job-manager.js +50 -80
- package/esm2015/utils.js +68 -4
- package/fesm2015/stemy-backend.js +239 -140
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +2 -3
- package/public_api.d.ts +1 -1
- package/services/assets.d.ts +1 -0
- package/services/entities/asset.d.ts +2 -2
- package/services/entities/temp-asset.d.ts +20 -0
- package/services/job-manager.d.ts +11 -13
- package/stemy-backend.metadata.json +1 -1
- package/utils.d.ts +35 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-
|
|
5
|
-
})(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('socket.io-client'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', 'socket.io-client', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', 'bcrypt', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.socket["io-client"], global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
|
|
5
|
+
})(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeCron, zeromq, socket_io_client, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
var sharp___default = /*#__PURE__*/_interopDefaultLegacy(sharp_);
|
|
29
29
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
30
30
|
var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
|
|
31
|
-
var ioredis__default = /*#__PURE__*/_interopDefaultLegacy(ioredis);
|
|
32
31
|
var socket_io_client__default = /*#__PURE__*/_interopDefaultLegacy(socket_io_client);
|
|
33
32
|
var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
|
|
34
33
|
var socket_io__default = /*#__PURE__*/_interopDefaultLegacy(socket_io);
|
|
@@ -106,7 +105,7 @@
|
|
|
106
105
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
107
106
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
108
107
|
}
|
|
109
|
-
function __awaiter$
|
|
108
|
+
function __awaiter$x(thisArg, _arguments, P, generator) {
|
|
110
109
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
111
110
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
112
111
|
function fulfilled(value) { try {
|
|
@@ -353,7 +352,7 @@
|
|
|
353
352
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
354
353
|
}
|
|
355
354
|
|
|
356
|
-
var __awaiter$
|
|
355
|
+
var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
357
356
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
358
357
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
359
358
|
function fulfilled(value) { try {
|
|
@@ -595,7 +594,7 @@
|
|
|
595
594
|
}
|
|
596
595
|
function paginateAggregations(model, aggregations, params, metaProjection) {
|
|
597
596
|
if (metaProjection === void 0) { metaProjection = {}; }
|
|
598
|
-
return __awaiter$
|
|
597
|
+
return __awaiter$w(this, void 0, void 0, function () {
|
|
599
598
|
var sortField, sortAggregation, result, pagination;
|
|
600
599
|
var _a;
|
|
601
600
|
return __generator(this, function (_b) {
|
|
@@ -706,7 +705,7 @@
|
|
|
706
705
|
}
|
|
707
706
|
function readAndDeleteFile(path, timeout) {
|
|
708
707
|
if (timeout === void 0) { timeout = 5000; }
|
|
709
|
-
return __awaiter$
|
|
708
|
+
return __awaiter$w(this, void 0, void 0, function () {
|
|
710
709
|
var data;
|
|
711
710
|
return __generator(this, function (_a) {
|
|
712
711
|
switch (_a.label) {
|
|
@@ -723,7 +722,7 @@
|
|
|
723
722
|
});
|
|
724
723
|
}
|
|
725
724
|
function writeFile(path$1, data) {
|
|
726
|
-
return __awaiter$
|
|
725
|
+
return __awaiter$w(this, void 0, void 0, function () {
|
|
727
726
|
return __generator(this, function (_a) {
|
|
728
727
|
switch (_a.label) {
|
|
729
728
|
case 0: return [4 /*yield*/, mkdirRecursive(path.dirname(path$1))];
|
|
@@ -745,11 +744,16 @@
|
|
|
745
744
|
function valueToPromise(value) {
|
|
746
745
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
747
746
|
}
|
|
748
|
-
function promiseTimeout(timeout) {
|
|
747
|
+
function promiseTimeout(timeout, error) {
|
|
749
748
|
if (timeout === void 0) { timeout = 1000; }
|
|
750
|
-
|
|
749
|
+
if (error === void 0) { error = false; }
|
|
750
|
+
return new Promise(function (resolve, reject) {
|
|
751
751
|
setTimeout(function () {
|
|
752
|
-
|
|
752
|
+
if (error) {
|
|
753
|
+
reject("Timeout exceeded: " + timeout + "ms");
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
resolve("Timeout: " + timeout + "ms");
|
|
753
757
|
}, timeout);
|
|
754
758
|
});
|
|
755
759
|
}
|
|
@@ -811,7 +815,7 @@
|
|
|
811
815
|
var paramName = modelName.toLowerCase();
|
|
812
816
|
return routingControllers.createParamDecorator({
|
|
813
817
|
required: false,
|
|
814
|
-
value: function (action) { return __awaiter$
|
|
818
|
+
value: function (action) { return __awaiter$w(_this, void 0, void 0, function () {
|
|
815
819
|
var req, token, id, query, doc, _a, _b, e_3;
|
|
816
820
|
return __generator(this, function (_c) {
|
|
817
821
|
switch (_c.label) {
|
|
@@ -1059,6 +1063,66 @@
|
|
|
1059
1063
|
console.error(data.toString());
|
|
1060
1064
|
});
|
|
1061
1065
|
});
|
|
1066
|
+
}
|
|
1067
|
+
exports.ConsoleColor = void 0;
|
|
1068
|
+
(function (ConsoleColor) {
|
|
1069
|
+
ConsoleColor["Reset"] = "\u001B[0m";
|
|
1070
|
+
ConsoleColor["Bright"] = "\u001B[1m";
|
|
1071
|
+
ConsoleColor["Dim"] = "\u001B[2m";
|
|
1072
|
+
ConsoleColor["Underscore"] = "\u001B[4m";
|
|
1073
|
+
ConsoleColor["Blink"] = "\u001B[5m";
|
|
1074
|
+
ConsoleColor["Reverse"] = "\u001B[7m";
|
|
1075
|
+
ConsoleColor["Hidden"] = "\u001B[8m";
|
|
1076
|
+
ConsoleColor["FgBlack"] = "\u001B[30m";
|
|
1077
|
+
ConsoleColor["FgRed"] = "\u001B[31m";
|
|
1078
|
+
ConsoleColor["FgGreen"] = "\u001B[32m";
|
|
1079
|
+
ConsoleColor["FgYellow"] = "\u001B[33m";
|
|
1080
|
+
ConsoleColor["FgBlue"] = "\u001B[34m";
|
|
1081
|
+
ConsoleColor["FgMagenta"] = "\u001B[35m";
|
|
1082
|
+
ConsoleColor["FgCyan"] = "\u001B[36m";
|
|
1083
|
+
ConsoleColor["FgWhite"] = "\u001B[37m";
|
|
1084
|
+
ConsoleColor["BgBlack"] = "\u001B[40m";
|
|
1085
|
+
ConsoleColor["BgRed"] = "\u001B[41m";
|
|
1086
|
+
ConsoleColor["BgGreen"] = "\u001B[42m";
|
|
1087
|
+
ConsoleColor["BgYellow"] = "\u001B[43m";
|
|
1088
|
+
ConsoleColor["BgBlue"] = "\u001B[44m";
|
|
1089
|
+
ConsoleColor["BgMagenta"] = "\u001B[45m";
|
|
1090
|
+
ConsoleColor["BgCyan"] = "\u001B[46m";
|
|
1091
|
+
ConsoleColor["BgWhite"] = "\u001B[47m";
|
|
1092
|
+
})(exports.ConsoleColor || (exports.ConsoleColor = {}));
|
|
1093
|
+
var defaultColors = {
|
|
1094
|
+
keyColor: exports.ConsoleColor.Dim,
|
|
1095
|
+
numberColor: exports.ConsoleColor.FgBlue,
|
|
1096
|
+
stringColor: exports.ConsoleColor.FgCyan,
|
|
1097
|
+
trueColor: exports.ConsoleColor.FgGreen,
|
|
1098
|
+
falseColor: exports.ConsoleColor.FgRed,
|
|
1099
|
+
nullColor: exports.ConsoleColor.BgMagenta
|
|
1100
|
+
};
|
|
1101
|
+
function jsonHighlight(input, colorOptions) {
|
|
1102
|
+
var colors = Object.assign({}, defaultColors, colorOptions);
|
|
1103
|
+
var json = (isString(input) ? input : JSON.stringify(input, null, 2)).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
1104
|
+
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g, function (match) {
|
|
1105
|
+
var color = colors.numberColor;
|
|
1106
|
+
if (/^"/.test(match)) {
|
|
1107
|
+
if (/:$/.test(match)) {
|
|
1108
|
+
color = colors.keyColor;
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
color = colors.stringColor;
|
|
1112
|
+
match = '"' + match.substr(1, match.length - 2) + '"';
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
color = /true/.test(match)
|
|
1117
|
+
? colors.trueColor
|
|
1118
|
+
: /false/.test(match)
|
|
1119
|
+
? colors.falseColor
|
|
1120
|
+
: /null/.test(match)
|
|
1121
|
+
? colors.nullColor
|
|
1122
|
+
: color;
|
|
1123
|
+
}
|
|
1124
|
+
return "" + color + match + exports.ConsoleColor.Reset;
|
|
1125
|
+
});
|
|
1062
1126
|
}
|
|
1063
1127
|
|
|
1064
1128
|
var __decorate$x = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -1186,7 +1250,7 @@
|
|
|
1186
1250
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1187
1251
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1188
1252
|
};
|
|
1189
|
-
var __awaiter$
|
|
1253
|
+
var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1190
1254
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1191
1255
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1192
1256
|
function fulfilled(value) { try {
|
|
@@ -1234,7 +1298,7 @@
|
|
|
1234
1298
|
};
|
|
1235
1299
|
AssetProcessor.fileTypeFromBuffer = function (buffer) {
|
|
1236
1300
|
var _a;
|
|
1237
|
-
return __awaiter$
|
|
1301
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
1238
1302
|
var type;
|
|
1239
1303
|
return __generator(this, function (_b) {
|
|
1240
1304
|
switch (_b.label) {
|
|
@@ -1268,13 +1332,13 @@
|
|
|
1268
1332
|
return imageTypes.indexOf(contentType) >= 0;
|
|
1269
1333
|
};
|
|
1270
1334
|
AssetProcessor.copyImageMeta = function (buffer, metadata, fileType) {
|
|
1271
|
-
return __awaiter$
|
|
1335
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
1272
1336
|
var match, attrs, parts, output;
|
|
1273
1337
|
return __generator(this, function (_b) {
|
|
1274
1338
|
switch (_b.label) {
|
|
1275
1339
|
case 0:
|
|
1276
1340
|
if (fileType.mime === "image/svg+xml") {
|
|
1277
|
-
match = /<svg(
|
|
1341
|
+
match = /<svg([^<>]+)>/gi.exec(buffer.toString("utf8"));
|
|
1278
1342
|
if (match && match.length > 1) {
|
|
1279
1343
|
attrs = match[1].match(/([a-z]+)="([^"]+)"/gi);
|
|
1280
1344
|
attrs.forEach(function (attr) {
|
|
@@ -1315,7 +1379,7 @@
|
|
|
1315
1379
|
});
|
|
1316
1380
|
};
|
|
1317
1381
|
AssetProcessor.prototype.process = function (buffer, metadata, fileType) {
|
|
1318
|
-
return __awaiter$
|
|
1382
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
1319
1383
|
return __generator(this, function (_b) {
|
|
1320
1384
|
switch (_b.label) {
|
|
1321
1385
|
case 0:
|
|
@@ -1413,7 +1477,7 @@
|
|
|
1413
1477
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1414
1478
|
return Reflect.metadata(k, v);
|
|
1415
1479
|
};
|
|
1416
|
-
var __awaiter$
|
|
1480
|
+
var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1417
1481
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1418
1482
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1419
1483
|
function fulfilled(value) { try {
|
|
@@ -1461,7 +1525,7 @@
|
|
|
1461
1525
|
configurable: true
|
|
1462
1526
|
});
|
|
1463
1527
|
MongoConnector.prototype.connect = function () {
|
|
1464
|
-
return __awaiter$
|
|
1528
|
+
return __awaiter$u(this, void 0, void 0, function () {
|
|
1465
1529
|
var _a;
|
|
1466
1530
|
return __generator(this, function (_b) {
|
|
1467
1531
|
switch (_b.label) {
|
|
@@ -1493,7 +1557,7 @@
|
|
|
1493
1557
|
__metadata$o("design:paramtypes", [exports.Configuration])
|
|
1494
1558
|
], exports.MongoConnector);
|
|
1495
1559
|
|
|
1496
|
-
var __awaiter$
|
|
1560
|
+
var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1497
1561
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1498
1562
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1499
1563
|
function fulfilled(value) { try {
|
|
@@ -1529,7 +1593,7 @@
|
|
|
1529
1593
|
return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
|
|
1530
1594
|
};
|
|
1531
1595
|
BaseEntity.prototype.load = function () {
|
|
1532
|
-
return __awaiter$
|
|
1596
|
+
return __awaiter$t(this, void 0, void 0, function () {
|
|
1533
1597
|
var res;
|
|
1534
1598
|
return __generator(this, function (_a) {
|
|
1535
1599
|
switch (_a.label) {
|
|
@@ -1552,7 +1616,7 @@
|
|
|
1552
1616
|
return BaseEntity;
|
|
1553
1617
|
}());
|
|
1554
1618
|
|
|
1555
|
-
var __awaiter$
|
|
1619
|
+
var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1556
1620
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1557
1621
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1558
1622
|
function fulfilled(value) { try {
|
|
@@ -1605,16 +1669,17 @@
|
|
|
1605
1669
|
};
|
|
1606
1670
|
};
|
|
1607
1671
|
Asset.toImage = function (stream, meta, params) {
|
|
1608
|
-
return __awaiter$
|
|
1609
|
-
var crop, buffer, cropBefore, cropAfter,
|
|
1610
|
-
return __generator(this, function (
|
|
1611
|
-
switch (
|
|
1672
|
+
return __awaiter$s(this, void 0, void 0, function () {
|
|
1673
|
+
var crop, buffer, cropBefore, cropAfter, img, _a, width, height, canvasScaleX, canvasScaleY, _b, e_1;
|
|
1674
|
+
return __generator(this, function (_c) {
|
|
1675
|
+
switch (_c.label) {
|
|
1612
1676
|
case 0:
|
|
1613
1677
|
params = params || {};
|
|
1614
1678
|
crop = Asset.toCropRegion(meta.crop);
|
|
1615
|
-
// Return
|
|
1616
|
-
if (Object.keys(params).length == 0 && !crop)
|
|
1679
|
+
// Return the stream if there is no params and no default crop exists
|
|
1680
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.extension) === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
1617
1681
|
return [2 /*return*/, stream];
|
|
1682
|
+
}
|
|
1618
1683
|
// Parse params
|
|
1619
1684
|
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
1620
1685
|
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
@@ -1624,76 +1689,59 @@
|
|
|
1624
1689
|
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
1625
1690
|
return [4 /*yield*/, streamToBuffer(stream)];
|
|
1626
1691
|
case 1:
|
|
1627
|
-
buffer =
|
|
1628
|
-
|
|
1692
|
+
buffer = _c.sent();
|
|
1693
|
+
_c.label = 2;
|
|
1629
1694
|
case 2:
|
|
1630
|
-
|
|
1695
|
+
_c.trys.push([2, 7, , 8]);
|
|
1631
1696
|
cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
1632
1697
|
cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
1633
|
-
|
|
1698
|
+
img = sharp$2(buffer);
|
|
1699
|
+
return [4 /*yield*/, img.metadata()];
|
|
1634
1700
|
case 3:
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1701
|
+
_a = _c.sent(), width = _a.width, height = _a.height;
|
|
1702
|
+
// Crop before resize
|
|
1703
|
+
if (cropBefore) {
|
|
1704
|
+
width = cropBefore.width;
|
|
1705
|
+
height = cropBefore.height;
|
|
1706
|
+
img = img.extract(cropBefore);
|
|
1707
|
+
}
|
|
1708
|
+
else if (crop) {
|
|
1709
|
+
width = crop.width;
|
|
1710
|
+
height = crop.height;
|
|
1711
|
+
img = img.extract(crop);
|
|
1712
|
+
}
|
|
1713
|
+
canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
1714
|
+
canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
1715
|
+
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
1716
|
+
width = Math.round(width * params.canvasScaleX);
|
|
1717
|
+
height = Math.round(height * params.canvasScaleY);
|
|
1718
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
|
|
1719
|
+
}
|
|
1720
|
+
// Resize image
|
|
1721
|
+
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
1722
|
+
width = Math.round(width * params.scaleX);
|
|
1723
|
+
height = Math.round(height * params.scaleY);
|
|
1724
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
|
|
1725
|
+
}
|
|
1726
|
+
// Crop after resize
|
|
1727
|
+
if (cropAfter) {
|
|
1728
|
+
img = img.extract(cropAfter);
|
|
1729
|
+
}
|
|
1730
|
+
if (!(params.rotation !== 0)) return [3 /*break*/, 5];
|
|
1731
|
+
return [4 /*yield*/, img.toBuffer()];
|
|
1642
1732
|
case 4:
|
|
1643
|
-
buffer =
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
return [3 /*break*/, 7];
|
|
1733
|
+
buffer = _c.sent();
|
|
1734
|
+
img = sharp$2(buffer).rotate(params.rotation);
|
|
1735
|
+
_c.label = 5;
|
|
1647
1736
|
case 5:
|
|
1648
|
-
|
|
1649
|
-
return [4 /*yield*/,
|
|
1650
|
-
|
|
1651
|
-
.toBuffer()];
|
|
1652
|
-
case 6:
|
|
1653
|
-
buffer = _a.sent();
|
|
1654
|
-
width = crop.width;
|
|
1655
|
-
height = crop.height;
|
|
1656
|
-
_a.label = 7;
|
|
1737
|
+
_b = bufferToStream;
|
|
1738
|
+
return [4 /*yield*/, img.toBuffer()];
|
|
1739
|
+
case 6: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
|
|
1657
1740
|
case 7:
|
|
1658
|
-
|
|
1659
|
-
width = Math.round(width * params.canvasScaleX);
|
|
1660
|
-
height = Math.round(height * params.canvasScaleY);
|
|
1661
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1662
|
-
.resize({ width: width, height: height, background: "#00000000", fit: "contain" })
|
|
1663
|
-
.toBuffer()];
|
|
1664
|
-
case 8:
|
|
1665
|
-
buffer = _a.sent();
|
|
1666
|
-
_a.label = 9;
|
|
1667
|
-
case 9:
|
|
1668
|
-
if (!(params.scaleX !== 1 || params.scaleY !== 1)) return [3 /*break*/, 11];
|
|
1669
|
-
width = Math.round(width * params.scaleX);
|
|
1670
|
-
height = Math.round(height * params.scaleY);
|
|
1671
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1672
|
-
.resize({ width: width, height: height, background: "#00000000", fit: "fill" })
|
|
1673
|
-
.toBuffer()];
|
|
1674
|
-
case 10:
|
|
1675
|
-
buffer = _a.sent();
|
|
1676
|
-
_a.label = 11;
|
|
1677
|
-
case 11:
|
|
1678
|
-
if (!cropAfter) return [3 /*break*/, 13];
|
|
1679
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1680
|
-
.extract(cropAfter)
|
|
1681
|
-
.toBuffer()];
|
|
1682
|
-
case 12:
|
|
1683
|
-
buffer = _a.sent();
|
|
1684
|
-
_a.label = 13;
|
|
1685
|
-
case 13:
|
|
1686
|
-
if (!(params.rotation !== 0)) return [3 /*break*/, 15];
|
|
1687
|
-
return [4 /*yield*/, sharp$2(buffer).rotate(params.rotation).toBuffer()];
|
|
1688
|
-
case 14:
|
|
1689
|
-
buffer = _a.sent();
|
|
1690
|
-
_a.label = 15;
|
|
1691
|
-
case 15: return [2 /*return*/, bufferToStream(buffer)];
|
|
1692
|
-
case 16:
|
|
1693
|
-
e_1 = _a.sent();
|
|
1741
|
+
e_1 = _c.sent();
|
|
1694
1742
|
console.log("Asset image conversion error", e_1);
|
|
1695
1743
|
return [2 /*return*/, bufferToStream(buffer)];
|
|
1696
|
-
case
|
|
1744
|
+
case 8: return [2 /*return*/];
|
|
1697
1745
|
}
|
|
1698
1746
|
});
|
|
1699
1747
|
});
|
|
@@ -1727,7 +1775,7 @@
|
|
|
1727
1775
|
configurable: true
|
|
1728
1776
|
});
|
|
1729
1777
|
Asset.prototype.unlink = function () {
|
|
1730
|
-
return __awaiter$
|
|
1778
|
+
return __awaiter$s(this, void 0, void 0, function () {
|
|
1731
1779
|
return __generator(this, function (_a) {
|
|
1732
1780
|
return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
|
|
1733
1781
|
});
|
|
@@ -1737,7 +1785,7 @@
|
|
|
1737
1785
|
return streamToBuffer(this.stream);
|
|
1738
1786
|
};
|
|
1739
1787
|
Asset.prototype.download = function (metadata) {
|
|
1740
|
-
return __awaiter$
|
|
1788
|
+
return __awaiter$s(this, void 0, void 0, function () {
|
|
1741
1789
|
return __generator(this, function (_a) {
|
|
1742
1790
|
switch (_a.label) {
|
|
1743
1791
|
case 0:
|
|
@@ -1757,14 +1805,14 @@
|
|
|
1757
1805
|
};
|
|
1758
1806
|
Asset.prototype.getImage = function (params) {
|
|
1759
1807
|
if (params === void 0) { params = null; }
|
|
1760
|
-
return __awaiter$
|
|
1808
|
+
return __awaiter$s(this, void 0, void 0, function () {
|
|
1761
1809
|
return __generator(this, function (_a) {
|
|
1762
1810
|
return [2 /*return*/, Asset.toImage(this.stream, this.metadata, params)];
|
|
1763
1811
|
});
|
|
1764
1812
|
});
|
|
1765
1813
|
};
|
|
1766
1814
|
Asset.prototype.downloadImage = function (params, metadata) {
|
|
1767
|
-
return __awaiter$
|
|
1815
|
+
return __awaiter$s(this, void 0, void 0, function () {
|
|
1768
1816
|
var _a, _b;
|
|
1769
1817
|
return __generator(this, function (_c) {
|
|
1770
1818
|
switch (_c.label) {
|
|
@@ -1779,6 +1827,93 @@
|
|
|
1779
1827
|
return Asset;
|
|
1780
1828
|
}(BaseEntity));
|
|
1781
1829
|
|
|
1830
|
+
var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1831
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1832
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1833
|
+
function fulfilled(value) { try {
|
|
1834
|
+
step(generator.next(value));
|
|
1835
|
+
}
|
|
1836
|
+
catch (e) {
|
|
1837
|
+
reject(e);
|
|
1838
|
+
} }
|
|
1839
|
+
function rejected(value) { try {
|
|
1840
|
+
step(generator["throw"](value));
|
|
1841
|
+
}
|
|
1842
|
+
catch (e) {
|
|
1843
|
+
reject(e);
|
|
1844
|
+
} }
|
|
1845
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1846
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1849
|
+
var TempAsset = /** @class */ (function () {
|
|
1850
|
+
function TempAsset(buffer, filename, contentType, metadata) {
|
|
1851
|
+
this.buffer = buffer;
|
|
1852
|
+
this.filename = filename;
|
|
1853
|
+
this.contentType = contentType;
|
|
1854
|
+
this.metadata = metadata;
|
|
1855
|
+
this.id = new bson.ObjectId().toHexString();
|
|
1856
|
+
}
|
|
1857
|
+
Object.defineProperty(TempAsset.prototype, "stream", {
|
|
1858
|
+
get: function () {
|
|
1859
|
+
return bufferToStream(this.buffer);
|
|
1860
|
+
},
|
|
1861
|
+
enumerable: false,
|
|
1862
|
+
configurable: true
|
|
1863
|
+
});
|
|
1864
|
+
TempAsset.prototype.unlink = function () {
|
|
1865
|
+
return __awaiter$r(this, void 0, void 0, function () {
|
|
1866
|
+
return __generator(this, function (_a) {
|
|
1867
|
+
throw new Error("Temp asset '" + this.id + "' can not be removed!");
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
};
|
|
1871
|
+
TempAsset.prototype.getBuffer = function () {
|
|
1872
|
+
return __awaiter$r(this, void 0, void 0, function () {
|
|
1873
|
+
return __generator(this, function (_a) {
|
|
1874
|
+
return [2 /*return*/, this.buffer];
|
|
1875
|
+
});
|
|
1876
|
+
});
|
|
1877
|
+
};
|
|
1878
|
+
TempAsset.prototype.download = function (metadata) {
|
|
1879
|
+
return __awaiter$r(this, void 0, void 0, function () {
|
|
1880
|
+
return __generator(this, function (_a) {
|
|
1881
|
+
return [2 /*return*/, this.stream];
|
|
1882
|
+
});
|
|
1883
|
+
});
|
|
1884
|
+
};
|
|
1885
|
+
TempAsset.prototype.downloadImage = function (params, metadata) {
|
|
1886
|
+
Object.assign(this.metadata, metadata || {});
|
|
1887
|
+
return Asset.toImage(this.stream, this.metadata, params);
|
|
1888
|
+
};
|
|
1889
|
+
TempAsset.prototype.getImage = function (params) {
|
|
1890
|
+
return this.downloadImage(params);
|
|
1891
|
+
};
|
|
1892
|
+
TempAsset.prototype.save = function () {
|
|
1893
|
+
return __awaiter$r(this, void 0, void 0, function () {
|
|
1894
|
+
return __generator(this, function (_a) {
|
|
1895
|
+
return [2 /*return*/, this];
|
|
1896
|
+
});
|
|
1897
|
+
});
|
|
1898
|
+
};
|
|
1899
|
+
TempAsset.prototype.load = function () {
|
|
1900
|
+
return __awaiter$r(this, void 0, void 0, function () {
|
|
1901
|
+
return __generator(this, function (_a) {
|
|
1902
|
+
return [2 /*return*/, this];
|
|
1903
|
+
});
|
|
1904
|
+
});
|
|
1905
|
+
};
|
|
1906
|
+
TempAsset.prototype.toJSON = function () {
|
|
1907
|
+
return {
|
|
1908
|
+
id: this.id,
|
|
1909
|
+
filename: this.filename,
|
|
1910
|
+
contentType: this.contentType,
|
|
1911
|
+
metadata: this.metadata
|
|
1912
|
+
};
|
|
1913
|
+
};
|
|
1914
|
+
return TempAsset;
|
|
1915
|
+
}());
|
|
1916
|
+
|
|
1782
1917
|
var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
1783
1918
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1784
1919
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1901,6 +2036,43 @@
|
|
|
1901
2036
|
});
|
|
1902
2037
|
});
|
|
1903
2038
|
};
|
|
2039
|
+
Assets.prototype.download = function (url, contentType) {
|
|
2040
|
+
if (contentType === void 0) { contentType = null; }
|
|
2041
|
+
return __awaiter$q(this, void 0, void 0, function () {
|
|
2042
|
+
var buffer, fileType, e_3, metadata;
|
|
2043
|
+
return __generator(this, function (_b) {
|
|
2044
|
+
switch (_b.label) {
|
|
2045
|
+
case 0: return [4 /*yield*/, axios__default["default"]({ url: url, responseType: "arraybuffer" })];
|
|
2046
|
+
case 1:
|
|
2047
|
+
buffer = (_b.sent()).data;
|
|
2048
|
+
fileType = { ext: "", mime: contentType };
|
|
2049
|
+
_b.label = 2;
|
|
2050
|
+
case 2:
|
|
2051
|
+
_b.trys.push([2, 4, , 5]);
|
|
2052
|
+
return [4 /*yield*/, exports.AssetProcessor.fileTypeFromBuffer(buffer)];
|
|
2053
|
+
case 3:
|
|
2054
|
+
fileType = _b.sent();
|
|
2055
|
+
return [3 /*break*/, 5];
|
|
2056
|
+
case 4:
|
|
2057
|
+
e_3 = _b.sent();
|
|
2058
|
+
if (!fileType.mime) {
|
|
2059
|
+
throw "Can't determine mime type";
|
|
2060
|
+
}
|
|
2061
|
+
console.log("Can't determine mime type", e_3);
|
|
2062
|
+
return [3 /*break*/, 5];
|
|
2063
|
+
case 5:
|
|
2064
|
+
metadata = {
|
|
2065
|
+
filename: url,
|
|
2066
|
+
extension: (fileType.ext || "").trim()
|
|
2067
|
+
};
|
|
2068
|
+
return [4 /*yield*/, this.assetProcessor.process(buffer, metadata, fileType)];
|
|
2069
|
+
case 6:
|
|
2070
|
+
buffer = _b.sent();
|
|
2071
|
+
return [2 /*return*/, new TempAsset(buffer, url, fileType.mime, metadata)];
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
});
|
|
2075
|
+
};
|
|
1904
2076
|
Assets.prototype.read = function (id) {
|
|
1905
2077
|
return __awaiter$q(this, void 0, void 0, function () {
|
|
1906
2078
|
return __generator(this, function (_b) {
|
|
@@ -1924,7 +2096,7 @@
|
|
|
1924
2096
|
Assets.prototype.findMany = function (where) {
|
|
1925
2097
|
return __awaiter$q(this, void 0, void 0, function () {
|
|
1926
2098
|
var cursor, items, result, items_1, items_1_1, item;
|
|
1927
|
-
var
|
|
2099
|
+
var e_4, _b;
|
|
1928
2100
|
return __generator(this, function (_c) {
|
|
1929
2101
|
switch (_c.label) {
|
|
1930
2102
|
case 0:
|
|
@@ -1941,12 +2113,12 @@
|
|
|
1941
2113
|
result.push(new Asset(item._id, item, this.collection, this.bucket));
|
|
1942
2114
|
}
|
|
1943
2115
|
}
|
|
1944
|
-
catch (
|
|
2116
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1945
2117
|
finally {
|
|
1946
2118
|
try {
|
|
1947
2119
|
if (items_1_1 && !items_1_1.done && (_b = items_1.return)) _b.call(items_1);
|
|
1948
2120
|
}
|
|
1949
|
-
finally { if (
|
|
2121
|
+
finally { if (e_4) throw e_4.error; }
|
|
1950
2122
|
}
|
|
1951
2123
|
return [2 /*return*/, result];
|
|
1952
2124
|
}
|
|
@@ -2206,7 +2378,6 @@
|
|
|
2206
2378
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2207
2379
|
});
|
|
2208
2380
|
};
|
|
2209
|
-
var IORedis = ioredis__default["default"];
|
|
2210
2381
|
exports.JobManager = /** @class */ (function () {
|
|
2211
2382
|
function JobManager(config, container, jobTypes) {
|
|
2212
2383
|
var _this = this;
|
|
@@ -2214,8 +2385,9 @@
|
|
|
2214
2385
|
this.container = container;
|
|
2215
2386
|
this.jobTypes = jobTypes || [];
|
|
2216
2387
|
this.jobs = this.jobTypes.reduce(function (res, jobType) {
|
|
2217
|
-
res[getConstructorName(jobType)] = {
|
|
2218
|
-
|
|
2388
|
+
res[getConstructorName(jobType)] = function (jobParams) {
|
|
2389
|
+
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2390
|
+
return job.process();
|
|
2219
2391
|
};
|
|
2220
2392
|
return res;
|
|
2221
2393
|
}, {});
|
|
@@ -2237,9 +2409,8 @@
|
|
|
2237
2409
|
});
|
|
2238
2410
|
});
|
|
2239
2411
|
};
|
|
2240
|
-
JobManager.prototype.enqueueWithName = function (name, params
|
|
2412
|
+
JobManager.prototype.enqueueWithName = function (name, params) {
|
|
2241
2413
|
if (params === void 0) { params = {}; }
|
|
2242
|
-
if (que === void 0) { que = "main"; }
|
|
2243
2414
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2244
2415
|
var jobName;
|
|
2245
2416
|
return __generator(this, function (_a) {
|
|
@@ -2247,17 +2418,13 @@
|
|
|
2247
2418
|
case 0: return [4 /*yield*/, this.tryResolveFromName(name, params)];
|
|
2248
2419
|
case 1:
|
|
2249
2420
|
jobName = _a.sent();
|
|
2250
|
-
return [
|
|
2251
|
-
case 2:
|
|
2252
|
-
_a.sent();
|
|
2253
|
-
return [2 /*return*/];
|
|
2421
|
+
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2254
2422
|
}
|
|
2255
2423
|
});
|
|
2256
2424
|
});
|
|
2257
2425
|
};
|
|
2258
|
-
JobManager.prototype.enqueue = function (jobType, params
|
|
2426
|
+
JobManager.prototype.enqueue = function (jobType, params) {
|
|
2259
2427
|
if (params === void 0) { params = {}; }
|
|
2260
|
-
if (que === void 0) { que = "main"; }
|
|
2261
2428
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2262
2429
|
var jobName;
|
|
2263
2430
|
return __generator(this, function (_a) {
|
|
@@ -2265,25 +2432,20 @@
|
|
|
2265
2432
|
case 0: return [4 /*yield*/, this.tryResolveAndConnect(jobType, params)];
|
|
2266
2433
|
case 1:
|
|
2267
2434
|
jobName = _a.sent();
|
|
2268
|
-
return [
|
|
2269
|
-
case 2:
|
|
2270
|
-
_a.sent();
|
|
2271
|
-
return [2 /*return*/];
|
|
2435
|
+
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2272
2436
|
}
|
|
2273
2437
|
});
|
|
2274
2438
|
});
|
|
2275
2439
|
};
|
|
2276
|
-
JobManager.prototype.
|
|
2277
|
-
if (params === void 0) { params = {}; }
|
|
2278
|
-
if (que === void 0) { que = "main"; }
|
|
2440
|
+
JobManager.prototype.sendToWorkers = function (jobName, params) {
|
|
2279
2441
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2280
|
-
var
|
|
2442
|
+
var publisher;
|
|
2281
2443
|
return __generator(this, function (_a) {
|
|
2282
2444
|
switch (_a.label) {
|
|
2283
|
-
case 0: return [4 /*yield*/, this.
|
|
2445
|
+
case 0: return [4 /*yield*/, this.scheduler];
|
|
2284
2446
|
case 1:
|
|
2285
|
-
|
|
2286
|
-
return [4 /*yield*/,
|
|
2447
|
+
publisher = _a.sent();
|
|
2448
|
+
return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
|
|
2287
2449
|
case 2:
|
|
2288
2450
|
_a.sent();
|
|
2289
2451
|
return [2 /*return*/];
|
|
@@ -2291,28 +2453,9 @@
|
|
|
2291
2453
|
});
|
|
2292
2454
|
});
|
|
2293
2455
|
};
|
|
2294
|
-
JobManager.prototype.
|
|
2295
|
-
if (params === void 0) { params = {}; }
|
|
2296
|
-
if (que === void 0) { que = "main"; }
|
|
2297
|
-
return __awaiter$o(this, void 0, void 0, function () {
|
|
2298
|
-
var jobName;
|
|
2299
|
-
return __generator(this, function (_a) {
|
|
2300
|
-
switch (_a.label) {
|
|
2301
|
-
case 0: return [4 /*yield*/, this.tryResolveAndConnect(jobType, params)];
|
|
2302
|
-
case 1:
|
|
2303
|
-
jobName = _a.sent();
|
|
2304
|
-
return [4 /*yield*/, this.queue.enqueueIn(time, que, jobName, [params])];
|
|
2305
|
-
case 2:
|
|
2306
|
-
_a.sent();
|
|
2307
|
-
return [2 /*return*/];
|
|
2308
|
-
}
|
|
2309
|
-
});
|
|
2310
|
-
});
|
|
2311
|
-
};
|
|
2312
|
-
JobManager.prototype.schedule = function (minute, hour, dayOfMonth, month, dayOfWeek, jobType, params, que) {
|
|
2456
|
+
JobManager.prototype.schedule = function (minute, hour, dayOfMonth, month, dayOfWeek, jobType, params) {
|
|
2313
2457
|
var _this = this;
|
|
2314
2458
|
if (params === void 0) { params = {}; }
|
|
2315
|
-
if (que === void 0) { que = "main"; }
|
|
2316
2459
|
var expression = [minute, hour, dayOfMonth, month, dayOfWeek].map(function (t) {
|
|
2317
2460
|
if (isObject(t)) {
|
|
2318
2461
|
var range = t;
|
|
@@ -2329,33 +2472,53 @@
|
|
|
2329
2472
|
return null;
|
|
2330
2473
|
}
|
|
2331
2474
|
return nodeCron.schedule(expression, function () {
|
|
2332
|
-
_this.enqueue(jobType, params
|
|
2475
|
+
_this.enqueue(jobType, params).catch(function (e) {
|
|
2333
2476
|
console.log("Can't enqueue job: '" + jobName + "' because: " + e);
|
|
2334
2477
|
});
|
|
2335
2478
|
});
|
|
2336
2479
|
};
|
|
2337
2480
|
JobManager.prototype.startProcessing = function () {
|
|
2338
|
-
|
|
2481
|
+
var _this = this;
|
|
2482
|
+
var host = this.config.resolve("zmqRemoteHost");
|
|
2483
|
+
this.worker = zeromq.socket("pull");
|
|
2484
|
+
this.worker.connect(host);
|
|
2485
|
+
this.worker.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2486
|
+
var jobName, jobParams, timerId, jobNameLog, jobArgsLog, e_1, e_2;
|
|
2339
2487
|
return __generator(this, function (_a) {
|
|
2340
2488
|
switch (_a.label) {
|
|
2341
2489
|
case 0:
|
|
2342
|
-
|
|
2343
|
-
|
|
2490
|
+
_a.trys.push([0, 5, , 6]);
|
|
2491
|
+
jobName = name.toString("utf8");
|
|
2492
|
+
jobParams = JSON.parse(args.toString("utf8"));
|
|
2493
|
+
timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
|
|
2494
|
+
jobNameLog = "\u001B[36m\"" + jobName + "\"\u001B[0m";
|
|
2495
|
+
jobArgsLog = "\n" + jsonHighlight(jobParams) + "\n";
|
|
2496
|
+
console.time(timerId);
|
|
2497
|
+
console.timeLog(timerId, "Started working on background job: " + jobNameLog + " with args: " + jobArgsLog);
|
|
2498
|
+
_a.label = 1;
|
|
2344
2499
|
case 1:
|
|
2345
|
-
_a.
|
|
2346
|
-
return [4 /*yield*/, this.
|
|
2500
|
+
_a.trys.push([1, 3, , 4]);
|
|
2501
|
+
return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(15000, true)])];
|
|
2347
2502
|
case 2:
|
|
2348
2503
|
_a.sent();
|
|
2349
|
-
|
|
2504
|
+
console.timeLog(timerId, "Finished working on background job: " + jobNameLog + " with args: " + jobArgsLog);
|
|
2505
|
+
return [3 /*break*/, 4];
|
|
2350
2506
|
case 3:
|
|
2351
|
-
_a.sent();
|
|
2352
|
-
|
|
2507
|
+
e_1 = _a.sent();
|
|
2508
|
+
console.timeLog(timerId, "Background job failed: " + jobNameLog + " with args: " + jobArgsLog + e_1.message + "\n\n");
|
|
2509
|
+
return [3 /*break*/, 4];
|
|
2353
2510
|
case 4:
|
|
2354
|
-
|
|
2355
|
-
return [
|
|
2511
|
+
console.timeEnd(timerId);
|
|
2512
|
+
return [3 /*break*/, 6];
|
|
2513
|
+
case 5:
|
|
2514
|
+
e_2 = _a.sent();
|
|
2515
|
+
console.log("Failed to start job: " + e_2.message);
|
|
2516
|
+
return [3 /*break*/, 6];
|
|
2517
|
+
case 6: return [2 /*return*/];
|
|
2356
2518
|
}
|
|
2357
2519
|
});
|
|
2358
|
-
});
|
|
2520
|
+
}); });
|
|
2521
|
+
console.log("Waiting for jobs at: " + host);
|
|
2359
2522
|
};
|
|
2360
2523
|
JobManager.prototype.tryResolve = function (jobType, params) {
|
|
2361
2524
|
var jobName = getConstructorName(jobType);
|
|
@@ -2370,47 +2533,6 @@
|
|
|
2370
2533
|
}
|
|
2371
2534
|
return jobName;
|
|
2372
2535
|
};
|
|
2373
|
-
JobManager.prototype.initialize = function () {
|
|
2374
|
-
if (this.queue)
|
|
2375
|
-
return;
|
|
2376
|
-
var config = this.config;
|
|
2377
|
-
var options = { password: config.resolve("redisPassword") };
|
|
2378
|
-
var sentinels = config.resolve("redisSentinels");
|
|
2379
|
-
var redis = !sentinels
|
|
2380
|
-
? null
|
|
2381
|
-
: new IORedis({
|
|
2382
|
-
sentinels: sentinels,
|
|
2383
|
-
name: config.resolve("redisCluster"),
|
|
2384
|
-
});
|
|
2385
|
-
var connection = {
|
|
2386
|
-
pkg: "ioredis",
|
|
2387
|
-
host: config.resolve("redisHost"),
|
|
2388
|
-
password: options.password,
|
|
2389
|
-
port: config.resolve("redisPort"),
|
|
2390
|
-
namespace: config.resolve("redisNamespace"),
|
|
2391
|
-
redis: redis,
|
|
2392
|
-
options: options
|
|
2393
|
-
};
|
|
2394
|
-
var queues = config.resolve("workQueues");
|
|
2395
|
-
this.queue = new nodeResque.Queue({ connection: connection }, this.jobs);
|
|
2396
|
-
this.worker = new nodeResque.Worker({ connection: connection, queues: queues }, this.jobs);
|
|
2397
|
-
this.worker.on("job", function (queue, job) {
|
|
2398
|
-
console.log("working job " + queue + " " + JSON.stringify(job));
|
|
2399
|
-
});
|
|
2400
|
-
this.worker.on("reEnqueue", function (queue, job, plugin) {
|
|
2401
|
-
console.log("reEnqueue job (" + plugin + ") " + queue + " " + JSON.stringify(job));
|
|
2402
|
-
});
|
|
2403
|
-
this.worker.on("success", function (queue, job, result, duration) {
|
|
2404
|
-
console.log("job success " + queue + " " + JSON.stringify(job) + " >> " + result + " (" + duration + "ms)");
|
|
2405
|
-
});
|
|
2406
|
-
this.worker.on("failure", function (queue, job, failure, duration) {
|
|
2407
|
-
console.log("job failure " + queue + " " + JSON.stringify(job) + " >> " + failure + " (" + duration + "ms)");
|
|
2408
|
-
});
|
|
2409
|
-
this.worker.on("error", function (error, queue, job) {
|
|
2410
|
-
console.log("error " + queue + " " + JSON.stringify(job) + " >> " + error);
|
|
2411
|
-
});
|
|
2412
|
-
this.scheduler = new nodeResque.Scheduler({ connection: connection }, this.jobs);
|
|
2413
|
-
};
|
|
2414
2536
|
JobManager.prototype.tryResolveFromName = function (jobName, params) {
|
|
2415
2537
|
var jobType = this.jobTypes.find(function (type) {
|
|
2416
2538
|
return getConstructorName(type) == jobName;
|
|
@@ -2422,17 +2544,25 @@
|
|
|
2422
2544
|
};
|
|
2423
2545
|
JobManager.prototype.tryResolveAndConnect = function (jobType, params) {
|
|
2424
2546
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2425
|
-
var
|
|
2547
|
+
var _this = this;
|
|
2426
2548
|
return __generator(this, function (_a) {
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2549
|
+
this.scheduler = this.scheduler || new Promise(function (resolve) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2550
|
+
var port, publisher;
|
|
2551
|
+
return __generator(this, function (_a) {
|
|
2552
|
+
switch (_a.label) {
|
|
2553
|
+
case 0:
|
|
2554
|
+
port = this.config.resolve("zmqPort");
|
|
2555
|
+
publisher = zeromq.socket("push");
|
|
2556
|
+
return [4 /*yield*/, publisher.bind("tcp://0.0.0.0:" + port)];
|
|
2557
|
+
case 1:
|
|
2558
|
+
_a.sent();
|
|
2559
|
+
console.log("Publisher bound to port: " + port);
|
|
2560
|
+
resolve(publisher);
|
|
2561
|
+
return [2 /*return*/];
|
|
2562
|
+
}
|
|
2563
|
+
});
|
|
2564
|
+
}); });
|
|
2565
|
+
return [2 /*return*/, this.tryResolve(jobType, params)];
|
|
2436
2566
|
});
|
|
2437
2567
|
});
|
|
2438
2568
|
};
|
|
@@ -2444,13 +2574,6 @@
|
|
|
2444
2574
|
container.register(jobType, jobType);
|
|
2445
2575
|
return container.resolve(jobType);
|
|
2446
2576
|
};
|
|
2447
|
-
JobManager.prototype.toPerformFunction = function (jobType) {
|
|
2448
|
-
var _this = this;
|
|
2449
|
-
return function (jobParams) {
|
|
2450
|
-
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2451
|
-
return job.process();
|
|
2452
|
-
};
|
|
2453
|
-
};
|
|
2454
2577
|
return JobManager;
|
|
2455
2578
|
}());
|
|
2456
2579
|
exports.JobManager = __decorate$s([
|
|
@@ -4605,7 +4728,9 @@
|
|
|
4605
4728
|
case 0: return [4 /*yield*/, this.getAsset("Image", id, params.lazy, res)];
|
|
4606
4729
|
case 1:
|
|
4607
4730
|
asset = _c.sent();
|
|
4608
|
-
|
|
4731
|
+
if (rotation !== 0) {
|
|
4732
|
+
params.rotation = params.rotation || rotation;
|
|
4733
|
+
}
|
|
4609
4734
|
return [2 /*return*/, asset.downloadImage(params)];
|
|
4610
4735
|
}
|
|
4611
4736
|
});
|
|
@@ -5709,20 +5834,8 @@
|
|
|
5709
5834
|
new Parameter("mongoPassword", null),
|
|
5710
5835
|
new Parameter("nodeEnv", "development"),
|
|
5711
5836
|
new Parameter("appPort", 80),
|
|
5712
|
-
new Parameter("
|
|
5713
|
-
new Parameter("
|
|
5714
|
-
new Parameter("redisPassword", "123456"),
|
|
5715
|
-
new Parameter("redisNamespace", "resque"),
|
|
5716
|
-
new Parameter("redisCluster", "mymaster"),
|
|
5717
|
-
new Parameter("redisSentinels", null, function (value) {
|
|
5718
|
-
if (!value)
|
|
5719
|
-
return null;
|
|
5720
|
-
return value.split(", ").map(function (item) {
|
|
5721
|
-
var values = item.split(":");
|
|
5722
|
-
return { host: values[0], port: Number(values[1]) };
|
|
5723
|
-
});
|
|
5724
|
-
}),
|
|
5725
|
-
new Parameter("workQueues", ["main"]),
|
|
5837
|
+
new Parameter("zmqPort", 3000),
|
|
5838
|
+
new Parameter("zmqRemoteHost", "tcp://127.0.0.1:3000"),
|
|
5726
5839
|
new Parameter("isWorker", false),
|
|
5727
5840
|
new Parameter("mainEndpoint", ""),
|
|
5728
5841
|
new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
@@ -6011,6 +6124,7 @@
|
|
|
6011
6124
|
exports.isPrimitive = isPrimitive;
|
|
6012
6125
|
exports.isString = isString;
|
|
6013
6126
|
exports.isType = isType;
|
|
6127
|
+
exports.jsonHighlight = jsonHighlight;
|
|
6014
6128
|
exports.lastItem = lastItem;
|
|
6015
6129
|
exports.lcFirst = lcFirst;
|
|
6016
6130
|
exports.lookupPipelines = lookupPipelines;
|