@stemy/backend 2.7.2 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/stemy-backend.umd.js +418 -190
- 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 +17 -8
- package/esm2015/common-types.js +1 -1
- package/esm2015/rest-controllers/assets.controller.js +22 -2
- package/esm2015/services/assets.js +28 -4
- package/esm2015/services/entities/asset.js +25 -28
- package/esm2015/services/entities/base-entity.js +37 -0
- package/esm2015/services/entities/lazy-asset.js +42 -45
- package/esm2015/services/entities/progress.js +72 -54
- package/esm2015/services/lazy-assets.js +9 -5
- package/esm2015/services/progresses.js +10 -6
- package/esm2015/utilities/lazy-asset-generator.js +7 -2
- package/fesm2015/stemy-backend.js +252 -150
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +1 -1
- package/rest-controllers/assets.controller.d.ts +1 -0
- package/services/assets.d.ts +2 -0
- package/services/entities/asset.d.ts +6 -9
- package/services/entities/base-entity.d.ts +13 -0
- package/services/entities/lazy-asset.d.ts +6 -12
- package/services/entities/progress.d.ts +18 -20
- package/stemy-backend.metadata.json +1 -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('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('
|
|
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', 'mongodb', 'dotenv', 'node-resque', 'node-cron', 'ioredis', 'socket.io-client', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', '
|
|
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.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.
|
|
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_, mongodb, dotenv, nodeResque, nodeCron, ioredis, socket_io_client, http, express_, socket_io, uuid, nodemailer, Handlebars,
|
|
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
|
+
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';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
|
|
27
27
|
var fontKit___default = /*#__PURE__*/_interopDefaultLegacy(fontKit_);
|
|
28
28
|
var sharp___default = /*#__PURE__*/_interopDefaultLegacy(sharp_);
|
|
29
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
29
30
|
var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
|
|
30
31
|
var ioredis__default = /*#__PURE__*/_interopDefaultLegacy(ioredis);
|
|
31
32
|
var socket_io_client__default = /*#__PURE__*/_interopDefaultLegacy(socket_io_client);
|
|
32
33
|
var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
|
|
33
34
|
var socket_io__default = /*#__PURE__*/_interopDefaultLegacy(socket_io);
|
|
34
35
|
var Handlebars__namespace = /*#__PURE__*/_interopNamespace(Handlebars);
|
|
35
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
36
36
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
37
37
|
|
|
38
38
|
/*! *****************************************************************************
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
107
107
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
108
108
|
}
|
|
109
|
-
function __awaiter$
|
|
109
|
+
function __awaiter$w(thisArg, _arguments, P, generator) {
|
|
110
110
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
111
111
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
112
112
|
function fulfilled(value) { try {
|
|
@@ -353,7 +353,7 @@
|
|
|
353
353
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
var __awaiter$
|
|
356
|
+
var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
357
357
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
358
358
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
359
359
|
function fulfilled(value) { try {
|
|
@@ -595,7 +595,7 @@
|
|
|
595
595
|
}
|
|
596
596
|
function paginateAggregations(model, aggregations, params, metaProjection) {
|
|
597
597
|
if (metaProjection === void 0) { metaProjection = {}; }
|
|
598
|
-
return __awaiter$
|
|
598
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
599
599
|
var sortField, sortAggregation, result, pagination;
|
|
600
600
|
var _a;
|
|
601
601
|
return __generator(this, function (_b) {
|
|
@@ -706,7 +706,7 @@
|
|
|
706
706
|
}
|
|
707
707
|
function readAndDeleteFile(path, timeout) {
|
|
708
708
|
if (timeout === void 0) { timeout = 5000; }
|
|
709
|
-
return __awaiter$
|
|
709
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
710
710
|
var data;
|
|
711
711
|
return __generator(this, function (_a) {
|
|
712
712
|
switch (_a.label) {
|
|
@@ -723,7 +723,7 @@
|
|
|
723
723
|
});
|
|
724
724
|
}
|
|
725
725
|
function writeFile(path$1, data) {
|
|
726
|
-
return __awaiter$
|
|
726
|
+
return __awaiter$v(this, void 0, void 0, function () {
|
|
727
727
|
return __generator(this, function (_a) {
|
|
728
728
|
switch (_a.label) {
|
|
729
729
|
case 0: return [4 /*yield*/, mkdirRecursive(path.dirname(path$1))];
|
|
@@ -811,7 +811,7 @@
|
|
|
811
811
|
var paramName = modelName.toLowerCase();
|
|
812
812
|
return routingControllers.createParamDecorator({
|
|
813
813
|
required: false,
|
|
814
|
-
value: function (action) { return __awaiter$
|
|
814
|
+
value: function (action) { return __awaiter$v(_this, void 0, void 0, function () {
|
|
815
815
|
var req, token, id, query, doc, _a, _b, e_3;
|
|
816
816
|
return __generator(this, function (_c) {
|
|
817
817
|
switch (_c.label) {
|
|
@@ -1186,7 +1186,7 @@
|
|
|
1186
1186
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1187
1187
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1188
1188
|
};
|
|
1189
|
-
var __awaiter$
|
|
1189
|
+
var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1190
1190
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1191
1191
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1192
1192
|
function fulfilled(value) { try {
|
|
@@ -1223,7 +1223,7 @@
|
|
|
1223
1223
|
function AssetProcessor() {
|
|
1224
1224
|
}
|
|
1225
1225
|
AssetProcessor.getMimeType = function (buffer, mimeType) {
|
|
1226
|
-
return __awaiter$
|
|
1226
|
+
return __awaiter$u(this, void 0, void 0, function () {
|
|
1227
1227
|
var e_1;
|
|
1228
1228
|
return __generator(this, function (_a) {
|
|
1229
1229
|
switch (_a.label) {
|
|
@@ -1264,7 +1264,7 @@
|
|
|
1264
1264
|
return imageTypes.indexOf(contentType) >= 0;
|
|
1265
1265
|
};
|
|
1266
1266
|
AssetProcessor.copyImageMeta = function (buffer, metadata) {
|
|
1267
|
-
return __awaiter$
|
|
1267
|
+
return __awaiter$u(this, void 0, void 0, function () {
|
|
1268
1268
|
var output;
|
|
1269
1269
|
return __generator(this, function (_a) {
|
|
1270
1270
|
switch (_a.label) {
|
|
@@ -1288,7 +1288,7 @@
|
|
|
1288
1288
|
});
|
|
1289
1289
|
};
|
|
1290
1290
|
AssetProcessor.prototype.process = function (buffer, metadata, contentType) {
|
|
1291
|
-
return __awaiter$
|
|
1291
|
+
return __awaiter$u(this, void 0, void 0, function () {
|
|
1292
1292
|
return __generator(this, function (_a) {
|
|
1293
1293
|
switch (_a.label) {
|
|
1294
1294
|
case 0:
|
|
@@ -1384,7 +1384,7 @@
|
|
|
1384
1384
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1385
1385
|
return Reflect.metadata(k, v);
|
|
1386
1386
|
};
|
|
1387
|
-
var __awaiter$
|
|
1387
|
+
var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1388
1388
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1389
1389
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1390
1390
|
function fulfilled(value) { try {
|
|
@@ -1432,7 +1432,7 @@
|
|
|
1432
1432
|
configurable: true
|
|
1433
1433
|
});
|
|
1434
1434
|
MongoConnector.prototype.connect = function () {
|
|
1435
|
-
return __awaiter$
|
|
1435
|
+
return __awaiter$t(this, void 0, void 0, function () {
|
|
1436
1436
|
var _a;
|
|
1437
1437
|
return __generator(this, function (_b) {
|
|
1438
1438
|
switch (_b.label) {
|
|
@@ -1464,6 +1464,65 @@
|
|
|
1464
1464
|
__metadata$o("design:paramtypes", [exports.Configuration])
|
|
1465
1465
|
], exports.MongoConnector);
|
|
1466
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
|
+
|
|
1467
1526
|
var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1468
1527
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1469
1528
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -1490,14 +1549,12 @@
|
|
|
1490
1549
|
w: "number",
|
|
1491
1550
|
h: "number"
|
|
1492
1551
|
};
|
|
1493
|
-
var Asset = /** @class */ (function () {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
this.bucket = bucket;
|
|
1500
|
-
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;
|
|
1501
1558
|
}
|
|
1502
1559
|
Asset.toCropRegion = function (cropInfo) {
|
|
1503
1560
|
var crop = cropInfo;
|
|
@@ -1520,27 +1577,28 @@
|
|
|
1520
1577
|
};
|
|
1521
1578
|
Asset.toImage = function (stream, meta, params) {
|
|
1522
1579
|
return __awaiter$r(this, void 0, void 0, function () {
|
|
1523
|
-
var
|
|
1580
|
+
var crop, buffer, cropBefore, cropAfter, imgMeta, width, height, e_1;
|
|
1524
1581
|
return __generator(this, function (_a) {
|
|
1525
1582
|
switch (_a.label) {
|
|
1526
1583
|
case 0:
|
|
1527
1584
|
params = params || {};
|
|
1528
|
-
|
|
1585
|
+
crop = Asset.toCropRegion(meta.crop);
|
|
1586
|
+
// Return back the stream if there is no params and no default crop exists
|
|
1587
|
+
if (Object.keys(params).length == 0 && !crop)
|
|
1529
1588
|
return [2 /*return*/, stream];
|
|
1530
|
-
return [4 /*yield*/, streamToBuffer(stream)];
|
|
1531
|
-
case 1:
|
|
1532
|
-
buffer = _a.sent();
|
|
1533
1589
|
// Parse params
|
|
1534
1590
|
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
1535
|
-
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : params.canvasScaleX;
|
|
1536
|
-
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : params.canvasScaleY;
|
|
1537
|
-
params.scaleX = isNaN(params.scaleX) ? 1 : params.scaleX;
|
|
1538
|
-
params.scaleY = isNaN(params.scaleY) ? 1 : params.scaleY;
|
|
1591
|
+
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
1592
|
+
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
|
|
1593
|
+
params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
|
|
1594
|
+
params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
|
|
1539
1595
|
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
1596
|
+
return [4 /*yield*/, streamToBuffer(stream)];
|
|
1597
|
+
case 1:
|
|
1598
|
+
buffer = _a.sent();
|
|
1540
1599
|
_a.label = 2;
|
|
1541
1600
|
case 2:
|
|
1542
1601
|
_a.trys.push([2, 16, , 17]);
|
|
1543
|
-
crop = Asset.toCropRegion(meta.crop);
|
|
1544
1602
|
cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
1545
1603
|
cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
1546
1604
|
return [4 /*yield*/, sharp$2(buffer).metadata()];
|
|
@@ -1611,16 +1669,30 @@
|
|
|
1611
1669
|
});
|
|
1612
1670
|
});
|
|
1613
1671
|
};
|
|
1614
|
-
Object.defineProperty(Asset.prototype, "
|
|
1672
|
+
Object.defineProperty(Asset.prototype, "filename", {
|
|
1615
1673
|
get: function () {
|
|
1616
|
-
return this.
|
|
1674
|
+
return this.data.filename;
|
|
1675
|
+
},
|
|
1676
|
+
enumerable: false,
|
|
1677
|
+
configurable: true
|
|
1678
|
+
});
|
|
1679
|
+
Object.defineProperty(Asset.prototype, "contentType", {
|
|
1680
|
+
get: function () {
|
|
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;
|
|
1617
1689
|
},
|
|
1618
1690
|
enumerable: false,
|
|
1619
1691
|
configurable: true
|
|
1620
1692
|
});
|
|
1621
1693
|
Object.defineProperty(Asset.prototype, "stream", {
|
|
1622
1694
|
get: function () {
|
|
1623
|
-
return this.bucket.openDownloadStream(this.
|
|
1695
|
+
return this.bucket.openDownloadStream(this.mId);
|
|
1624
1696
|
},
|
|
1625
1697
|
enumerable: false,
|
|
1626
1698
|
configurable: true
|
|
@@ -1628,7 +1700,7 @@
|
|
|
1628
1700
|
Asset.prototype.unlink = function () {
|
|
1629
1701
|
return __awaiter$r(this, void 0, void 0, function () {
|
|
1630
1702
|
return __generator(this, function (_a) {
|
|
1631
|
-
return [2 /*return*/, deleteFromBucket(this.bucket, this.
|
|
1703
|
+
return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
|
|
1632
1704
|
});
|
|
1633
1705
|
});
|
|
1634
1706
|
};
|
|
@@ -1646,7 +1718,7 @@
|
|
|
1646
1718
|
: metadata.downloadCount + 1;
|
|
1647
1719
|
metadata.firstDownload = metadata.firstDownload || new Date();
|
|
1648
1720
|
metadata.lastDownload = new Date();
|
|
1649
|
-
return [4 /*yield*/, this.collection.updateOne({ _id: this.
|
|
1721
|
+
return [4 /*yield*/, this.collection.updateOne({ _id: this.mId }, { $set: { metadata: metadata } })];
|
|
1650
1722
|
case 1:
|
|
1651
1723
|
_a.sent();
|
|
1652
1724
|
return [2 /*return*/, this.stream];
|
|
@@ -1675,16 +1747,8 @@
|
|
|
1675
1747
|
});
|
|
1676
1748
|
});
|
|
1677
1749
|
};
|
|
1678
|
-
Asset.prototype.toJSON = function () {
|
|
1679
|
-
return {
|
|
1680
|
-
id: this.id,
|
|
1681
|
-
filename: this.filename,
|
|
1682
|
-
contentType: this.contentType,
|
|
1683
|
-
metadata: this.metadata
|
|
1684
|
-
};
|
|
1685
|
-
};
|
|
1686
1750
|
return Asset;
|
|
1687
|
-
}());
|
|
1751
|
+
}(BaseEntity));
|
|
1688
1752
|
|
|
1689
1753
|
var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
1690
1754
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1772,8 +1836,12 @@
|
|
|
1772
1836
|
reject(error.message || error);
|
|
1773
1837
|
})
|
|
1774
1838
|
.on("finish", function () {
|
|
1775
|
-
var asset = new Asset(uploaderStream.id,
|
|
1776
|
-
|
|
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 () {
|
|
1777
1845
|
resolve(asset);
|
|
1778
1846
|
}, function (error) {
|
|
1779
1847
|
reject(error.message || error);
|
|
@@ -1802,6 +1870,20 @@
|
|
|
1802
1870
|
});
|
|
1803
1871
|
});
|
|
1804
1872
|
};
|
|
1873
|
+
Assets.prototype.writeUrl = function (url, metadata) {
|
|
1874
|
+
if (metadata === void 0) { metadata = null; }
|
|
1875
|
+
return __awaiter$q(this, void 0, void 0, function () {
|
|
1876
|
+
var buffer;
|
|
1877
|
+
return __generator(this, function (_b) {
|
|
1878
|
+
switch (_b.label) {
|
|
1879
|
+
case 0: return [4 /*yield*/, axios__default["default"]({ url: url, responseType: "arraybuffer" })];
|
|
1880
|
+
case 1:
|
|
1881
|
+
buffer = (_b.sent()).data;
|
|
1882
|
+
return [2 /*return*/, this.writeBuffer(buffer, metadata)];
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
});
|
|
1886
|
+
};
|
|
1805
1887
|
Assets.prototype.read = function (id) {
|
|
1806
1888
|
return __awaiter$q(this, void 0, void 0, function () {
|
|
1807
1889
|
return __generator(this, function (_b) {
|
|
@@ -1817,7 +1899,39 @@
|
|
|
1817
1899
|
case 0: return [4 /*yield*/, this.collection.findOne(where)];
|
|
1818
1900
|
case 1:
|
|
1819
1901
|
data = _b.sent();
|
|
1820
|
-
return [2 /*return*/, !data ? null : new Asset(data._id, data
|
|
1902
|
+
return [2 /*return*/, !data ? null : new Asset(data._id, data, this.collection, this.bucket)];
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
});
|
|
1906
|
+
};
|
|
1907
|
+
Assets.prototype.findMany = function (where) {
|
|
1908
|
+
return __awaiter$q(this, void 0, void 0, function () {
|
|
1909
|
+
var cursor, items, result, items_1, items_1_1, item;
|
|
1910
|
+
var e_2, _b;
|
|
1911
|
+
return __generator(this, function (_c) {
|
|
1912
|
+
switch (_c.label) {
|
|
1913
|
+
case 0:
|
|
1914
|
+
cursor = this.collection.find(where);
|
|
1915
|
+
return [4 /*yield*/, cursor.toArray()];
|
|
1916
|
+
case 1:
|
|
1917
|
+
items = (_c.sent()) || [];
|
|
1918
|
+
result = [];
|
|
1919
|
+
try {
|
|
1920
|
+
for (items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
1921
|
+
item = items_1_1.value;
|
|
1922
|
+
if (!item)
|
|
1923
|
+
continue;
|
|
1924
|
+
result.push(new Asset(item._id, item, this.collection, this.bucket));
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1928
|
+
finally {
|
|
1929
|
+
try {
|
|
1930
|
+
if (items_1_1 && !items_1_1.done && (_b = items_1.return)) _b.call(items_1);
|
|
1931
|
+
}
|
|
1932
|
+
finally { if (e_2) throw e_2.error; }
|
|
1933
|
+
}
|
|
1934
|
+
return [2 /*return*/, result];
|
|
1821
1935
|
}
|
|
1822
1936
|
});
|
|
1823
1937
|
});
|
|
@@ -1864,36 +1978,46 @@
|
|
|
1864
1978
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1865
1979
|
});
|
|
1866
1980
|
};
|
|
1867
|
-
var LazyAsset = /** @class */ (function () {
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
this.assets = assets;
|
|
1876
|
-
this.progresses = progresses;
|
|
1877
|
-
this.jobMan = jobMan;
|
|
1878
|
-
this.collection = collection;
|
|
1981
|
+
var LazyAsset = /** @class */ (function (_super) {
|
|
1982
|
+
__extends(LazyAsset, _super);
|
|
1983
|
+
function LazyAsset(id, data, collection, assets, progresses, jobMan) {
|
|
1984
|
+
var _this = _super.call(this, id, data, collection) || this;
|
|
1985
|
+
_this.assets = assets;
|
|
1986
|
+
_this.progresses = progresses;
|
|
1987
|
+
_this.jobMan = jobMan;
|
|
1988
|
+
return _this;
|
|
1879
1989
|
}
|
|
1880
|
-
Object.defineProperty(LazyAsset.prototype, "
|
|
1990
|
+
Object.defineProperty(LazyAsset.prototype, "jobName", {
|
|
1881
1991
|
get: function () {
|
|
1882
|
-
return this.
|
|
1992
|
+
return this.data.jobName;
|
|
1993
|
+
},
|
|
1994
|
+
enumerable: false,
|
|
1995
|
+
configurable: true
|
|
1996
|
+
});
|
|
1997
|
+
Object.defineProperty(LazyAsset.prototype, "jobParams", {
|
|
1998
|
+
get: function () {
|
|
1999
|
+
return this.data.jobParams;
|
|
2000
|
+
},
|
|
2001
|
+
enumerable: false,
|
|
2002
|
+
configurable: true
|
|
2003
|
+
});
|
|
2004
|
+
Object.defineProperty(LazyAsset.prototype, "jobQue", {
|
|
2005
|
+
get: function () {
|
|
2006
|
+
return this.data.jobQue;
|
|
1883
2007
|
},
|
|
1884
2008
|
enumerable: false,
|
|
1885
2009
|
configurable: true
|
|
1886
2010
|
});
|
|
1887
2011
|
Object.defineProperty(LazyAsset.prototype, "progressId", {
|
|
1888
2012
|
get: function () {
|
|
1889
|
-
return this.
|
|
2013
|
+
return this.data.progressId;
|
|
1890
2014
|
},
|
|
1891
2015
|
enumerable: false,
|
|
1892
2016
|
configurable: true
|
|
1893
2017
|
});
|
|
1894
2018
|
Object.defineProperty(LazyAsset.prototype, "assetId", {
|
|
1895
2019
|
get: function () {
|
|
1896
|
-
return this.
|
|
2020
|
+
return this.data.assetId;
|
|
1897
2021
|
},
|
|
1898
2022
|
enumerable: false,
|
|
1899
2023
|
configurable: true
|
|
@@ -1902,41 +2026,50 @@
|
|
|
1902
2026
|
return __awaiter$p(this, void 0, void 0, function () {
|
|
1903
2027
|
return __generator(this, function (_a) {
|
|
1904
2028
|
switch (_a.label) {
|
|
1905
|
-
case 0: return [4 /*yield*/, this.
|
|
2029
|
+
case 0: return [4 /*yield*/, this.load()];
|
|
1906
2030
|
case 1:
|
|
1907
2031
|
_a.sent();
|
|
1908
|
-
return [
|
|
2032
|
+
if (!!this.progressId) return [3 /*break*/, 3];
|
|
2033
|
+
return [4 /*yield*/, this.collection.deleteOne({ _id: this.mId })];
|
|
2034
|
+
case 2:
|
|
2035
|
+
_a.sent();
|
|
2036
|
+
_a.label = 3;
|
|
2037
|
+
case 3: return [2 /*return*/, deleteFromBucket(this.assets.bucket, new bson.ObjectId(this.assetId))];
|
|
1909
2038
|
}
|
|
1910
2039
|
});
|
|
1911
2040
|
});
|
|
1912
2041
|
};
|
|
1913
2042
|
LazyAsset.prototype.startWorking = function () {
|
|
1914
2043
|
var _this = this;
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2044
|
+
this.load().then(function () {
|
|
2045
|
+
if (_this.deleted)
|
|
2046
|
+
return;
|
|
2047
|
+
var progressPromise = !_this.progressId ? Promise.resolve(null) : _this.progresses.get(_this.progressId).then(function (p) { return p.cancel(); });
|
|
2048
|
+
progressPromise.then(function () {
|
|
2049
|
+
_this.startWorkingOnAsset().then(function () {
|
|
2050
|
+
console.log("Started working on lazy asset: " + _this.id);
|
|
2051
|
+
}).catch(function (reason) {
|
|
2052
|
+
console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
|
|
2053
|
+
});
|
|
2054
|
+
});
|
|
1921
2055
|
});
|
|
1922
2056
|
};
|
|
1923
2057
|
LazyAsset.prototype.loadAsset = function () {
|
|
1924
2058
|
return __awaiter$p(this, void 0, void 0, function () {
|
|
1925
|
-
var data;
|
|
1926
2059
|
return __generator(this, function (_a) {
|
|
1927
2060
|
switch (_a.label) {
|
|
1928
|
-
case 0:
|
|
1929
|
-
if (this.mAssetId) {
|
|
1930
|
-
return [2 /*return*/, this.assets.read(this.mAssetId)];
|
|
1931
|
-
}
|
|
1932
|
-
if (!this.mProgressId) return [3 /*break*/, 3];
|
|
1933
|
-
return [4 /*yield*/, this.progresses.waitToFinish(this.mProgressId)];
|
|
2061
|
+
case 0: return [4 /*yield*/, this.load()];
|
|
1934
2062
|
case 1:
|
|
1935
2063
|
_a.sent();
|
|
1936
|
-
|
|
2064
|
+
if (this.deleted)
|
|
2065
|
+
return [2 /*return*/, null];
|
|
2066
|
+
if (this.assetId) {
|
|
2067
|
+
return [2 /*return*/, this.assets.read(this.assetId)];
|
|
2068
|
+
}
|
|
2069
|
+
if (!this.progressId) return [3 /*break*/, 3];
|
|
2070
|
+
return [4 /*yield*/, this.progresses.waitToFinish(this.progressId)];
|
|
1937
2071
|
case 2:
|
|
1938
|
-
|
|
1939
|
-
this.mAssetId = data.assetId;
|
|
2072
|
+
_a.sent();
|
|
1940
2073
|
return [2 /*return*/, this.loadAsset()];
|
|
1941
2074
|
case 3: return [4 /*yield*/, this.startWorkingOnAsset()];
|
|
1942
2075
|
case 4:
|
|
@@ -1951,7 +2084,7 @@
|
|
|
1951
2084
|
return __generator(this, function (_a) {
|
|
1952
2085
|
switch (_a.label) {
|
|
1953
2086
|
case 0:
|
|
1954
|
-
this.
|
|
2087
|
+
this.data.assetId = asset.id;
|
|
1955
2088
|
return [4 /*yield*/, this.save()];
|
|
1956
2089
|
case 1:
|
|
1957
2090
|
_a.sent();
|
|
@@ -1960,32 +2093,19 @@
|
|
|
1960
2093
|
});
|
|
1961
2094
|
});
|
|
1962
2095
|
};
|
|
1963
|
-
LazyAsset.prototype.save = function () {
|
|
1964
|
-
return this.collection.updateOne({ _id: this.lazyId }, { $set: this.toJSON() });
|
|
1965
|
-
};
|
|
1966
|
-
LazyAsset.prototype.toJSON = function () {
|
|
1967
|
-
return {
|
|
1968
|
-
id: this.id,
|
|
1969
|
-
jobName: this.jobName,
|
|
1970
|
-
jobParams: this.jobParams,
|
|
1971
|
-
jobQue: this.jobQue,
|
|
1972
|
-
progressId: this.progressId,
|
|
1973
|
-
assetId: this.assetId,
|
|
1974
|
-
};
|
|
1975
|
-
};
|
|
1976
2096
|
LazyAsset.prototype.startWorkingOnAsset = function () {
|
|
1977
2097
|
return __awaiter$p(this, void 0, void 0, function () {
|
|
1978
|
-
var
|
|
2098
|
+
var id;
|
|
1979
2099
|
return __generator(this, function (_a) {
|
|
1980
2100
|
switch (_a.label) {
|
|
1981
2101
|
case 0: return [4 /*yield*/, this.progresses.create()];
|
|
1982
2102
|
case 1:
|
|
1983
|
-
|
|
1984
|
-
this.
|
|
2103
|
+
id = (_a.sent()).id;
|
|
2104
|
+
this.data.progressId = id;
|
|
1985
2105
|
return [4 /*yield*/, this.save()];
|
|
1986
2106
|
case 2:
|
|
1987
2107
|
_a.sent();
|
|
1988
|
-
return [4 /*yield*/, this.jobMan.enqueueWithName(this.jobName, Object.assign(Object.assign({}, this.jobParams), { lazyId: this.id }))];
|
|
2108
|
+
return [4 /*yield*/, this.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id }))];
|
|
1989
2109
|
case 3:
|
|
1990
2110
|
_a.sent();
|
|
1991
2111
|
return [2 /*return*/];
|
|
@@ -1994,7 +2114,7 @@
|
|
|
1994
2114
|
});
|
|
1995
2115
|
};
|
|
1996
2116
|
return LazyAsset;
|
|
1997
|
-
}());
|
|
2117
|
+
}(BaseEntity));
|
|
1998
2118
|
|
|
1999
2119
|
var __decorate$s = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2000
2120
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2305,61 +2425,58 @@
|
|
|
2305
2425
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2306
2426
|
});
|
|
2307
2427
|
};
|
|
2308
|
-
var Progress = /** @class */ (function () {
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
this.mError = mError;
|
|
2315
|
-
this.client = client;
|
|
2316
|
-
this.collection = collection;
|
|
2428
|
+
var Progress = /** @class */ (function (_super) {
|
|
2429
|
+
__extends(Progress, _super);
|
|
2430
|
+
function Progress(id, data, collection, client) {
|
|
2431
|
+
var _this = _super.call(this, id, data, collection) || this;
|
|
2432
|
+
_this.client = client;
|
|
2433
|
+
return _this;
|
|
2317
2434
|
}
|
|
2318
|
-
Object.defineProperty(Progress.prototype, "
|
|
2435
|
+
Object.defineProperty(Progress.prototype, "current", {
|
|
2319
2436
|
get: function () {
|
|
2320
|
-
return this.
|
|
2437
|
+
return this.data.current;
|
|
2321
2438
|
},
|
|
2322
2439
|
enumerable: false,
|
|
2323
2440
|
configurable: true
|
|
2324
2441
|
});
|
|
2325
|
-
Object.defineProperty(Progress.prototype, "
|
|
2442
|
+
Object.defineProperty(Progress.prototype, "max", {
|
|
2326
2443
|
get: function () {
|
|
2327
|
-
return this.
|
|
2444
|
+
return this.data.max;
|
|
2328
2445
|
},
|
|
2329
2446
|
enumerable: false,
|
|
2330
2447
|
configurable: true
|
|
2331
2448
|
});
|
|
2332
|
-
Object.defineProperty(Progress.prototype, "
|
|
2449
|
+
Object.defineProperty(Progress.prototype, "message", {
|
|
2333
2450
|
get: function () {
|
|
2334
|
-
return this.
|
|
2451
|
+
return this.data.message;
|
|
2335
2452
|
},
|
|
2336
2453
|
enumerable: false,
|
|
2337
2454
|
configurable: true
|
|
2338
2455
|
});
|
|
2339
|
-
Object.defineProperty(Progress.prototype, "
|
|
2456
|
+
Object.defineProperty(Progress.prototype, "error", {
|
|
2340
2457
|
get: function () {
|
|
2341
|
-
return this.
|
|
2458
|
+
return this.data.error;
|
|
2342
2459
|
},
|
|
2343
2460
|
enumerable: false,
|
|
2344
2461
|
configurable: true
|
|
2345
2462
|
});
|
|
2346
|
-
Object.defineProperty(Progress.prototype, "
|
|
2463
|
+
Object.defineProperty(Progress.prototype, "canceled", {
|
|
2347
2464
|
get: function () {
|
|
2348
|
-
return this.
|
|
2465
|
+
return this.data.canceled;
|
|
2349
2466
|
},
|
|
2350
2467
|
enumerable: false,
|
|
2351
2468
|
configurable: true
|
|
2352
2469
|
});
|
|
2353
2470
|
Object.defineProperty(Progress.prototype, "percent", {
|
|
2354
2471
|
get: function () {
|
|
2355
|
-
return this.
|
|
2472
|
+
return this.max > 0 ? Math.round(this.current / this.max * 100) : 0;
|
|
2356
2473
|
},
|
|
2357
2474
|
enumerable: false,
|
|
2358
2475
|
configurable: true
|
|
2359
2476
|
});
|
|
2360
2477
|
Object.defineProperty(Progress.prototype, "remaining", {
|
|
2361
2478
|
get: function () {
|
|
2362
|
-
return this.
|
|
2479
|
+
return this.max > 0 ? this.max - this.current : 0;
|
|
2363
2480
|
},
|
|
2364
2481
|
enumerable: false,
|
|
2365
2482
|
configurable: true
|
|
@@ -2376,12 +2493,12 @@
|
|
|
2376
2493
|
_a.label = 2;
|
|
2377
2494
|
case 2:
|
|
2378
2495
|
if (!(message !== null)) return [3 /*break*/, 4];
|
|
2379
|
-
this.
|
|
2496
|
+
this.data.message = message;
|
|
2380
2497
|
return [4 /*yield*/, this.save()];
|
|
2381
2498
|
case 3:
|
|
2382
2499
|
_a.sent();
|
|
2383
2500
|
_a.label = 4;
|
|
2384
|
-
case 4: return [2 /*return*/, new SubProgress(this, this.
|
|
2501
|
+
case 4: return [2 /*return*/, new SubProgress(this, this.current, progressValue, Math.max(max, 1))];
|
|
2385
2502
|
}
|
|
2386
2503
|
});
|
|
2387
2504
|
});
|
|
@@ -2394,7 +2511,21 @@
|
|
|
2394
2511
|
if (isNaN(max) || max <= 0) {
|
|
2395
2512
|
throw "Max progress value must be bigger than zero";
|
|
2396
2513
|
}
|
|
2397
|
-
this.
|
|
2514
|
+
this.data.max = max;
|
|
2515
|
+
return [4 /*yield*/, this.save()];
|
|
2516
|
+
case 1:
|
|
2517
|
+
_a.sent();
|
|
2518
|
+
return [2 /*return*/];
|
|
2519
|
+
}
|
|
2520
|
+
});
|
|
2521
|
+
});
|
|
2522
|
+
};
|
|
2523
|
+
Progress.prototype.setMessage = function (message) {
|
|
2524
|
+
return __awaiter$n(this, void 0, void 0, function () {
|
|
2525
|
+
return __generator(this, function (_a) {
|
|
2526
|
+
switch (_a.label) {
|
|
2527
|
+
case 0:
|
|
2528
|
+
this.data.message = message;
|
|
2398
2529
|
return [4 /*yield*/, this.save()];
|
|
2399
2530
|
case 1:
|
|
2400
2531
|
_a.sent();
|
|
@@ -2408,7 +2539,7 @@
|
|
|
2408
2539
|
return __generator(this, function (_a) {
|
|
2409
2540
|
switch (_a.label) {
|
|
2410
2541
|
case 0:
|
|
2411
|
-
this.
|
|
2542
|
+
this.data.error = error;
|
|
2412
2543
|
return [4 /*yield*/, this.save()];
|
|
2413
2544
|
case 1:
|
|
2414
2545
|
_a.sent();
|
|
@@ -2426,9 +2557,14 @@
|
|
|
2426
2557
|
if (isNaN(value) || value <= 0) {
|
|
2427
2558
|
throw "Advance value must be bigger than zero";
|
|
2428
2559
|
}
|
|
2429
|
-
|
|
2430
|
-
return [4 /*yield*/, this.save()];
|
|
2560
|
+
return [4 /*yield*/, this.load()];
|
|
2431
2561
|
case 1:
|
|
2562
|
+
_a.sent();
|
|
2563
|
+
if (this.deleted || this.canceled)
|
|
2564
|
+
return [2 /*return*/, null];
|
|
2565
|
+
this.data.current = Math.min(this.max, this.current + value);
|
|
2566
|
+
return [4 /*yield*/, this.save()];
|
|
2567
|
+
case 2:
|
|
2432
2568
|
_a.sent();
|
|
2433
2569
|
if (!this.client)
|
|
2434
2570
|
return [2 /*return*/];
|
|
@@ -2438,34 +2574,36 @@
|
|
|
2438
2574
|
});
|
|
2439
2575
|
});
|
|
2440
2576
|
};
|
|
2441
|
-
Progress.prototype.
|
|
2442
|
-
return {
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2577
|
+
Progress.prototype.cancel = function () {
|
|
2578
|
+
return __awaiter$n(this, void 0, void 0, function () {
|
|
2579
|
+
return __generator(this, function (_a) {
|
|
2580
|
+
switch (_a.label) {
|
|
2581
|
+
case 0:
|
|
2582
|
+
this.data.canceled = true;
|
|
2583
|
+
return [4 /*yield*/, this.save()];
|
|
2584
|
+
case 1:
|
|
2585
|
+
_a.sent();
|
|
2586
|
+
return [2 /*return*/];
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
});
|
|
2452
2590
|
};
|
|
2453
2591
|
return Progress;
|
|
2454
|
-
}());
|
|
2592
|
+
}(BaseEntity));
|
|
2455
2593
|
var SubProgress = /** @class */ (function () {
|
|
2456
|
-
function SubProgress(parent, progressFrom, progressValue,
|
|
2457
|
-
if (
|
|
2594
|
+
function SubProgress(parent, progressFrom, progressValue, mMax) {
|
|
2595
|
+
if (mMax === void 0) { mMax = 100; }
|
|
2458
2596
|
this.parent = parent;
|
|
2459
2597
|
this.progressFrom = progressFrom;
|
|
2460
2598
|
this.progressValue = progressValue;
|
|
2461
|
-
this.
|
|
2599
|
+
this.mMax = mMax;
|
|
2462
2600
|
if (progressFrom < 0) {
|
|
2463
2601
|
throw "Progress from must be bigger than or zero";
|
|
2464
2602
|
}
|
|
2465
2603
|
if (progressValue <= 0) {
|
|
2466
2604
|
throw "Progress value must be bigger than zero";
|
|
2467
2605
|
}
|
|
2468
|
-
this.
|
|
2606
|
+
this.mCurrent = 0;
|
|
2469
2607
|
}
|
|
2470
2608
|
Object.defineProperty(SubProgress.prototype, "id", {
|
|
2471
2609
|
get: function () {
|
|
@@ -2474,13 +2612,24 @@
|
|
|
2474
2612
|
enumerable: false,
|
|
2475
2613
|
configurable: true
|
|
2476
2614
|
});
|
|
2615
|
+
Object.defineProperty(SubProgress.prototype, "current", {
|
|
2616
|
+
get: function () {
|
|
2617
|
+
return this.mCurrent;
|
|
2618
|
+
},
|
|
2619
|
+
enumerable: false,
|
|
2620
|
+
configurable: true
|
|
2621
|
+
});
|
|
2622
|
+
Object.defineProperty(SubProgress.prototype, "max", {
|
|
2623
|
+
get: function () {
|
|
2624
|
+
return this.mMax;
|
|
2625
|
+
},
|
|
2626
|
+
enumerable: false,
|
|
2627
|
+
configurable: true
|
|
2628
|
+
});
|
|
2477
2629
|
Object.defineProperty(SubProgress.prototype, "message", {
|
|
2478
2630
|
get: function () {
|
|
2479
2631
|
return this.parent.message;
|
|
2480
2632
|
},
|
|
2481
|
-
set: function (value) {
|
|
2482
|
-
this.parent.message = value;
|
|
2483
|
-
},
|
|
2484
2633
|
enumerable: false,
|
|
2485
2634
|
configurable: true
|
|
2486
2635
|
});
|
|
@@ -2488,9 +2637,6 @@
|
|
|
2488
2637
|
get: function () {
|
|
2489
2638
|
return this.parent.error;
|
|
2490
2639
|
},
|
|
2491
|
-
set: function (value) {
|
|
2492
|
-
this.parent.error = value;
|
|
2493
|
-
},
|
|
2494
2640
|
enumerable: false,
|
|
2495
2641
|
configurable: true
|
|
2496
2642
|
});
|
|
@@ -2501,16 +2647,16 @@
|
|
|
2501
2647
|
enumerable: false,
|
|
2502
2648
|
configurable: true
|
|
2503
2649
|
});
|
|
2504
|
-
Object.defineProperty(SubProgress.prototype, "
|
|
2650
|
+
Object.defineProperty(SubProgress.prototype, "remaining", {
|
|
2505
2651
|
get: function () {
|
|
2506
|
-
return this.
|
|
2652
|
+
return this.max - this.mCurrent;
|
|
2507
2653
|
},
|
|
2508
2654
|
enumerable: false,
|
|
2509
2655
|
configurable: true
|
|
2510
2656
|
});
|
|
2511
|
-
Object.defineProperty(SubProgress.prototype, "
|
|
2657
|
+
Object.defineProperty(SubProgress.prototype, "canceled", {
|
|
2512
2658
|
get: function () {
|
|
2513
|
-
return this.
|
|
2659
|
+
return !this.parent || this.parent.canceled;
|
|
2514
2660
|
},
|
|
2515
2661
|
enumerable: false,
|
|
2516
2662
|
configurable: true
|
|
@@ -2527,8 +2673,7 @@
|
|
|
2527
2673
|
_a.label = 2;
|
|
2528
2674
|
case 2:
|
|
2529
2675
|
if (!(message !== null)) return [3 /*break*/, 4];
|
|
2530
|
-
this.message
|
|
2531
|
-
return [4 /*yield*/, this.parent.save()];
|
|
2676
|
+
return [4 /*yield*/, this.setMessage(message)];
|
|
2532
2677
|
case 3:
|
|
2533
2678
|
_a.sent();
|
|
2534
2679
|
_a.label = 4;
|
|
@@ -2545,7 +2690,7 @@
|
|
|
2545
2690
|
if (isNaN(max) || max <= 0) {
|
|
2546
2691
|
throw "Max progress value must be bigger than zero";
|
|
2547
2692
|
}
|
|
2548
|
-
this.
|
|
2693
|
+
this.mMax = max;
|
|
2549
2694
|
return [4 /*yield*/, this.save()];
|
|
2550
2695
|
case 1:
|
|
2551
2696
|
_a.sent();
|
|
@@ -2554,13 +2699,29 @@
|
|
|
2554
2699
|
});
|
|
2555
2700
|
});
|
|
2556
2701
|
};
|
|
2702
|
+
SubProgress.prototype.setMessage = function (message) {
|
|
2703
|
+
return __awaiter$n(this, void 0, void 0, function () {
|
|
2704
|
+
return __generator(this, function (_a) {
|
|
2705
|
+
switch (_a.label) {
|
|
2706
|
+
case 0:
|
|
2707
|
+
if (!this.parent)
|
|
2708
|
+
return [2 /*return*/, null];
|
|
2709
|
+
return [4 /*yield*/, this.parent.setMessage(message)];
|
|
2710
|
+
case 1:
|
|
2711
|
+
_a.sent();
|
|
2712
|
+
return [2 /*return*/];
|
|
2713
|
+
}
|
|
2714
|
+
});
|
|
2715
|
+
});
|
|
2716
|
+
};
|
|
2557
2717
|
SubProgress.prototype.setError = function (error) {
|
|
2558
2718
|
return __awaiter$n(this, void 0, void 0, function () {
|
|
2559
2719
|
return __generator(this, function (_a) {
|
|
2560
2720
|
switch (_a.label) {
|
|
2561
2721
|
case 0:
|
|
2562
|
-
this.
|
|
2563
|
-
|
|
2722
|
+
if (!this.parent)
|
|
2723
|
+
return [2 /*return*/, null];
|
|
2724
|
+
return [4 /*yield*/, this.parent.setError(error)];
|
|
2564
2725
|
case 1:
|
|
2565
2726
|
_a.sent();
|
|
2566
2727
|
return [2 /*return*/];
|
|
@@ -2577,7 +2738,7 @@
|
|
|
2577
2738
|
if (isNaN(value) || value <= 0) {
|
|
2578
2739
|
throw "Advance value must be bigger than zero";
|
|
2579
2740
|
}
|
|
2580
|
-
this.
|
|
2741
|
+
this.mCurrent = Math.min(this.max, this.mCurrent + value);
|
|
2581
2742
|
return [4 /*yield*/, this.save()];
|
|
2582
2743
|
case 1:
|
|
2583
2744
|
_a.sent();
|
|
@@ -2586,13 +2747,28 @@
|
|
|
2586
2747
|
});
|
|
2587
2748
|
});
|
|
2588
2749
|
};
|
|
2750
|
+
SubProgress.prototype.cancel = function () {
|
|
2751
|
+
return __awaiter$n(this, void 0, void 0, function () {
|
|
2752
|
+
return __generator(this, function (_a) {
|
|
2753
|
+
switch (_a.label) {
|
|
2754
|
+
case 0:
|
|
2755
|
+
if (!this.parent)
|
|
2756
|
+
return [2 /*return*/, null];
|
|
2757
|
+
return [4 /*yield*/, this.parent.cancel()];
|
|
2758
|
+
case 1:
|
|
2759
|
+
_a.sent();
|
|
2760
|
+
return [2 /*return*/];
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
});
|
|
2764
|
+
};
|
|
2589
2765
|
SubProgress.prototype.save = function () {
|
|
2590
2766
|
return __awaiter$n(this, void 0, void 0, function () {
|
|
2591
2767
|
var ratio, newProgress, current;
|
|
2592
2768
|
return __generator(this, function (_a) {
|
|
2593
2769
|
switch (_a.label) {
|
|
2594
2770
|
case 0:
|
|
2595
|
-
ratio = this.max > 0 ? this.
|
|
2771
|
+
ratio = this.max > 0 ? this.mCurrent / this.max : 0;
|
|
2596
2772
|
newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
|
|
2597
2773
|
current = this.parent.current;
|
|
2598
2774
|
if (newProgress <= current)
|
|
@@ -2605,6 +2781,13 @@
|
|
|
2605
2781
|
});
|
|
2606
2782
|
});
|
|
2607
2783
|
};
|
|
2784
|
+
SubProgress.prototype.load = function () {
|
|
2785
|
+
return __awaiter$n(this, void 0, void 0, function () {
|
|
2786
|
+
return __generator(this, function (_a) {
|
|
2787
|
+
return [2 /*return*/, null];
|
|
2788
|
+
});
|
|
2789
|
+
});
|
|
2790
|
+
};
|
|
2608
2791
|
SubProgress.prototype.toJSON = function () {
|
|
2609
2792
|
return this.parent.toJSON();
|
|
2610
2793
|
};
|
|
@@ -2700,7 +2883,7 @@
|
|
|
2700
2883
|
case 0: return [4 /*yield*/, this.collection.findOne(where)];
|
|
2701
2884
|
case 1:
|
|
2702
2885
|
data = _a.sent();
|
|
2703
|
-
return [2 /*return*/, !data ? null : new Progress(data._id, data
|
|
2886
|
+
return [2 /*return*/, !data ? null : new Progress(data._id, data, this.collection, this.client)];
|
|
2704
2887
|
}
|
|
2705
2888
|
});
|
|
2706
2889
|
});
|
|
@@ -2708,20 +2891,24 @@
|
|
|
2708
2891
|
Progresses.prototype.create = function (max) {
|
|
2709
2892
|
if (max === void 0) { max = 100; }
|
|
2710
2893
|
return __awaiter$m(this, void 0, void 0, function () {
|
|
2711
|
-
var res;
|
|
2894
|
+
var data, res;
|
|
2712
2895
|
return __generator(this, function (_a) {
|
|
2713
2896
|
switch (_a.label) {
|
|
2714
2897
|
case 0:
|
|
2715
2898
|
if (isNaN(max) || max <= 0) {
|
|
2716
2899
|
throw "Max progress value must be bigger than zero";
|
|
2717
2900
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2901
|
+
data = {
|
|
2902
|
+
current: 0,
|
|
2903
|
+
max: max,
|
|
2904
|
+
message: "",
|
|
2905
|
+
error: "",
|
|
2906
|
+
canceled: false
|
|
2907
|
+
};
|
|
2908
|
+
return [4 /*yield*/, this.collection.insertOne(data)];
|
|
2722
2909
|
case 1:
|
|
2723
2910
|
res = _a.sent();
|
|
2724
|
-
return [2 /*return*/, new Progress(res.insertedId,
|
|
2911
|
+
return [2 /*return*/, new Progress(res.insertedId, data, this.collection, this.client)];
|
|
2725
2912
|
}
|
|
2726
2913
|
});
|
|
2727
2914
|
});
|
|
@@ -2791,19 +2978,25 @@
|
|
|
2791
2978
|
if (jobParams === void 0) { jobParams = {}; }
|
|
2792
2979
|
if (jobQue === void 0) { jobQue = "main"; }
|
|
2793
2980
|
return __awaiter$l(this, void 0, void 0, function () {
|
|
2794
|
-
var jobName, res;
|
|
2981
|
+
var jobName, data, existingAsset, res;
|
|
2795
2982
|
return __generator(this, function (_a) {
|
|
2796
2983
|
switch (_a.label) {
|
|
2797
2984
|
case 0:
|
|
2798
2985
|
jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2986
|
+
data = {
|
|
2987
|
+
jobName: jobName,
|
|
2988
|
+
jobParams: jobParams,
|
|
2989
|
+
jobQue: jobQue
|
|
2990
|
+
};
|
|
2991
|
+
return [4 /*yield*/, this.find(data)];
|
|
2804
2992
|
case 1:
|
|
2993
|
+
existingAsset = _a.sent();
|
|
2994
|
+
if (existingAsset)
|
|
2995
|
+
return [2 /*return*/, existingAsset];
|
|
2996
|
+
return [4 /*yield*/, this.collection.insertOne(data)];
|
|
2997
|
+
case 2:
|
|
2805
2998
|
res = _a.sent();
|
|
2806
|
-
return [2 /*return*/, new LazyAsset(res.insertedId,
|
|
2999
|
+
return [2 /*return*/, new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses, this.jobMan)];
|
|
2807
3000
|
}
|
|
2808
3001
|
});
|
|
2809
3002
|
});
|
|
@@ -2825,7 +3018,7 @@
|
|
|
2825
3018
|
data = _a.sent();
|
|
2826
3019
|
return [2 /*return*/, !data
|
|
2827
3020
|
? null
|
|
2828
|
-
: new LazyAsset(data._id, data
|
|
3021
|
+
: new LazyAsset(data._id, data, this.collection, this.assets, this.progresses, this.jobMan)];
|
|
2829
3022
|
}
|
|
2830
3023
|
});
|
|
2831
3024
|
});
|
|
@@ -4329,6 +4522,26 @@
|
|
|
4329
4522
|
});
|
|
4330
4523
|
});
|
|
4331
4524
|
};
|
|
4525
|
+
AssetsController.prototype.uploadUrl = function (body) {
|
|
4526
|
+
return __awaiter$7(this, void 0, void 0, function () {
|
|
4527
|
+
var asset, e_2, msg;
|
|
4528
|
+
return __generator(this, function (_c) {
|
|
4529
|
+
switch (_c.label) {
|
|
4530
|
+
case 0:
|
|
4531
|
+
_c.trys.push([0, 2, , 3]);
|
|
4532
|
+
return [4 /*yield*/, this.assets.writeUrl(body.url, body)];
|
|
4533
|
+
case 1:
|
|
4534
|
+
asset = _c.sent();
|
|
4535
|
+
return [2 /*return*/, asset.toJSON()];
|
|
4536
|
+
case 2:
|
|
4537
|
+
e_2 = _c.sent();
|
|
4538
|
+
msg = (e_2 === null || e_2 === void 0 ? void 0 : e_2.message) || e_2 || "Unknown error";
|
|
4539
|
+
throw new routingControllers.HttpError(400, "Asset can't be uploaded.\n" + msg);
|
|
4540
|
+
case 3: return [2 /*return*/];
|
|
4541
|
+
}
|
|
4542
|
+
});
|
|
4543
|
+
});
|
|
4544
|
+
};
|
|
4332
4545
|
AssetsController.prototype.getImageRotation = function (id, params, rotation) {
|
|
4333
4546
|
if (rotation === void 0) { rotation = 0; }
|
|
4334
4547
|
var _a;
|
|
@@ -4392,6 +4605,14 @@
|
|
|
4392
4605
|
__metadata$7("design:paramtypes", [Object]),
|
|
4393
4606
|
__metadata$7("design:returntype", Promise)
|
|
4394
4607
|
], AssetsController.prototype, "upload", null);
|
|
4608
|
+
__decorate$a([
|
|
4609
|
+
routingControllers.Authorized(),
|
|
4610
|
+
routingControllers.Post("url"),
|
|
4611
|
+
__param$5(0, routingControllers.Body()),
|
|
4612
|
+
__metadata$7("design:type", Function),
|
|
4613
|
+
__metadata$7("design:paramtypes", [Object]),
|
|
4614
|
+
__metadata$7("design:returntype", Promise)
|
|
4615
|
+
], AssetsController.prototype, "uploadUrl", null);
|
|
4395
4616
|
__decorate$a([
|
|
4396
4617
|
routingControllers.Get("/image/:id/:rotation"),
|
|
4397
4618
|
__param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParams()), __param$5(2, routingControllers.Param("rotation")),
|
|
@@ -5327,29 +5548,36 @@
|
|
|
5327
5548
|
return [4 /*yield*/, this.progresses.get(lazyAsset.progressId)];
|
|
5328
5549
|
case 2:
|
|
5329
5550
|
progress = _a.sent();
|
|
5551
|
+
if (!progress || progress.canceled)
|
|
5552
|
+
return [2 /*return*/, null];
|
|
5330
5553
|
_a.label = 3;
|
|
5331
5554
|
case 3:
|
|
5332
|
-
_a.trys.push([3,
|
|
5555
|
+
_a.trys.push([3, 7, , 9]);
|
|
5333
5556
|
return [4 /*yield*/, this.generate(progress)];
|
|
5334
5557
|
case 4:
|
|
5335
5558
|
asset = _a.sent();
|
|
5336
|
-
return [4 /*yield*/,
|
|
5559
|
+
return [4 /*yield*/, progress.load()];
|
|
5337
5560
|
case 5:
|
|
5338
|
-
_a.sent();
|
|
5339
|
-
|
|
5561
|
+
progress = _a.sent();
|
|
5562
|
+
if (!progress || progress.canceled)
|
|
5563
|
+
return [2 /*return*/, null];
|
|
5564
|
+
return [4 /*yield*/, lazyAsset.writeAsset(asset)];
|
|
5340
5565
|
case 6:
|
|
5566
|
+
_a.sent();
|
|
5567
|
+
return [3 /*break*/, 9];
|
|
5568
|
+
case 7:
|
|
5341
5569
|
e_1 = _a.sent();
|
|
5342
5570
|
return [4 /*yield*/, progress.setError(e_1.message || e_1)];
|
|
5343
|
-
case
|
|
5571
|
+
case 8:
|
|
5344
5572
|
_a.sent();
|
|
5345
5573
|
throw e_1;
|
|
5346
|
-
case 8:
|
|
5347
|
-
if (!(progress.remaining > 0)) return [3 /*break*/, 10];
|
|
5348
|
-
return [4 /*yield*/, progress.advance(progress.remaining)];
|
|
5349
5574
|
case 9:
|
|
5575
|
+
if (!(progress.remaining > 0)) return [3 /*break*/, 11];
|
|
5576
|
+
return [4 /*yield*/, progress.advance(progress.remaining)];
|
|
5577
|
+
case 10:
|
|
5350
5578
|
_a.sent();
|
|
5351
|
-
_a.label =
|
|
5352
|
-
case
|
|
5579
|
+
_a.label = 11;
|
|
5580
|
+
case 11: return [2 /*return*/];
|
|
5353
5581
|
}
|
|
5354
5582
|
});
|
|
5355
5583
|
});
|