@stemy/backend 2.7.4 → 2.8.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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
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-resque'), require('node-cron'), require('ioredis'), require('socket.io-client'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
3
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-resque', 'node-cron', 'ioredis', '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-resque'], global['node-cron'], global.ioredis, 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, nodeResque, nodeCron, ioredis, socket_io_client, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
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-resque"], global["node-cron"], global.ioredis, 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, nodeResque, nodeCron, ioredis, 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
 
@@ -15,14 +15,12 @@
15
15
  var d = Object.getOwnPropertyDescriptor(e, k);
16
16
  Object.defineProperty(n, k, d.get ? d : {
17
17
  enumerable: true,
18
- get: function () {
19
- return e[k];
20
- }
18
+ get: function () { return e[k]; }
21
19
  });
22
20
  }
23
21
  });
24
22
  }
25
- n['default'] = e;
23
+ n["default"] = e;
26
24
  return Object.freeze(n);
27
25
  }
28
26
 
@@ -108,7 +106,7 @@
108
106
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
109
107
  return Reflect.metadata(metadataKey, metadataValue);
110
108
  }
111
- function __awaiter$v(thisArg, _arguments, P, generator) {
109
+ function __awaiter$w(thisArg, _arguments, P, generator) {
112
110
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
113
111
  return new (P || (P = Promise))(function (resolve, reject) {
114
112
  function fulfilled(value) { try {
@@ -355,7 +353,7 @@
355
353
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
356
354
  }
357
355
 
358
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
356
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
359
357
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
360
358
  return new (P || (P = Promise))(function (resolve, reject) {
361
359
  function fulfilled(value) { try {
@@ -597,7 +595,7 @@
597
595
  }
598
596
  function paginateAggregations(model, aggregations, params, metaProjection) {
599
597
  if (metaProjection === void 0) { metaProjection = {}; }
600
- return __awaiter$u(this, void 0, void 0, function () {
598
+ return __awaiter$v(this, void 0, void 0, function () {
601
599
  var sortField, sortAggregation, result, pagination;
602
600
  var _a;
603
601
  return __generator(this, function (_b) {
@@ -708,7 +706,7 @@
708
706
  }
709
707
  function readAndDeleteFile(path, timeout) {
710
708
  if (timeout === void 0) { timeout = 5000; }
711
- return __awaiter$u(this, void 0, void 0, function () {
709
+ return __awaiter$v(this, void 0, void 0, function () {
712
710
  var data;
713
711
  return __generator(this, function (_a) {
714
712
  switch (_a.label) {
@@ -725,7 +723,7 @@
725
723
  });
726
724
  }
727
725
  function writeFile(path$1, data) {
728
- return __awaiter$u(this, void 0, void 0, function () {
726
+ return __awaiter$v(this, void 0, void 0, function () {
729
727
  return __generator(this, function (_a) {
730
728
  switch (_a.label) {
731
729
  case 0: return [4 /*yield*/, mkdirRecursive(path.dirname(path$1))];
@@ -813,7 +811,7 @@
813
811
  var paramName = modelName.toLowerCase();
814
812
  return routingControllers.createParamDecorator({
815
813
  required: false,
816
- value: function (action) { return __awaiter$u(_this, void 0, void 0, function () {
814
+ value: function (action) { return __awaiter$v(_this, void 0, void 0, function () {
817
815
  var req, token, id, query, doc, _a, _b, e_3;
818
816
  return __generator(this, function (_c) {
819
817
  switch (_c.label) {
@@ -1188,7 +1186,7 @@
1188
1186
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1189
1187
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1190
1188
  };
1191
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1189
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1192
1190
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1193
1191
  return new (P || (P = Promise))(function (resolve, reject) {
1194
1192
  function fulfilled(value) { try {
@@ -1208,8 +1206,8 @@
1208
1206
  });
1209
1207
  };
1210
1208
  var AssetProcessor_1;
1211
- var sharp$3 = sharp___default['default'];
1212
- var fontKit = fontKit___default['default'];
1209
+ var sharp$3 = sharp___default["default"];
1210
+ var fontKit = fontKit___default["default"];
1213
1211
  var fontTypes = [
1214
1212
  "application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
1215
1213
  "font/woff", "font/woff2", "font/otf", "font/ttf", "font/datafork"
@@ -1225,7 +1223,7 @@
1225
1223
  function AssetProcessor() {
1226
1224
  }
1227
1225
  AssetProcessor.getMimeType = function (buffer, mimeType) {
1228
- return __awaiter$t(this, void 0, void 0, function () {
1226
+ return __awaiter$u(this, void 0, void 0, function () {
1229
1227
  var e_1;
1230
1228
  return __generator(this, function (_a) {
1231
1229
  switch (_a.label) {
@@ -1266,7 +1264,7 @@
1266
1264
  return imageTypes.indexOf(contentType) >= 0;
1267
1265
  };
1268
1266
  AssetProcessor.copyImageMeta = function (buffer, metadata) {
1269
- return __awaiter$t(this, void 0, void 0, function () {
1267
+ return __awaiter$u(this, void 0, void 0, function () {
1270
1268
  var output;
1271
1269
  return __generator(this, function (_a) {
1272
1270
  switch (_a.label) {
@@ -1290,7 +1288,7 @@
1290
1288
  });
1291
1289
  };
1292
1290
  AssetProcessor.prototype.process = function (buffer, metadata, contentType) {
1293
- return __awaiter$t(this, void 0, void 0, function () {
1291
+ return __awaiter$u(this, void 0, void 0, function () {
1294
1292
  return __generator(this, function (_a) {
1295
1293
  switch (_a.label) {
1296
1294
  case 0:
@@ -1335,7 +1333,7 @@
1335
1333
  exports.Configuration = /** @class */ (function () {
1336
1334
  function Configuration(params) {
1337
1335
  var _this = this;
1338
- dotenv__default['default'].config();
1336
+ dotenv__default["default"].config();
1339
1337
  this.paramMap = {};
1340
1338
  (params || []).forEach(function (param) { return _this.add(param); });
1341
1339
  }
@@ -1386,7 +1384,7 @@
1386
1384
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
1387
1385
  return Reflect.metadata(k, v);
1388
1386
  };
1389
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1387
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1390
1388
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1391
1389
  return new (P || (P = Promise))(function (resolve, reject) {
1392
1390
  function fulfilled(value) { try {
@@ -1434,7 +1432,7 @@
1434
1432
  configurable: true
1435
1433
  });
1436
1434
  MongoConnector.prototype.connect = function () {
1437
- return __awaiter$s(this, void 0, void 0, function () {
1435
+ return __awaiter$t(this, void 0, void 0, function () {
1438
1436
  var _a;
1439
1437
  return __generator(this, function (_b) {
1440
1438
  switch (_b.label) {
@@ -1466,6 +1464,65 @@
1466
1464
  __metadata$o("design:paramtypes", [exports.Configuration])
1467
1465
  ], exports.MongoConnector);
1468
1466
 
1467
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1468
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1469
+ return new (P || (P = Promise))(function (resolve, reject) {
1470
+ function fulfilled(value) { try {
1471
+ step(generator.next(value));
1472
+ }
1473
+ catch (e) {
1474
+ reject(e);
1475
+ } }
1476
+ function rejected(value) { try {
1477
+ step(generator["throw"](value));
1478
+ }
1479
+ catch (e) {
1480
+ reject(e);
1481
+ } }
1482
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1483
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1484
+ });
1485
+ };
1486
+ var BaseEntity = /** @class */ (function () {
1487
+ function BaseEntity(mId, data, collection) {
1488
+ this.mId = mId;
1489
+ this.data = data;
1490
+ this.collection = collection;
1491
+ }
1492
+ Object.defineProperty(BaseEntity.prototype, "id", {
1493
+ get: function () {
1494
+ return this.mId.toHexString();
1495
+ },
1496
+ enumerable: false,
1497
+ configurable: true
1498
+ });
1499
+ BaseEntity.prototype.save = function () {
1500
+ return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1501
+ };
1502
+ BaseEntity.prototype.load = function () {
1503
+ return __awaiter$s(this, void 0, void 0, function () {
1504
+ var res;
1505
+ return __generator(this, function (_a) {
1506
+ switch (_a.label) {
1507
+ case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.mId })];
1508
+ case 1:
1509
+ res = _a.sent();
1510
+ this.deleted = !res;
1511
+ this.data = res || {};
1512
+ return [2 /*return*/, this];
1513
+ }
1514
+ });
1515
+ });
1516
+ };
1517
+ BaseEntity.prototype.toJSON = function () {
1518
+ var ret = Object.assign({}, this.data);
1519
+ delete ret._id;
1520
+ ret.id = this.id;
1521
+ return ret;
1522
+ };
1523
+ return BaseEntity;
1524
+ }());
1525
+
1469
1526
  var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1470
1527
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1471
1528
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1485,21 +1542,19 @@
1485
1542
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1486
1543
  });
1487
1544
  };
1488
- var sharp$2 = sharp___default['default'];
1545
+ var sharp$2 = sharp___default["default"];
1489
1546
  var cropInterface = {
1490
1547
  x: "number",
1491
1548
  y: "number",
1492
1549
  w: "number",
1493
1550
  h: "number"
1494
1551
  };
1495
- var Asset = /** @class */ (function () {
1496
- function Asset(fileId, filename, contentType, metadata, bucket, collection) {
1497
- this.fileId = fileId;
1498
- this.filename = filename;
1499
- this.contentType = contentType;
1500
- this.metadata = metadata;
1501
- this.bucket = bucket;
1502
- this.collection = collection;
1552
+ var Asset = /** @class */ (function (_super) {
1553
+ __extends(Asset, _super);
1554
+ function Asset(id, data, collection, bucket) {
1555
+ var _this = _super.call(this, id, data, collection) || this;
1556
+ _this.bucket = bucket;
1557
+ return _this;
1503
1558
  }
1504
1559
  Asset.toCropRegion = function (cropInfo) {
1505
1560
  var crop = cropInfo;
@@ -1614,16 +1669,30 @@
1614
1669
  });
1615
1670
  });
1616
1671
  };
1617
- Object.defineProperty(Asset.prototype, "id", {
1672
+ Object.defineProperty(Asset.prototype, "filename", {
1673
+ get: function () {
1674
+ return this.data.filename;
1675
+ },
1676
+ enumerable: false,
1677
+ configurable: true
1678
+ });
1679
+ Object.defineProperty(Asset.prototype, "contentType", {
1618
1680
  get: function () {
1619
- return this.fileId.toHexString();
1681
+ return this.data.contentType;
1682
+ },
1683
+ enumerable: false,
1684
+ configurable: true
1685
+ });
1686
+ Object.defineProperty(Asset.prototype, "metadata", {
1687
+ get: function () {
1688
+ return this.data.metadata;
1620
1689
  },
1621
1690
  enumerable: false,
1622
1691
  configurable: true
1623
1692
  });
1624
1693
  Object.defineProperty(Asset.prototype, "stream", {
1625
1694
  get: function () {
1626
- return this.bucket.openDownloadStream(this.fileId);
1695
+ return this.bucket.openDownloadStream(this.mId);
1627
1696
  },
1628
1697
  enumerable: false,
1629
1698
  configurable: true
@@ -1631,7 +1700,7 @@
1631
1700
  Asset.prototype.unlink = function () {
1632
1701
  return __awaiter$r(this, void 0, void 0, function () {
1633
1702
  return __generator(this, function (_a) {
1634
- return [2 /*return*/, deleteFromBucket(this.bucket, this.fileId)];
1703
+ return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
1635
1704
  });
1636
1705
  });
1637
1706
  };
@@ -1649,7 +1718,7 @@
1649
1718
  : metadata.downloadCount + 1;
1650
1719
  metadata.firstDownload = metadata.firstDownload || new Date();
1651
1720
  metadata.lastDownload = new Date();
1652
- return [4 /*yield*/, this.collection.updateOne({ _id: this.fileId }, { $set: { metadata: metadata } })];
1721
+ return [4 /*yield*/, this.collection.updateOne({ _id: this.mId }, { $set: { metadata: metadata } })];
1653
1722
  case 1:
1654
1723
  _a.sent();
1655
1724
  return [2 /*return*/, this.stream];
@@ -1678,16 +1747,8 @@
1678
1747
  });
1679
1748
  });
1680
1749
  };
1681
- Asset.prototype.toJSON = function () {
1682
- return {
1683
- id: this.id,
1684
- filename: this.filename,
1685
- contentType: this.contentType,
1686
- metadata: this.metadata
1687
- };
1688
- };
1689
1750
  return Asset;
1690
- }());
1751
+ }(BaseEntity));
1691
1752
 
1692
1753
  var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
1693
1754
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1775,8 +1836,12 @@
1775
1836
  reject(error.message || error);
1776
1837
  })
1777
1838
  .on("finish", function () {
1778
- var asset = new Asset(uploaderStream.id, metadata.filename, contentType, metadata, _this.bucket, _this.collection);
1779
- _this.collection.updateOne({ _id: uploaderStream.id }, { $set: asset.toJSON() }).then(function () {
1839
+ var asset = new Asset(uploaderStream.id, {
1840
+ filename: metadata.filename,
1841
+ contentType: contentType,
1842
+ metadata: metadata
1843
+ }, _this.collection, _this.bucket);
1844
+ asset.save().then(function () {
1780
1845
  resolve(asset);
1781
1846
  }, function (error) {
1782
1847
  reject(error.message || error);
@@ -1811,7 +1876,7 @@
1811
1876
  var buffer;
1812
1877
  return __generator(this, function (_b) {
1813
1878
  switch (_b.label) {
1814
- case 0: return [4 /*yield*/, axios__default['default']({ url: url, responseType: "arraybuffer" })];
1879
+ case 0: return [4 /*yield*/, axios__default["default"]({ url: url, responseType: "arraybuffer" })];
1815
1880
  case 1:
1816
1881
  buffer = (_b.sent()).data;
1817
1882
  return [2 /*return*/, this.writeBuffer(buffer, metadata)];
@@ -1834,7 +1899,7 @@
1834
1899
  case 0: return [4 /*yield*/, this.collection.findOne(where)];
1835
1900
  case 1:
1836
1901
  data = _b.sent();
1837
- return [2 /*return*/, !data ? null : new Asset(data._id, data.filename, data.contentType, data.metadata, this.bucket, this.collection)];
1902
+ return [2 /*return*/, !data ? null : new Asset(data._id, data, this.collection, this.bucket)];
1838
1903
  }
1839
1904
  });
1840
1905
  });
@@ -1881,36 +1946,46 @@
1881
1946
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1882
1947
  });
1883
1948
  };
1884
- var LazyAsset = /** @class */ (function () {
1885
- function LazyAsset(lazyId, jobName, jobParams, jobQue, mProgressId, mAssetId, assets, progresses, jobMan, collection) {
1886
- this.lazyId = lazyId;
1887
- this.jobName = jobName;
1888
- this.jobParams = jobParams;
1889
- this.jobQue = jobQue;
1890
- this.mProgressId = mProgressId;
1891
- this.mAssetId = mAssetId;
1892
- this.assets = assets;
1893
- this.progresses = progresses;
1894
- this.jobMan = jobMan;
1895
- this.collection = collection;
1949
+ var LazyAsset = /** @class */ (function (_super) {
1950
+ __extends(LazyAsset, _super);
1951
+ function LazyAsset(id, data, collection, assets, progresses, jobMan) {
1952
+ var _this = _super.call(this, id, data, collection) || this;
1953
+ _this.assets = assets;
1954
+ _this.progresses = progresses;
1955
+ _this.jobMan = jobMan;
1956
+ return _this;
1896
1957
  }
1897
- Object.defineProperty(LazyAsset.prototype, "id", {
1958
+ Object.defineProperty(LazyAsset.prototype, "jobName", {
1959
+ get: function () {
1960
+ return this.data.jobName;
1961
+ },
1962
+ enumerable: false,
1963
+ configurable: true
1964
+ });
1965
+ Object.defineProperty(LazyAsset.prototype, "jobParams", {
1898
1966
  get: function () {
1899
- return this.lazyId.toHexString();
1967
+ return this.data.jobParams;
1968
+ },
1969
+ enumerable: false,
1970
+ configurable: true
1971
+ });
1972
+ Object.defineProperty(LazyAsset.prototype, "jobQue", {
1973
+ get: function () {
1974
+ return this.data.jobQue;
1900
1975
  },
1901
1976
  enumerable: false,
1902
1977
  configurable: true
1903
1978
  });
1904
1979
  Object.defineProperty(LazyAsset.prototype, "progressId", {
1905
1980
  get: function () {
1906
- return this.mProgressId;
1981
+ return this.data.progressId;
1907
1982
  },
1908
1983
  enumerable: false,
1909
1984
  configurable: true
1910
1985
  });
1911
1986
  Object.defineProperty(LazyAsset.prototype, "assetId", {
1912
1987
  get: function () {
1913
- return this.mAssetId;
1988
+ return this.data.assetId;
1914
1989
  },
1915
1990
  enumerable: false,
1916
1991
  configurable: true
@@ -1919,41 +1994,50 @@
1919
1994
  return __awaiter$p(this, void 0, void 0, function () {
1920
1995
  return __generator(this, function (_a) {
1921
1996
  switch (_a.label) {
1922
- case 0: return [4 /*yield*/, this.collection.deleteOne({ _id: this.lazyId })];
1997
+ case 0: return [4 /*yield*/, this.load()];
1923
1998
  case 1:
1924
1999
  _a.sent();
1925
- return [2 /*return*/, deleteFromBucket(this.assets.bucket, new bson.ObjectId(this.mAssetId))];
2000
+ if (!!this.progressId) return [3 /*break*/, 3];
2001
+ return [4 /*yield*/, this.collection.deleteOne({ _id: this.mId })];
2002
+ case 2:
2003
+ _a.sent();
2004
+ _a.label = 3;
2005
+ case 3: return [2 /*return*/, deleteFromBucket(this.assets.bucket, new bson.ObjectId(this.assetId))];
1926
2006
  }
1927
2007
  });
1928
2008
  });
1929
2009
  };
1930
2010
  LazyAsset.prototype.startWorking = function () {
1931
2011
  var _this = this;
1932
- if (this.mProgressId)
1933
- return;
1934
- this.startWorkingOnAsset().then(function () {
1935
- console.log("Started working on lazy asset: " + _this.id);
1936
- }).catch(function (reason) {
1937
- console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
2012
+ this.load().then(function () {
2013
+ if (_this.deleted)
2014
+ return;
2015
+ var progressPromise = !_this.progressId ? Promise.resolve(null) : _this.progresses.get(_this.progressId).then(function (p) { return p.cancel(); });
2016
+ progressPromise.then(function () {
2017
+ _this.startWorkingOnAsset().then(function () {
2018
+ console.log("Started working on lazy asset: " + _this.id);
2019
+ }).catch(function (reason) {
2020
+ console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
2021
+ });
2022
+ });
1938
2023
  });
1939
2024
  };
1940
2025
  LazyAsset.prototype.loadAsset = function () {
1941
2026
  return __awaiter$p(this, void 0, void 0, function () {
1942
- var data;
1943
2027
  return __generator(this, function (_a) {
1944
2028
  switch (_a.label) {
1945
- case 0:
1946
- if (this.mAssetId) {
1947
- return [2 /*return*/, this.assets.read(this.mAssetId)];
1948
- }
1949
- if (!this.mProgressId) return [3 /*break*/, 3];
1950
- return [4 /*yield*/, this.progresses.waitToFinish(this.mProgressId)];
2029
+ case 0: return [4 /*yield*/, this.load()];
1951
2030
  case 1:
1952
2031
  _a.sent();
1953
- return [4 /*yield*/, this.collection.findOne({ _id: this.lazyId })];
2032
+ if (this.deleted)
2033
+ return [2 /*return*/, null];
2034
+ if (this.assetId) {
2035
+ return [2 /*return*/, this.assets.read(this.assetId)];
2036
+ }
2037
+ if (!this.progressId) return [3 /*break*/, 3];
2038
+ return [4 /*yield*/, this.progresses.waitToFinish(this.progressId)];
1954
2039
  case 2:
1955
- data = _a.sent();
1956
- this.mAssetId = data.assetId;
2040
+ _a.sent();
1957
2041
  return [2 /*return*/, this.loadAsset()];
1958
2042
  case 3: return [4 /*yield*/, this.startWorkingOnAsset()];
1959
2043
  case 4:
@@ -1968,7 +2052,7 @@
1968
2052
  return __generator(this, function (_a) {
1969
2053
  switch (_a.label) {
1970
2054
  case 0:
1971
- this.mAssetId = asset.id;
2055
+ this.data.assetId = asset.id;
1972
2056
  return [4 /*yield*/, this.save()];
1973
2057
  case 1:
1974
2058
  _a.sent();
@@ -1977,32 +2061,19 @@
1977
2061
  });
1978
2062
  });
1979
2063
  };
1980
- LazyAsset.prototype.save = function () {
1981
- return this.collection.updateOne({ _id: this.lazyId }, { $set: this.toJSON() });
1982
- };
1983
- LazyAsset.prototype.toJSON = function () {
1984
- return {
1985
- id: this.id,
1986
- jobName: this.jobName,
1987
- jobParams: this.jobParams,
1988
- jobQue: this.jobQue,
1989
- progressId: this.progressId,
1990
- assetId: this.assetId,
1991
- };
1992
- };
1993
2064
  LazyAsset.prototype.startWorkingOnAsset = function () {
1994
2065
  return __awaiter$p(this, void 0, void 0, function () {
1995
- var progress;
2066
+ var id;
1996
2067
  return __generator(this, function (_a) {
1997
2068
  switch (_a.label) {
1998
2069
  case 0: return [4 /*yield*/, this.progresses.create()];
1999
2070
  case 1:
2000
- progress = _a.sent();
2001
- this.mProgressId = progress.id;
2071
+ id = (_a.sent()).id;
2072
+ this.data.progressId = id;
2002
2073
  return [4 /*yield*/, this.save()];
2003
2074
  case 2:
2004
2075
  _a.sent();
2005
- return [4 /*yield*/, this.jobMan.enqueueWithName(this.jobName, Object.assign(Object.assign({}, this.jobParams), { lazyId: this.id }))];
2076
+ return [4 /*yield*/, this.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id }))];
2006
2077
  case 3:
2007
2078
  _a.sent();
2008
2079
  return [2 /*return*/];
@@ -2011,7 +2082,7 @@
2011
2082
  });
2012
2083
  };
2013
2084
  return LazyAsset;
2014
- }());
2085
+ }(BaseEntity));
2015
2086
 
2016
2087
  var __decorate$s = (this && this.__decorate) || function (decorators, target, key, desc) {
2017
2088
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2049,7 +2120,7 @@
2049
2120
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2050
2121
  });
2051
2122
  };
2052
- var IORedis = ioredis__default['default'];
2123
+ var IORedis = ioredis__default["default"];
2053
2124
  exports.JobManager = /** @class */ (function () {
2054
2125
  function JobManager(config, container, jobTypes) {
2055
2126
  var _this = this;
@@ -2322,61 +2393,58 @@
2322
2393
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2323
2394
  });
2324
2395
  };
2325
- var Progress = /** @class */ (function () {
2326
- function Progress(progressId, mCurrent, mMax, mMessage, mError, client, collection) {
2327
- this.progressId = progressId;
2328
- this.mCurrent = mCurrent;
2329
- this.mMax = mMax;
2330
- this.mMessage = mMessage;
2331
- this.mError = mError;
2332
- this.client = client;
2333
- this.collection = collection;
2396
+ var Progress = /** @class */ (function (_super) {
2397
+ __extends(Progress, _super);
2398
+ function Progress(id, data, collection, client) {
2399
+ var _this = _super.call(this, id, data, collection) || this;
2400
+ _this.client = client;
2401
+ return _this;
2334
2402
  }
2335
- Object.defineProperty(Progress.prototype, "id", {
2403
+ Object.defineProperty(Progress.prototype, "current", {
2336
2404
  get: function () {
2337
- return this.progressId.toHexString();
2405
+ return this.data.current;
2338
2406
  },
2339
2407
  enumerable: false,
2340
2408
  configurable: true
2341
2409
  });
2342
- Object.defineProperty(Progress.prototype, "current", {
2410
+ Object.defineProperty(Progress.prototype, "max", {
2343
2411
  get: function () {
2344
- return this.mCurrent;
2412
+ return this.data.max;
2345
2413
  },
2346
2414
  enumerable: false,
2347
2415
  configurable: true
2348
2416
  });
2349
- Object.defineProperty(Progress.prototype, "max", {
2417
+ Object.defineProperty(Progress.prototype, "message", {
2350
2418
  get: function () {
2351
- return this.mMax;
2419
+ return this.data.message;
2352
2420
  },
2353
2421
  enumerable: false,
2354
2422
  configurable: true
2355
2423
  });
2356
- Object.defineProperty(Progress.prototype, "message", {
2424
+ Object.defineProperty(Progress.prototype, "error", {
2357
2425
  get: function () {
2358
- return this.mMessage;
2426
+ return this.data.error;
2359
2427
  },
2360
2428
  enumerable: false,
2361
2429
  configurable: true
2362
2430
  });
2363
- Object.defineProperty(Progress.prototype, "error", {
2431
+ Object.defineProperty(Progress.prototype, "canceled", {
2364
2432
  get: function () {
2365
- return this.mError;
2433
+ return this.data.canceled;
2366
2434
  },
2367
2435
  enumerable: false,
2368
2436
  configurable: true
2369
2437
  });
2370
2438
  Object.defineProperty(Progress.prototype, "percent", {
2371
2439
  get: function () {
2372
- return this.mMax > 0 ? Math.round(this.mCurrent / this.mMax * 100) : 0;
2440
+ return this.max > 0 ? Math.round(this.current / this.max * 100) : 0;
2373
2441
  },
2374
2442
  enumerable: false,
2375
2443
  configurable: true
2376
2444
  });
2377
2445
  Object.defineProperty(Progress.prototype, "remaining", {
2378
2446
  get: function () {
2379
- return this.mMax > 0 ? this.mMax - this.mCurrent : 0;
2447
+ return this.max > 0 ? this.max - this.current : 0;
2380
2448
  },
2381
2449
  enumerable: false,
2382
2450
  configurable: true
@@ -2393,12 +2461,12 @@
2393
2461
  _a.label = 2;
2394
2462
  case 2:
2395
2463
  if (!(message !== null)) return [3 /*break*/, 4];
2396
- this.mMessage = message;
2464
+ this.data.message = message;
2397
2465
  return [4 /*yield*/, this.save()];
2398
2466
  case 3:
2399
2467
  _a.sent();
2400
2468
  _a.label = 4;
2401
- case 4: return [2 /*return*/, new SubProgress(this, this.mCurrent, progressValue, Math.max(max, 1))];
2469
+ case 4: return [2 /*return*/, new SubProgress(this, this.current, progressValue, Math.max(max, 1))];
2402
2470
  }
2403
2471
  });
2404
2472
  });
@@ -2411,7 +2479,21 @@
2411
2479
  if (isNaN(max) || max <= 0) {
2412
2480
  throw "Max progress value must be bigger than zero";
2413
2481
  }
2414
- this.mMax = max;
2482
+ this.data.max = max;
2483
+ return [4 /*yield*/, this.save()];
2484
+ case 1:
2485
+ _a.sent();
2486
+ return [2 /*return*/];
2487
+ }
2488
+ });
2489
+ });
2490
+ };
2491
+ Progress.prototype.setMessage = function (message) {
2492
+ return __awaiter$n(this, void 0, void 0, function () {
2493
+ return __generator(this, function (_a) {
2494
+ switch (_a.label) {
2495
+ case 0:
2496
+ this.data.message = message;
2415
2497
  return [4 /*yield*/, this.save()];
2416
2498
  case 1:
2417
2499
  _a.sent();
@@ -2425,7 +2507,7 @@
2425
2507
  return __generator(this, function (_a) {
2426
2508
  switch (_a.label) {
2427
2509
  case 0:
2428
- this.mError = error;
2510
+ this.data.error = error;
2429
2511
  return [4 /*yield*/, this.save()];
2430
2512
  case 1:
2431
2513
  _a.sent();
@@ -2443,9 +2525,14 @@
2443
2525
  if (isNaN(value) || value <= 0) {
2444
2526
  throw "Advance value must be bigger than zero";
2445
2527
  }
2446
- this.mCurrent = Math.min(this.mMax, this.mCurrent + value);
2447
- return [4 /*yield*/, this.save()];
2528
+ return [4 /*yield*/, this.load()];
2448
2529
  case 1:
2530
+ _a.sent();
2531
+ if (this.deleted || this.canceled)
2532
+ return [2 /*return*/, null];
2533
+ this.data.current = Math.min(this.max, this.current + value);
2534
+ return [4 /*yield*/, this.save()];
2535
+ case 2:
2449
2536
  _a.sent();
2450
2537
  if (!this.client)
2451
2538
  return [2 /*return*/];
@@ -2455,34 +2542,36 @@
2455
2542
  });
2456
2543
  });
2457
2544
  };
2458
- Progress.prototype.toJSON = function () {
2459
- return {
2460
- id: this.id,
2461
- current: this.current,
2462
- max: this.max,
2463
- message: this.message,
2464
- error: this.error
2465
- };
2466
- };
2467
- Progress.prototype.save = function () {
2468
- return this.collection.updateOne({ _id: this.progressId }, { $set: this.toJSON() });
2545
+ Progress.prototype.cancel = function () {
2546
+ return __awaiter$n(this, void 0, void 0, function () {
2547
+ return __generator(this, function (_a) {
2548
+ switch (_a.label) {
2549
+ case 0:
2550
+ this.data.canceled = true;
2551
+ return [4 /*yield*/, this.save()];
2552
+ case 1:
2553
+ _a.sent();
2554
+ return [2 /*return*/];
2555
+ }
2556
+ });
2557
+ });
2469
2558
  };
2470
2559
  return Progress;
2471
- }());
2560
+ }(BaseEntity));
2472
2561
  var SubProgress = /** @class */ (function () {
2473
- function SubProgress(parent, progressFrom, progressValue, max) {
2474
- if (max === void 0) { max = 100; }
2562
+ function SubProgress(parent, progressFrom, progressValue, mMax) {
2563
+ if (mMax === void 0) { mMax = 100; }
2475
2564
  this.parent = parent;
2476
2565
  this.progressFrom = progressFrom;
2477
2566
  this.progressValue = progressValue;
2478
- this.max = max;
2567
+ this.mMax = mMax;
2479
2568
  if (progressFrom < 0) {
2480
2569
  throw "Progress from must be bigger than or zero";
2481
2570
  }
2482
2571
  if (progressValue <= 0) {
2483
2572
  throw "Progress value must be bigger than zero";
2484
2573
  }
2485
- this.currentValue = 0;
2574
+ this.mCurrent = 0;
2486
2575
  }
2487
2576
  Object.defineProperty(SubProgress.prototype, "id", {
2488
2577
  get: function () {
@@ -2491,13 +2580,24 @@
2491
2580
  enumerable: false,
2492
2581
  configurable: true
2493
2582
  });
2583
+ Object.defineProperty(SubProgress.prototype, "current", {
2584
+ get: function () {
2585
+ return this.mCurrent;
2586
+ },
2587
+ enumerable: false,
2588
+ configurable: true
2589
+ });
2590
+ Object.defineProperty(SubProgress.prototype, "max", {
2591
+ get: function () {
2592
+ return this.mMax;
2593
+ },
2594
+ enumerable: false,
2595
+ configurable: true
2596
+ });
2494
2597
  Object.defineProperty(SubProgress.prototype, "message", {
2495
2598
  get: function () {
2496
2599
  return this.parent.message;
2497
2600
  },
2498
- set: function (value) {
2499
- this.parent.message = value;
2500
- },
2501
2601
  enumerable: false,
2502
2602
  configurable: true
2503
2603
  });
@@ -2505,9 +2605,6 @@
2505
2605
  get: function () {
2506
2606
  return this.parent.error;
2507
2607
  },
2508
- set: function (value) {
2509
- this.parent.error = value;
2510
- },
2511
2608
  enumerable: false,
2512
2609
  configurable: true
2513
2610
  });
@@ -2518,16 +2615,16 @@
2518
2615
  enumerable: false,
2519
2616
  configurable: true
2520
2617
  });
2521
- Object.defineProperty(SubProgress.prototype, "current", {
2618
+ Object.defineProperty(SubProgress.prototype, "remaining", {
2522
2619
  get: function () {
2523
- return this.currentValue;
2620
+ return this.max - this.mCurrent;
2524
2621
  },
2525
2622
  enumerable: false,
2526
2623
  configurable: true
2527
2624
  });
2528
- Object.defineProperty(SubProgress.prototype, "remaining", {
2625
+ Object.defineProperty(SubProgress.prototype, "canceled", {
2529
2626
  get: function () {
2530
- return this.max - this.currentValue;
2627
+ return !this.parent || this.parent.canceled;
2531
2628
  },
2532
2629
  enumerable: false,
2533
2630
  configurable: true
@@ -2544,8 +2641,7 @@
2544
2641
  _a.label = 2;
2545
2642
  case 2:
2546
2643
  if (!(message !== null)) return [3 /*break*/, 4];
2547
- this.message = message;
2548
- return [4 /*yield*/, this.parent.save()];
2644
+ return [4 /*yield*/, this.setMessage(message)];
2549
2645
  case 3:
2550
2646
  _a.sent();
2551
2647
  _a.label = 4;
@@ -2562,7 +2658,7 @@
2562
2658
  if (isNaN(max) || max <= 0) {
2563
2659
  throw "Max progress value must be bigger than zero";
2564
2660
  }
2565
- this.max = max;
2661
+ this.mMax = max;
2566
2662
  return [4 /*yield*/, this.save()];
2567
2663
  case 1:
2568
2664
  _a.sent();
@@ -2571,13 +2667,29 @@
2571
2667
  });
2572
2668
  });
2573
2669
  };
2670
+ SubProgress.prototype.setMessage = function (message) {
2671
+ return __awaiter$n(this, void 0, void 0, function () {
2672
+ return __generator(this, function (_a) {
2673
+ switch (_a.label) {
2674
+ case 0:
2675
+ if (!this.parent)
2676
+ return [2 /*return*/, null];
2677
+ return [4 /*yield*/, this.parent.setMessage(message)];
2678
+ case 1:
2679
+ _a.sent();
2680
+ return [2 /*return*/];
2681
+ }
2682
+ });
2683
+ });
2684
+ };
2574
2685
  SubProgress.prototype.setError = function (error) {
2575
2686
  return __awaiter$n(this, void 0, void 0, function () {
2576
2687
  return __generator(this, function (_a) {
2577
2688
  switch (_a.label) {
2578
2689
  case 0:
2579
- this.error = error || null;
2580
- return [4 /*yield*/, this.save()];
2690
+ if (!this.parent)
2691
+ return [2 /*return*/, null];
2692
+ return [4 /*yield*/, this.parent.setError(error)];
2581
2693
  case 1:
2582
2694
  _a.sent();
2583
2695
  return [2 /*return*/];
@@ -2594,7 +2706,7 @@
2594
2706
  if (isNaN(value) || value <= 0) {
2595
2707
  throw "Advance value must be bigger than zero";
2596
2708
  }
2597
- this.currentValue = Math.min(this.max, this.currentValue + value);
2709
+ this.mCurrent = Math.min(this.max, this.mCurrent + value);
2598
2710
  return [4 /*yield*/, this.save()];
2599
2711
  case 1:
2600
2712
  _a.sent();
@@ -2603,13 +2715,28 @@
2603
2715
  });
2604
2716
  });
2605
2717
  };
2718
+ SubProgress.prototype.cancel = function () {
2719
+ return __awaiter$n(this, void 0, void 0, function () {
2720
+ return __generator(this, function (_a) {
2721
+ switch (_a.label) {
2722
+ case 0:
2723
+ if (!this.parent)
2724
+ return [2 /*return*/, null];
2725
+ return [4 /*yield*/, this.parent.cancel()];
2726
+ case 1:
2727
+ _a.sent();
2728
+ return [2 /*return*/];
2729
+ }
2730
+ });
2731
+ });
2732
+ };
2606
2733
  SubProgress.prototype.save = function () {
2607
2734
  return __awaiter$n(this, void 0, void 0, function () {
2608
2735
  var ratio, newProgress, current;
2609
2736
  return __generator(this, function (_a) {
2610
2737
  switch (_a.label) {
2611
2738
  case 0:
2612
- ratio = this.max > 0 ? this.currentValue / this.max : 0;
2739
+ ratio = this.max > 0 ? this.mCurrent / this.max : 0;
2613
2740
  newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
2614
2741
  current = this.parent.current;
2615
2742
  if (newProgress <= current)
@@ -2622,6 +2749,13 @@
2622
2749
  });
2623
2750
  });
2624
2751
  };
2752
+ SubProgress.prototype.load = function () {
2753
+ return __awaiter$n(this, void 0, void 0, function () {
2754
+ return __generator(this, function (_a) {
2755
+ return [2 /*return*/, null];
2756
+ });
2757
+ });
2758
+ };
2625
2759
  SubProgress.prototype.toJSON = function () {
2626
2760
  return this.parent.toJSON();
2627
2761
  };
@@ -2661,7 +2795,7 @@
2661
2795
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2662
2796
  });
2663
2797
  };
2664
- var socketIOClient = socket_io_client__default['default'];
2798
+ var socketIOClient = socket_io_client__default["default"];
2665
2799
  exports.Progresses = /** @class */ (function () {
2666
2800
  function Progresses(connector, config) {
2667
2801
  this.connector = connector;
@@ -2717,7 +2851,7 @@
2717
2851
  case 0: return [4 /*yield*/, this.collection.findOne(where)];
2718
2852
  case 1:
2719
2853
  data = _a.sent();
2720
- return [2 /*return*/, !data ? null : new Progress(data._id, data.current, data.max, data.message, data.error, this.client, this.collection)];
2854
+ return [2 /*return*/, !data ? null : new Progress(data._id, data, this.collection, this.client)];
2721
2855
  }
2722
2856
  });
2723
2857
  });
@@ -2725,20 +2859,24 @@
2725
2859
  Progresses.prototype.create = function (max) {
2726
2860
  if (max === void 0) { max = 100; }
2727
2861
  return __awaiter$m(this, void 0, void 0, function () {
2728
- var res;
2862
+ var data, res;
2729
2863
  return __generator(this, function (_a) {
2730
2864
  switch (_a.label) {
2731
2865
  case 0:
2732
2866
  if (isNaN(max) || max <= 0) {
2733
2867
  throw "Max progress value must be bigger than zero";
2734
2868
  }
2735
- return [4 /*yield*/, this.collection.insertOne({
2736
- current: 0,
2737
- max: max
2738
- })];
2869
+ data = {
2870
+ current: 0,
2871
+ max: max,
2872
+ message: "",
2873
+ error: "",
2874
+ canceled: false
2875
+ };
2876
+ return [4 /*yield*/, this.collection.insertOne(data)];
2739
2877
  case 1:
2740
2878
  res = _a.sent();
2741
- return [2 /*return*/, new Progress(res.insertedId, 0, max, "", "", this.client, this.collection)];
2879
+ return [2 /*return*/, new Progress(res.insertedId, data, this.collection, this.client)];
2742
2880
  }
2743
2881
  });
2744
2882
  });
@@ -2808,19 +2946,25 @@
2808
2946
  if (jobParams === void 0) { jobParams = {}; }
2809
2947
  if (jobQue === void 0) { jobQue = "main"; }
2810
2948
  return __awaiter$l(this, void 0, void 0, function () {
2811
- var jobName, res;
2949
+ var jobName, data, existingAsset, res;
2812
2950
  return __generator(this, function (_a) {
2813
2951
  switch (_a.label) {
2814
2952
  case 0:
2815
2953
  jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
2816
- return [4 /*yield*/, this.collection.insertOne({
2817
- jobName: jobName,
2818
- jobParams: jobParams,
2819
- jobQue: jobQue
2820
- })];
2954
+ data = {
2955
+ jobName: jobName,
2956
+ jobParams: jobParams,
2957
+ jobQue: jobQue
2958
+ };
2959
+ return [4 /*yield*/, this.find(data)];
2821
2960
  case 1:
2961
+ existingAsset = _a.sent();
2962
+ if (existingAsset)
2963
+ return [2 /*return*/, existingAsset];
2964
+ return [4 /*yield*/, this.collection.insertOne(data)];
2965
+ case 2:
2822
2966
  res = _a.sent();
2823
- return [2 /*return*/, new LazyAsset(res.insertedId, jobName, jobParams, jobQue, null, null, this.assets, this.progresses, this.jobMan, this.collection)];
2967
+ return [2 /*return*/, new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses, this.jobMan)];
2824
2968
  }
2825
2969
  });
2826
2970
  });
@@ -2842,7 +2986,7 @@
2842
2986
  data = _a.sent();
2843
2987
  return [2 /*return*/, !data
2844
2988
  ? null
2845
- : new LazyAsset(data._id, data.jobName, data.jobParams, data.jobQue, data.progressId, data.assetId, this.assets, this.progresses, this.jobMan, this.collection)];
2989
+ : new LazyAsset(data._id, data, this.collection, this.assets, this.progresses, this.jobMan)];
2846
2990
  }
2847
2991
  });
2848
2992
  });
@@ -2961,8 +3105,8 @@
2961
3105
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
2962
3106
  return Reflect.metadata(k, v);
2963
3107
  };
2964
- var express = express___default['default'];
2965
- var socketIO = socket_io__default['default'];
3108
+ var express = express___default["default"];
3109
+ var socketIO = socket_io__default["default"];
2966
3110
  exports.BackendProvider = /** @class */ (function () {
2967
3111
  function BackendProvider() {
2968
3112
  this.express = express();
@@ -3353,7 +3497,7 @@
3353
3497
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3354
3498
  });
3355
3499
  };
3356
- var sharp$1 = sharp___default['default'];
3500
+ var sharp$1 = sharp___default["default"];
3357
3501
  var bigSize = 1500;
3358
3502
  var thumbSize = 250;
3359
3503
  var GalleryImage = /** @class */ (function () {
@@ -3480,7 +3624,7 @@
3480
3624
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3481
3625
  });
3482
3626
  };
3483
- var sharp = sharp___default['default'];
3627
+ var sharp = sharp___default["default"];
3484
3628
  exports.Gallery = /** @class */ (function () {
3485
3629
  function Gallery(config, galleryCache) {
3486
3630
  this.config = config;
@@ -3719,7 +3863,7 @@
3719
3863
  this.cache = {};
3720
3864
  }
3721
3865
  TranslationProvider.prototype.getDictionary = function (language) {
3722
- this.cache[language] = this.cache[language] || axios__default['default'].get(this.config.resolve("translationsTemplate").replace("[lang]", language)).then(function (r) { return r.data; }, function (reason) { return ({
3866
+ this.cache[language] = this.cache[language] || axios__default["default"].get(this.config.resolve("translationsTemplate").replace("[lang]", language)).then(function (r) { return r.data; }, function (reason) { return ({
3723
3867
  message: reason
3724
3868
  }); });
3725
3869
  return this.cache[language];
@@ -4875,9 +5019,9 @@
4875
5019
  function RequestEndedMiddleware() {
4876
5020
  }
4877
5021
  RequestEndedMiddleware.prototype.use = function (request, response, next) {
4878
- request.ended = moment__default['default']();
5022
+ request.ended = moment__default["default"]();
4879
5023
  var diff = request.ended.diff(request.started);
4880
- var duration = moment__default['default'].duration(diff);
5024
+ var duration = moment__default["default"].duration(diff);
4881
5025
  console.log("Request '" + request.id + "' ended at: " + request.ended.format("YYYY-MM-DD HH:mm:ss") + " [" + request.method + "] " + request.url);
4882
5026
  console.log("Request '" + request.id + "' lasted: " + duration.asMilliseconds() + "ms");
4883
5027
  next(null);
@@ -4904,7 +5048,7 @@
4904
5048
  }
4905
5049
  RequestStartedMiddleware.prototype.use = function (request, response, next) {
4906
5050
  request.id = new bson.ObjectId().toHexString();
4907
- request.started = moment__default['default']();
5051
+ request.started = moment__default["default"]();
4908
5052
  console.log("Request '" + request.id + "' started at: " + request.started.format("YYYY-MM-DD HH:mm:ss") + " [" + request.method + "] " + request.url);
4909
5053
  next(null);
4910
5054
  };
@@ -5306,7 +5450,7 @@
5306
5450
  console.log(browserFolder, fs.existsSync(browserFolder));
5307
5451
  if (fs.existsSync(browserFolder)) {
5308
5452
  console.log("public_html exists. setting up static files serving...");
5309
- app.use(express_['static'](browserFolder, {
5453
+ app.use(express_["static"](browserFolder, {
5310
5454
  maxAge: "1y"
5311
5455
  }));
5312
5456
  }
@@ -5372,29 +5516,36 @@
5372
5516
  return [4 /*yield*/, this.progresses.get(lazyAsset.progressId)];
5373
5517
  case 2:
5374
5518
  progress = _a.sent();
5519
+ if (!progress || progress.canceled)
5520
+ return [2 /*return*/, null];
5375
5521
  _a.label = 3;
5376
5522
  case 3:
5377
- _a.trys.push([3, 6, , 8]);
5523
+ _a.trys.push([3, 7, , 9]);
5378
5524
  return [4 /*yield*/, this.generate(progress)];
5379
5525
  case 4:
5380
5526
  asset = _a.sent();
5381
- return [4 /*yield*/, lazyAsset.writeAsset(asset)];
5527
+ return [4 /*yield*/, progress.load()];
5382
5528
  case 5:
5383
- _a.sent();
5384
- return [3 /*break*/, 8];
5529
+ progress = _a.sent();
5530
+ if (!progress || progress.canceled)
5531
+ return [2 /*return*/, null];
5532
+ return [4 /*yield*/, lazyAsset.writeAsset(asset)];
5385
5533
  case 6:
5534
+ _a.sent();
5535
+ return [3 /*break*/, 9];
5536
+ case 7:
5386
5537
  e_1 = _a.sent();
5387
5538
  return [4 /*yield*/, progress.setError(e_1.message || e_1)];
5388
- case 7:
5539
+ case 8:
5389
5540
  _a.sent();
5390
5541
  throw e_1;
5391
- case 8:
5392
- if (!(progress.remaining > 0)) return [3 /*break*/, 10];
5393
- return [4 /*yield*/, progress.advance(progress.remaining)];
5394
5542
  case 9:
5543
+ if (!(progress.remaining > 0)) return [3 /*break*/, 11];
5544
+ return [4 /*yield*/, progress.advance(progress.remaining)];
5545
+ case 10:
5395
5546
  _a.sent();
5396
- _a.label = 10;
5397
- case 10: return [2 /*return*/];
5547
+ _a.label = 11;
5548
+ case 11: return [2 /*return*/];
5398
5549
  }
5399
5550
  });
5400
5551
  });
@@ -5799,5 +5950,5 @@
5799
5950
 
5800
5951
  Object.defineProperty(exports, '__esModule', { value: true });
5801
5952
 
5802
- })));
5953
+ }));
5803
5954
  //# sourceMappingURL=stemy-backend.umd.js.map