@stemy/backend 3.2.0 → 3.2.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 +230 -141
- 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/esm2015/public_api.js +2 -2
- package/esm2015/rest-controllers/assets.controller.js +56 -17
- package/esm2015/services/assets.js +7 -1
- package/esm2015/services/entities/asset.js +4 -98
- package/esm2015/services/entities/temp-asset.js +3 -4
- package/esm2015/utils.js +102 -1
- package/fesm2015/stemy-backend.js +170 -118
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
- package/rest-controllers/assets.controller.d.ts +5 -1
- package/services/assets.d.ts +1 -0
- package/services/entities/asset.d.ts +1 -4
- package/stemy-backend.metadata.json +1 -1
- package/utils.d.ts +3 -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('
|
|
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', '
|
|
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.
|
|
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,
|
|
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('sharp'), require('fontkit'), require('file-type'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('rxjs/operators'), 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', 'sharp', 'fontkit', 'file-type', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', 'rxjs/operators', '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.sharp, global.fontkit, global["file-type"], global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.rxjs.operators, 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, sharp_, fontKit_, fileType, axios, mongodb, dotenv, nodeCron, zeromq, operators, 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
|
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
var fontKit___default = /*#__PURE__*/_interopDefaultLegacy(fontKit_);
|
|
28
27
|
var sharp___default = /*#__PURE__*/_interopDefaultLegacy(sharp_);
|
|
28
|
+
var fontKit___default = /*#__PURE__*/_interopDefaultLegacy(fontKit_);
|
|
29
29
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
30
30
|
var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
|
|
31
31
|
var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
|
|
@@ -379,6 +379,7 @@
|
|
|
379
379
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
380
380
|
});
|
|
381
381
|
};
|
|
382
|
+
var sharp$3 = sharp___default["default"];
|
|
382
383
|
var diContainers = {
|
|
383
384
|
appContainer: null
|
|
384
385
|
};
|
|
@@ -458,6 +459,9 @@
|
|
|
458
459
|
return "";
|
|
459
460
|
return value[0].toLowerCase() + value.substr(1);
|
|
460
461
|
}
|
|
462
|
+
function isObjectId(id) {
|
|
463
|
+
return typeof id === "string" && id.length == 24 && !isNaN(Number("0x" + id));
|
|
464
|
+
}
|
|
461
465
|
function firstItem(value) {
|
|
462
466
|
return value[0];
|
|
463
467
|
}
|
|
@@ -675,6 +679,120 @@
|
|
|
675
679
|
});
|
|
676
680
|
});
|
|
677
681
|
}
|
|
682
|
+
var cropInterface = {
|
|
683
|
+
x: "number",
|
|
684
|
+
y: "number",
|
|
685
|
+
w: "number",
|
|
686
|
+
h: "number"
|
|
687
|
+
};
|
|
688
|
+
function toCropRegion(cropInfo) {
|
|
689
|
+
var crop = cropInfo;
|
|
690
|
+
if (isString(cropInfo)) {
|
|
691
|
+
try {
|
|
692
|
+
crop = JSON.parse(cropInfo);
|
|
693
|
+
}
|
|
694
|
+
catch (e) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (!isInterface(crop, cropInterface))
|
|
699
|
+
return null;
|
|
700
|
+
return {
|
|
701
|
+
width: Math.round(crop.w),
|
|
702
|
+
height: Math.round(crop.h),
|
|
703
|
+
top: Math.round(crop.y),
|
|
704
|
+
left: Math.round(crop.x)
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function toImage(src, params, meta) {
|
|
708
|
+
return __awaiter$w(this, void 0, void 0, function () {
|
|
709
|
+
var crop, buffer, _a, cropBefore, cropAfter, img, _b, width, height, canvasScaleX, canvasScaleY, e_3;
|
|
710
|
+
return __generator(this, function (_c) {
|
|
711
|
+
switch (_c.label) {
|
|
712
|
+
case 0:
|
|
713
|
+
// Default params and meta
|
|
714
|
+
params = params || {};
|
|
715
|
+
meta = meta || {};
|
|
716
|
+
crop = toCropRegion(meta.crop);
|
|
717
|
+
// Return the src if there are no params and no default crop exists
|
|
718
|
+
if (meta.extension === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
719
|
+
return [2 /*return*/, src];
|
|
720
|
+
}
|
|
721
|
+
// Parse params
|
|
722
|
+
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
723
|
+
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
724
|
+
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
|
|
725
|
+
params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
|
|
726
|
+
params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
|
|
727
|
+
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
728
|
+
if (!(src instanceof stream.Readable)) return [3 /*break*/, 2];
|
|
729
|
+
return [4 /*yield*/, streamToBuffer(src)];
|
|
730
|
+
case 1:
|
|
731
|
+
_a = _c.sent();
|
|
732
|
+
return [3 /*break*/, 3];
|
|
733
|
+
case 2:
|
|
734
|
+
_a = src;
|
|
735
|
+
_c.label = 3;
|
|
736
|
+
case 3:
|
|
737
|
+
buffer = _a;
|
|
738
|
+
_c.label = 4;
|
|
739
|
+
case 4:
|
|
740
|
+
_c.trys.push([4, 9, , 10]);
|
|
741
|
+
cropBefore = toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
742
|
+
cropAfter = toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
743
|
+
img = sharp$3(buffer);
|
|
744
|
+
return [4 /*yield*/, img.metadata()];
|
|
745
|
+
case 5:
|
|
746
|
+
_b = _c.sent(), width = _b.width, height = _b.height;
|
|
747
|
+
// Crop before resize
|
|
748
|
+
if (cropBefore) {
|
|
749
|
+
width = cropBefore.width;
|
|
750
|
+
height = cropBefore.height;
|
|
751
|
+
img = img.extract(cropBefore);
|
|
752
|
+
}
|
|
753
|
+
else if (crop) {
|
|
754
|
+
width = crop.width;
|
|
755
|
+
height = crop.height;
|
|
756
|
+
img = img.extract(crop);
|
|
757
|
+
}
|
|
758
|
+
canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
759
|
+
canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
760
|
+
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
761
|
+
width = Math.round(width * params.canvasScaleX);
|
|
762
|
+
height = Math.round(height * params.canvasScaleY);
|
|
763
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
|
|
764
|
+
}
|
|
765
|
+
// Resize image
|
|
766
|
+
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
767
|
+
width = Math.round(width * params.scaleX);
|
|
768
|
+
height = Math.round(height * params.scaleY);
|
|
769
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
|
|
770
|
+
}
|
|
771
|
+
// Crop after resize
|
|
772
|
+
if (cropAfter) {
|
|
773
|
+
img = img.extract(cropAfter);
|
|
774
|
+
}
|
|
775
|
+
if (!(params.rotation !== 0)) return [3 /*break*/, 7];
|
|
776
|
+
return [4 /*yield*/, img.toBuffer()];
|
|
777
|
+
case 6:
|
|
778
|
+
buffer = _c.sent();
|
|
779
|
+
img = sharp$3(buffer).rotate(params.rotation);
|
|
780
|
+
_c.label = 7;
|
|
781
|
+
case 7: return [4 /*yield*/, img.toBuffer()];
|
|
782
|
+
case 8:
|
|
783
|
+
buffer = _c.sent();
|
|
784
|
+
src = src instanceof stream.Readable ? bufferToStream(buffer) : buffer;
|
|
785
|
+
return [2 /*return*/, src];
|
|
786
|
+
case 9:
|
|
787
|
+
e_3 = _c.sent();
|
|
788
|
+
console.log("Image conversion error", e_3);
|
|
789
|
+
src = src instanceof stream.Readable ? bufferToStream(buffer) : buffer;
|
|
790
|
+
return [2 /*return*/, src];
|
|
791
|
+
case 10: return [2 /*return*/];
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
}
|
|
678
796
|
function bufferToStream(buffer) {
|
|
679
797
|
var readStream = new stream.PassThrough();
|
|
680
798
|
readStream.end(buffer);
|
|
@@ -859,7 +977,7 @@
|
|
|
859
977
|
return routingControllers.createParamDecorator({
|
|
860
978
|
required: false,
|
|
861
979
|
value: function (action) { return __awaiter$w(_this, void 0, void 0, function () {
|
|
862
|
-
var req, token, id, query, doc, _a, _b,
|
|
980
|
+
var req, token, id, query, doc, _a, _b, e_4;
|
|
863
981
|
return __generator(this, function (_c) {
|
|
864
982
|
switch (_c.label) {
|
|
865
983
|
case 0:
|
|
@@ -891,8 +1009,8 @@
|
|
|
891
1009
|
_a[_b] = (_c.sent()) || doc;
|
|
892
1010
|
return [2 /*return*/, action.request[paramName]];
|
|
893
1011
|
case 4:
|
|
894
|
-
|
|
895
|
-
throw new routingControllers.BadRequestError(modelName + " check error: " + (
|
|
1012
|
+
e_4 = _c.sent();
|
|
1013
|
+
throw new routingControllers.BadRequestError(modelName + " check error: " + (e_4.message || e_4));
|
|
896
1014
|
case 5:
|
|
897
1015
|
action.request[paramName] = doc;
|
|
898
1016
|
return [2 /*return*/, doc];
|
|
@@ -995,7 +1113,7 @@
|
|
|
995
1113
|
var defaultPredicate = function () { return true; };
|
|
996
1114
|
var ɵ0 = defaultPredicate;
|
|
997
1115
|
function copyRecursive(target, source, predicate) {
|
|
998
|
-
var
|
|
1116
|
+
var e_5, _a;
|
|
999
1117
|
predicate = predicate || defaultPredicate;
|
|
1000
1118
|
if (isPrimitive(source) || isDate(source) || isFunction(source))
|
|
1001
1119
|
return source;
|
|
@@ -1039,12 +1157,12 @@
|
|
|
1039
1157
|
target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate));
|
|
1040
1158
|
}
|
|
1041
1159
|
}
|
|
1042
|
-
catch (
|
|
1160
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1043
1161
|
finally {
|
|
1044
1162
|
try {
|
|
1045
1163
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1046
1164
|
}
|
|
1047
|
-
finally { if (
|
|
1165
|
+
finally { if (e_5) throw e_5.error; }
|
|
1048
1166
|
}
|
|
1049
1167
|
}
|
|
1050
1168
|
return target;
|
|
@@ -1322,7 +1440,7 @@
|
|
|
1322
1440
|
});
|
|
1323
1441
|
};
|
|
1324
1442
|
var AssetProcessor_1;
|
|
1325
|
-
var sharp$
|
|
1443
|
+
var sharp$2 = sharp___default["default"];
|
|
1326
1444
|
var fontKit = fontKit___default["default"];
|
|
1327
1445
|
var fontTypes = [
|
|
1328
1446
|
"application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
|
|
@@ -1411,7 +1529,7 @@
|
|
|
1411
1529
|
}
|
|
1412
1530
|
return [2 /*return*/, buffer];
|
|
1413
1531
|
}
|
|
1414
|
-
return [4 /*yield*/, sharp$
|
|
1532
|
+
return [4 /*yield*/, sharp$2(buffer).rotate().toBuffer({ resolveWithObject: true })];
|
|
1415
1533
|
case 1:
|
|
1416
1534
|
output = _b.sent();
|
|
1417
1535
|
Object.assign(metadata, output.info);
|
|
@@ -1687,13 +1805,6 @@
|
|
|
1687
1805
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1688
1806
|
});
|
|
1689
1807
|
};
|
|
1690
|
-
var sharp$2 = sharp___default["default"];
|
|
1691
|
-
var cropInterface = {
|
|
1692
|
-
x: "number",
|
|
1693
|
-
y: "number",
|
|
1694
|
-
w: "number",
|
|
1695
|
-
h: "number"
|
|
1696
|
-
};
|
|
1697
1808
|
var Asset = /** @class */ (function (_super) {
|
|
1698
1809
|
__extends(Asset, _super);
|
|
1699
1810
|
function Asset(id, data, collection, bucket) {
|
|
@@ -1701,103 +1812,6 @@
|
|
|
1701
1812
|
_this.bucket = bucket;
|
|
1702
1813
|
return _this;
|
|
1703
1814
|
}
|
|
1704
|
-
Asset.toCropRegion = function (cropInfo) {
|
|
1705
|
-
var crop = cropInfo;
|
|
1706
|
-
if (isString(cropInfo)) {
|
|
1707
|
-
try {
|
|
1708
|
-
crop = JSON.parse(cropInfo);
|
|
1709
|
-
}
|
|
1710
|
-
catch (e) {
|
|
1711
|
-
return null;
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
if (!isInterface(crop, cropInterface))
|
|
1715
|
-
return null;
|
|
1716
|
-
return {
|
|
1717
|
-
width: Math.round(crop.w),
|
|
1718
|
-
height: Math.round(crop.h),
|
|
1719
|
-
top: Math.round(crop.y),
|
|
1720
|
-
left: Math.round(crop.x)
|
|
1721
|
-
};
|
|
1722
|
-
};
|
|
1723
|
-
Asset.toImage = function (stream, meta, params) {
|
|
1724
|
-
return __awaiter$s(this, void 0, void 0, function () {
|
|
1725
|
-
var crop, buffer, cropBefore, cropAfter, img, _a, width, height, canvasScaleX, canvasScaleY, _b, e_1;
|
|
1726
|
-
return __generator(this, function (_c) {
|
|
1727
|
-
switch (_c.label) {
|
|
1728
|
-
case 0:
|
|
1729
|
-
params = params || {};
|
|
1730
|
-
crop = Asset.toCropRegion(meta.crop);
|
|
1731
|
-
// Return the stream if there is no params and no default crop exists
|
|
1732
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.extension) === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
1733
|
-
return [2 /*return*/, stream];
|
|
1734
|
-
}
|
|
1735
|
-
// Parse params
|
|
1736
|
-
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
1737
|
-
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
1738
|
-
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
|
|
1739
|
-
params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
|
|
1740
|
-
params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
|
|
1741
|
-
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
1742
|
-
return [4 /*yield*/, streamToBuffer(stream)];
|
|
1743
|
-
case 1:
|
|
1744
|
-
buffer = _c.sent();
|
|
1745
|
-
_c.label = 2;
|
|
1746
|
-
case 2:
|
|
1747
|
-
_c.trys.push([2, 7, , 8]);
|
|
1748
|
-
cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
1749
|
-
cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
1750
|
-
img = sharp$2(buffer);
|
|
1751
|
-
return [4 /*yield*/, img.metadata()];
|
|
1752
|
-
case 3:
|
|
1753
|
-
_a = _c.sent(), width = _a.width, height = _a.height;
|
|
1754
|
-
// Crop before resize
|
|
1755
|
-
if (cropBefore) {
|
|
1756
|
-
width = cropBefore.width;
|
|
1757
|
-
height = cropBefore.height;
|
|
1758
|
-
img = img.extract(cropBefore);
|
|
1759
|
-
}
|
|
1760
|
-
else if (crop) {
|
|
1761
|
-
width = crop.width;
|
|
1762
|
-
height = crop.height;
|
|
1763
|
-
img = img.extract(crop);
|
|
1764
|
-
}
|
|
1765
|
-
canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
1766
|
-
canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
1767
|
-
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
1768
|
-
width = Math.round(width * params.canvasScaleX);
|
|
1769
|
-
height = Math.round(height * params.canvasScaleY);
|
|
1770
|
-
img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
|
|
1771
|
-
}
|
|
1772
|
-
// Resize image
|
|
1773
|
-
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
1774
|
-
width = Math.round(width * params.scaleX);
|
|
1775
|
-
height = Math.round(height * params.scaleY);
|
|
1776
|
-
img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
|
|
1777
|
-
}
|
|
1778
|
-
// Crop after resize
|
|
1779
|
-
if (cropAfter) {
|
|
1780
|
-
img = img.extract(cropAfter);
|
|
1781
|
-
}
|
|
1782
|
-
if (!(params.rotation !== 0)) return [3 /*break*/, 5];
|
|
1783
|
-
return [4 /*yield*/, img.toBuffer()];
|
|
1784
|
-
case 4:
|
|
1785
|
-
buffer = _c.sent();
|
|
1786
|
-
img = sharp$2(buffer).rotate(params.rotation);
|
|
1787
|
-
_c.label = 5;
|
|
1788
|
-
case 5:
|
|
1789
|
-
_b = bufferToStream;
|
|
1790
|
-
return [4 /*yield*/, img.toBuffer()];
|
|
1791
|
-
case 6: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
|
|
1792
|
-
case 7:
|
|
1793
|
-
e_1 = _c.sent();
|
|
1794
|
-
console.log("Asset image conversion error", e_1);
|
|
1795
|
-
return [2 /*return*/, bufferToStream(buffer)];
|
|
1796
|
-
case 8: return [2 /*return*/];
|
|
1797
|
-
}
|
|
1798
|
-
});
|
|
1799
|
-
});
|
|
1800
|
-
};
|
|
1801
1815
|
Object.defineProperty(Asset.prototype, "filename", {
|
|
1802
1816
|
get: function () {
|
|
1803
1817
|
return this.data.filename;
|
|
@@ -1859,19 +1873,19 @@
|
|
|
1859
1873
|
if (params === void 0) { params = null; }
|
|
1860
1874
|
return __awaiter$s(this, void 0, void 0, function () {
|
|
1861
1875
|
return __generator(this, function (_a) {
|
|
1862
|
-
return [2 /*return*/,
|
|
1876
|
+
return [2 /*return*/, toImage(this.stream, params, this.metadata)];
|
|
1863
1877
|
});
|
|
1864
1878
|
});
|
|
1865
1879
|
};
|
|
1866
1880
|
Asset.prototype.downloadImage = function (params, metadata) {
|
|
1867
1881
|
return __awaiter$s(this, void 0, void 0, function () {
|
|
1868
|
-
var _a
|
|
1869
|
-
return __generator(this, function (
|
|
1870
|
-
switch (
|
|
1882
|
+
var _a;
|
|
1883
|
+
return __generator(this, function (_b) {
|
|
1884
|
+
switch (_b.label) {
|
|
1871
1885
|
case 0:
|
|
1872
|
-
|
|
1886
|
+
_a = toImage;
|
|
1873
1887
|
return [4 /*yield*/, this.download(metadata)];
|
|
1874
|
-
case 1: return [2 /*return*/,
|
|
1888
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), params, this.metadata])];
|
|
1875
1889
|
}
|
|
1876
1890
|
});
|
|
1877
1891
|
});
|
|
@@ -1936,7 +1950,7 @@
|
|
|
1936
1950
|
};
|
|
1937
1951
|
TempAsset.prototype.downloadImage = function (params, metadata) {
|
|
1938
1952
|
Object.assign(this.metadata, metadata || {});
|
|
1939
|
-
return
|
|
1953
|
+
return toImage(this.stream, params, this.metadata);
|
|
1940
1954
|
};
|
|
1941
1955
|
TempAsset.prototype.getImage = function (params) {
|
|
1942
1956
|
return this.downloadImage(params);
|
|
@@ -2177,6 +2191,19 @@
|
|
|
2177
2191
|
});
|
|
2178
2192
|
});
|
|
2179
2193
|
};
|
|
2194
|
+
Assets.prototype.deleteMany = function (where) {
|
|
2195
|
+
return __awaiter$q(this, void 0, void 0, function () {
|
|
2196
|
+
var assets;
|
|
2197
|
+
return __generator(this, function (_b) {
|
|
2198
|
+
switch (_b.label) {
|
|
2199
|
+
case 0: return [4 /*yield*/, this.findMany(where)];
|
|
2200
|
+
case 1:
|
|
2201
|
+
assets = _b.sent();
|
|
2202
|
+
return [2 /*return*/, Promise.all(assets.map(function (a) { return a.unlink(); }))];
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
});
|
|
2206
|
+
};
|
|
2180
2207
|
Assets.prototype.unlink = function (id) {
|
|
2181
2208
|
return __awaiter$q(this, void 0, void 0, function () {
|
|
2182
2209
|
var asset;
|
|
@@ -4855,6 +4882,19 @@
|
|
|
4855
4882
|
});
|
|
4856
4883
|
});
|
|
4857
4884
|
};
|
|
4885
|
+
AssetsController.prototype.getFile = function (id, lazy, res) {
|
|
4886
|
+
return __awaiter$7(this, void 0, void 0, function () {
|
|
4887
|
+
var asset;
|
|
4888
|
+
return __generator(this, function (_c) {
|
|
4889
|
+
switch (_c.label) {
|
|
4890
|
+
case 0: return [4 /*yield*/, this.getAsset("Asset", id, lazy, res)];
|
|
4891
|
+
case 1:
|
|
4892
|
+
asset = _c.sent();
|
|
4893
|
+
return [2 /*return*/, asset.download()];
|
|
4894
|
+
}
|
|
4895
|
+
});
|
|
4896
|
+
});
|
|
4897
|
+
};
|
|
4858
4898
|
AssetsController.prototype.getImageRotation = function (id, params, res, rotation) {
|
|
4859
4899
|
if (rotation === void 0) { rotation = 0; }
|
|
4860
4900
|
return __awaiter$7(this, void 0, void 0, function () {
|
|
@@ -4879,12 +4919,12 @@
|
|
|
4879
4919
|
});
|
|
4880
4920
|
});
|
|
4881
4921
|
};
|
|
4882
|
-
AssetsController.prototype.
|
|
4922
|
+
AssetsController.prototype.getFileByName = function (name, res) {
|
|
4883
4923
|
return __awaiter$7(this, void 0, void 0, function () {
|
|
4884
4924
|
var asset;
|
|
4885
4925
|
return __generator(this, function (_c) {
|
|
4886
4926
|
switch (_c.label) {
|
|
4887
|
-
case 0: return [4 /*yield*/, this.
|
|
4927
|
+
case 0: return [4 /*yield*/, this.getAssetByName("Asset", name, res)];
|
|
4888
4928
|
case 1:
|
|
4889
4929
|
asset = _c.sent();
|
|
4890
4930
|
return [2 /*return*/, asset.download()];
|
|
@@ -4892,10 +4932,35 @@
|
|
|
4892
4932
|
});
|
|
4893
4933
|
});
|
|
4894
4934
|
};
|
|
4895
|
-
AssetsController.prototype.
|
|
4935
|
+
AssetsController.prototype.getImageByName = function (name, params, res) {
|
|
4936
|
+
return __awaiter$7(this, void 0, void 0, function () {
|
|
4937
|
+
var asset;
|
|
4938
|
+
return __generator(this, function (_c) {
|
|
4939
|
+
switch (_c.label) {
|
|
4940
|
+
case 0: return [4 /*yield*/, this.getAssetByName("Image", name, res)];
|
|
4941
|
+
case 1:
|
|
4942
|
+
asset = _c.sent();
|
|
4943
|
+
return [2 /*return*/, asset.downloadImage(params)];
|
|
4944
|
+
}
|
|
4945
|
+
});
|
|
4946
|
+
});
|
|
4947
|
+
};
|
|
4948
|
+
AssetsController.prototype.setAssetHeaders = function (type, asset, res) {
|
|
4896
4949
|
var _a, _b;
|
|
4950
|
+
if ((_a = asset.metadata) === null || _a === void 0 ? void 0 : _a.classified) {
|
|
4951
|
+
throw new routingControllers.HttpError(403, type + " is classified, and can be only downloaded from a custom url.");
|
|
4952
|
+
}
|
|
4953
|
+
var ext = (_b = asset.metadata) === null || _b === void 0 ? void 0 : _b.extension;
|
|
4954
|
+
if (ext) {
|
|
4955
|
+
res.header("content-disposition", "inline; filename=" + asset.filename + "." + ext);
|
|
4956
|
+
}
|
|
4957
|
+
if (asset.contentType) {
|
|
4958
|
+
res.header("content-type", asset.contentType);
|
|
4959
|
+
}
|
|
4960
|
+
};
|
|
4961
|
+
AssetsController.prototype.getAsset = function (type, id, lazy, res) {
|
|
4897
4962
|
return __awaiter$7(this, void 0, void 0, function () {
|
|
4898
|
-
var asset
|
|
4963
|
+
var asset;
|
|
4899
4964
|
return __generator(this, function (_c) {
|
|
4900
4965
|
switch (_c.label) {
|
|
4901
4966
|
case 0: return [4 /*yield*/, this.assetResolver.resolve(id, lazy)];
|
|
@@ -4904,16 +4969,24 @@
|
|
|
4904
4969
|
if (!asset) {
|
|
4905
4970
|
throw new routingControllers.HttpError(404, type + " with id: '" + id + "' not found.");
|
|
4906
4971
|
}
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4972
|
+
this.setAssetHeaders(type, asset, res);
|
|
4973
|
+
return [2 /*return*/, asset];
|
|
4974
|
+
}
|
|
4975
|
+
});
|
|
4976
|
+
});
|
|
4977
|
+
};
|
|
4978
|
+
AssetsController.prototype.getAssetByName = function (type, filename, res) {
|
|
4979
|
+
return __awaiter$7(this, void 0, void 0, function () {
|
|
4980
|
+
var asset;
|
|
4981
|
+
return __generator(this, function (_c) {
|
|
4982
|
+
switch (_c.label) {
|
|
4983
|
+
case 0: return [4 /*yield*/, this.assets.find({ filename: filename })];
|
|
4984
|
+
case 1:
|
|
4985
|
+
asset = _c.sent();
|
|
4986
|
+
if (!asset) {
|
|
4987
|
+
throw new routingControllers.HttpError(404, type + " with filename: '" + filename + "' not found.");
|
|
4916
4988
|
}
|
|
4989
|
+
this.setAssetHeaders(type, asset, res);
|
|
4917
4990
|
return [2 /*return*/, asset];
|
|
4918
4991
|
}
|
|
4919
4992
|
});
|
|
@@ -4937,6 +5010,13 @@
|
|
|
4937
5010
|
__metadata$7("design:paramtypes", [Object]),
|
|
4938
5011
|
__metadata$7("design:returntype", Promise)
|
|
4939
5012
|
], AssetsController.prototype, "uploadUrl", null);
|
|
5013
|
+
__decorate$a([
|
|
5014
|
+
routingControllers.Get("/:id"),
|
|
5015
|
+
__param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParam("lazy")), __param$5(2, routingControllers.Res()),
|
|
5016
|
+
__metadata$7("design:type", Function),
|
|
5017
|
+
__metadata$7("design:paramtypes", [String, Boolean, Object]),
|
|
5018
|
+
__metadata$7("design:returntype", Promise)
|
|
5019
|
+
], AssetsController.prototype, "getFile", null);
|
|
4940
5020
|
__decorate$a([
|
|
4941
5021
|
routingControllers.Get("/image/:id/:rotation"),
|
|
4942
5022
|
__param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParams()), __param$5(2, routingControllers.Res()), __param$5(3, routingControllers.Param("rotation")),
|
|
@@ -4952,12 +5032,19 @@
|
|
|
4952
5032
|
__metadata$7("design:returntype", Promise)
|
|
4953
5033
|
], AssetsController.prototype, "getImage", null);
|
|
4954
5034
|
__decorate$a([
|
|
4955
|
-
routingControllers.Get("/:id"),
|
|
4956
|
-
__param$5(0, routingControllers.Param("
|
|
5035
|
+
routingControllers.Get("/by-name/:id"),
|
|
5036
|
+
__param$5(0, routingControllers.Param("name")), __param$5(1, routingControllers.Res()),
|
|
4957
5037
|
__metadata$7("design:type", Function),
|
|
4958
|
-
__metadata$7("design:paramtypes", [String,
|
|
5038
|
+
__metadata$7("design:paramtypes", [String, Object]),
|
|
4959
5039
|
__metadata$7("design:returntype", Promise)
|
|
4960
|
-
], AssetsController.prototype, "
|
|
5040
|
+
], AssetsController.prototype, "getFileByName", null);
|
|
5041
|
+
__decorate$a([
|
|
5042
|
+
routingControllers.Get("/by-name/image/:id"),
|
|
5043
|
+
__param$5(0, routingControllers.Param("name")), __param$5(1, routingControllers.QueryParams()), __param$5(2, routingControllers.Res()),
|
|
5044
|
+
__metadata$7("design:type", Function),
|
|
5045
|
+
__metadata$7("design:paramtypes", [String, Object, Object]),
|
|
5046
|
+
__metadata$7("design:returntype", Promise)
|
|
5047
|
+
], AssetsController.prototype, "getImageByName", null);
|
|
4961
5048
|
AssetsController = __decorate$a([
|
|
4962
5049
|
tsyringe.injectable(),
|
|
4963
5050
|
routingControllers.Controller("/assets"),
|
|
@@ -6264,6 +6351,7 @@
|
|
|
6264
6351
|
exports.isInterface = isInterface;
|
|
6265
6352
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
6266
6353
|
exports.isObject = isObject;
|
|
6354
|
+
exports.isObjectId = isObjectId;
|
|
6267
6355
|
exports.isPrimitive = isPrimitive;
|
|
6268
6356
|
exports.isString = isString;
|
|
6269
6357
|
exports.isType = isType;
|
|
@@ -6292,6 +6380,7 @@
|
|
|
6292
6380
|
exports.runCommand = runCommand;
|
|
6293
6381
|
exports.setupBackend = setupBackend;
|
|
6294
6382
|
exports.streamToBuffer = streamToBuffer;
|
|
6383
|
+
exports.toImage = toImage;
|
|
6295
6384
|
exports.ucFirst = ucFirst;
|
|
6296
6385
|
exports.uniqueItems = uniqueItems;
|
|
6297
6386
|
exports.valueToPromise = valueToPromise;
|