@stemy/backend 5.0.4 → 5.0.7
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/esm2020/public_api.mjs +2 -2
- package/esm2020/rest-controllers/assets.controller.mjs +17 -1
- package/esm2020/services/configuration.mjs +1 -1
- package/esm2020/services/entities/lazy-asset.mjs +9 -2
- package/esm2020/services/lazy-assets.mjs +5 -3
- package/esm2020/utils.mjs +40 -14
- package/fesm2015/stemy-backend.mjs +73 -16
- package/fesm2015/stemy-backend.mjs.map +1 -1
- package/fesm2020/stemy-backend.mjs +66 -16
- package/fesm2020/stemy-backend.mjs.map +1 -1
- package/package.json +5 -4
- package/public_api.d.ts +1 -1
- package/rest-controllers/assets.controller.d.ts +1 -0
- package/services/entities/lazy-asset.d.ts +1 -0
- package/services/lazy-assets.d.ts +1 -1
- package/utils.d.ts +4 -0
|
@@ -10,6 +10,7 @@ import sharp_ from 'sharp';
|
|
|
10
10
|
import { ObjectId as ObjectId$1 } from 'bson';
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync } from 'fs';
|
|
13
|
+
import { gzip, gunzip } from 'zlib';
|
|
13
14
|
import { fileURLToPath } from 'url';
|
|
14
15
|
import { exec } from 'child_process';
|
|
15
16
|
import { createHash } from 'crypto';
|
|
@@ -601,6 +602,28 @@ function padRight(value, count = 3, padWith = "0") {
|
|
|
601
602
|
function camelCaseToDash(str) {
|
|
602
603
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
603
604
|
}
|
|
605
|
+
function gzipPromised(data, opts) {
|
|
606
|
+
return new Promise((resolve, reject) => {
|
|
607
|
+
gzip(data, opts, (err, result) => {
|
|
608
|
+
if (err) {
|
|
609
|
+
reject(err);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
resolve(result.toString("base64"));
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function gunzipPromised(data, opts) {
|
|
617
|
+
return new Promise((resolve, reject) => {
|
|
618
|
+
gunzip(Buffer.from(data, "base64"), opts, (err, result) => {
|
|
619
|
+
if (err) {
|
|
620
|
+
reject(err);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
resolve(result.toString("utf8"));
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
}
|
|
604
627
|
function deleteFromBucket(bucket, fileId) {
|
|
605
628
|
return new Promise(((resolve, reject) => {
|
|
606
629
|
bucket.delete(fileId, error => {
|
|
@@ -617,20 +640,22 @@ function deleteFromBucket(bucket, fileId) {
|
|
|
617
640
|
}));
|
|
618
641
|
}
|
|
619
642
|
const defaultPredicate = () => true;
|
|
620
|
-
function copyRecursive(target, source, predicate) {
|
|
621
|
-
predicate = predicate || defaultPredicate;
|
|
643
|
+
function copyRecursive(target, source, predicate, copies) {
|
|
622
644
|
if (isPrimitive(source) || isDate(source) || isFunction(source))
|
|
623
645
|
return source;
|
|
646
|
+
if (copies.has(source))
|
|
647
|
+
return copies.get(source);
|
|
624
648
|
if (isArray(source)) {
|
|
625
649
|
target = isArray(target) ? Array.from(target) : [];
|
|
626
650
|
source.forEach((item, index) => {
|
|
627
651
|
if (!predicate(item, index, target, source))
|
|
628
652
|
return;
|
|
629
653
|
if (target.length > index)
|
|
630
|
-
target[index] = copyRecursive(target[index], item, predicate);
|
|
654
|
+
target[index] = copyRecursive(target[index], item, predicate, copies);
|
|
631
655
|
else
|
|
632
|
-
target.push(copyRecursive(null, item, predicate));
|
|
656
|
+
target.push(copyRecursive(null, item, predicate, copies));
|
|
633
657
|
});
|
|
658
|
+
copies.set(source, target);
|
|
634
659
|
return target;
|
|
635
660
|
}
|
|
636
661
|
if (isBuffer(source))
|
|
@@ -654,24 +679,25 @@ function copyRecursive(target, source, predicate) {
|
|
|
654
679
|
else {
|
|
655
680
|
target = Object.assign({}, target || {});
|
|
656
681
|
}
|
|
682
|
+
// Set to copies to prevent circular references
|
|
683
|
+
copies.set(source, target);
|
|
657
684
|
// Copy map entries
|
|
658
685
|
if (target instanceof Map) {
|
|
659
686
|
if (source instanceof Map) {
|
|
660
687
|
for (let [key, value] of source.entries()) {
|
|
661
688
|
if (!predicate(value, key, target, source))
|
|
662
689
|
continue;
|
|
663
|
-
target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate));
|
|
690
|
+
target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate, copies));
|
|
664
691
|
}
|
|
665
692
|
}
|
|
666
693
|
return target;
|
|
667
694
|
}
|
|
668
695
|
// Copy object members
|
|
669
696
|
let keys = Object.keys(source);
|
|
670
|
-
|
|
671
|
-
if (!predicate(source[key], key,
|
|
672
|
-
return
|
|
673
|
-
|
|
674
|
-
return result;
|
|
697
|
+
keys.forEach(key => {
|
|
698
|
+
if (!predicate(source[key], key, target, source))
|
|
699
|
+
return;
|
|
700
|
+
target[key] = !shouldCopy(key, source[key]) ? source[key] : copyRecursive(target[key], source[key], predicate, copies);
|
|
675
701
|
}, target);
|
|
676
702
|
// Copy object properties
|
|
677
703
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
@@ -682,13 +708,13 @@ function copyRecursive(target, source, predicate) {
|
|
|
682
708
|
return target;
|
|
683
709
|
}
|
|
684
710
|
function filter(obj, predicate) {
|
|
685
|
-
return copyRecursive(null, obj, predicate);
|
|
711
|
+
return copyRecursive(null, obj, predicate || defaultPredicate, new Map());
|
|
686
712
|
}
|
|
687
713
|
function copy(obj) {
|
|
688
|
-
return copyRecursive(null, obj);
|
|
714
|
+
return copyRecursive(null, obj, defaultPredicate, new Map());
|
|
689
715
|
}
|
|
690
716
|
function assign(target, source, predicate) {
|
|
691
|
-
return copyRecursive(target, source, predicate);
|
|
717
|
+
return copyRecursive(target, source, predicate, new Map());
|
|
692
718
|
}
|
|
693
719
|
function md5(data) {
|
|
694
720
|
if (isObject(data)) {
|
|
@@ -1272,6 +1298,18 @@ class LazyAsset extends BaseEntity {
|
|
|
1272
1298
|
});
|
|
1273
1299
|
});
|
|
1274
1300
|
}
|
|
1301
|
+
load() {
|
|
1302
|
+
const _super = Object.create(null, {
|
|
1303
|
+
load: { get: () => super.load }
|
|
1304
|
+
});
|
|
1305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1306
|
+
yield _super.load.call(this);
|
|
1307
|
+
if (this.deleted)
|
|
1308
|
+
return this;
|
|
1309
|
+
this.data.jobParams = JSON.parse(yield gunzipPromised(this.data.jobParams));
|
|
1310
|
+
return this;
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1275
1313
|
loadAsset() {
|
|
1276
1314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1277
1315
|
yield this.load();
|
|
@@ -1818,9 +1856,10 @@ let LazyAssets = class LazyAssets {
|
|
|
1818
1856
|
this.jobMan = jobMan;
|
|
1819
1857
|
this.collection = connector.database.collection("lazyassets");
|
|
1820
1858
|
}
|
|
1821
|
-
create(jobType,
|
|
1859
|
+
create(jobType, jobParamsObj = {}, jobQue = "main") {
|
|
1822
1860
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1823
|
-
const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({},
|
|
1861
|
+
const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParamsObj), { lazyId: "" }));
|
|
1862
|
+
const jobParams = yield gzipPromised(JSON.stringify(jobParamsObj));
|
|
1824
1863
|
const data = {
|
|
1825
1864
|
jobName,
|
|
1826
1865
|
jobParams,
|
|
@@ -2890,6 +2929,15 @@ let AssetsController = class AssetsController {
|
|
|
2890
2929
|
return asset.download();
|
|
2891
2930
|
});
|
|
2892
2931
|
}
|
|
2932
|
+
getMetadata(id, lazy, res) {
|
|
2933
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2934
|
+
const asset = yield this.assetResolver.resolve(id, lazy);
|
|
2935
|
+
if (!asset) {
|
|
2936
|
+
throw new HttpError(404, `Asset with id: '${id}' not found.`);
|
|
2937
|
+
}
|
|
2938
|
+
return asset.metadata;
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2893
2941
|
getImageRotation(id, params, res, rotation = 0) {
|
|
2894
2942
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2895
2943
|
const asset = yield this.getAsset("Image", id, params.lazy, res);
|
|
@@ -2975,6 +3023,15 @@ __decorate([
|
|
|
2975
3023
|
__metadata("design:paramtypes", [String, Boolean, Object]),
|
|
2976
3024
|
__metadata("design:returntype", Promise)
|
|
2977
3025
|
], AssetsController.prototype, "getFile", null);
|
|
3026
|
+
__decorate([
|
|
3027
|
+
Get("/metadata/:id"),
|
|
3028
|
+
__param(0, Param("id")),
|
|
3029
|
+
__param(1, QueryParam("lazy")),
|
|
3030
|
+
__param(2, Res()),
|
|
3031
|
+
__metadata("design:type", Function),
|
|
3032
|
+
__metadata("design:paramtypes", [String, Boolean, Object]),
|
|
3033
|
+
__metadata("design:returntype", Promise)
|
|
3034
|
+
], AssetsController.prototype, "getMetadata", null);
|
|
2978
3035
|
__decorate([
|
|
2979
3036
|
Get("/image/:id/:rotation"),
|
|
2980
3037
|
__param(0, Param("id")),
|
|
@@ -4537,5 +4594,5 @@ function setupBackend(config, providers, parent) {
|
|
|
4537
4594
|
* Generated bundle index. Do not edit.
|
|
4538
4595
|
*/
|
|
4539
4596
|
|
|
4540
|
-
export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
|
|
4597
|
+
export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, gunzipPromised, gzipPromised, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
|
|
4541
4598
|
//# sourceMappingURL=stemy-backend.mjs.map
|