@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';
|
|
@@ -591,6 +592,28 @@ function padRight(value, count = 3, padWith = "0") {
|
|
|
591
592
|
function camelCaseToDash(str) {
|
|
592
593
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
593
594
|
}
|
|
595
|
+
function gzipPromised(data, opts) {
|
|
596
|
+
return new Promise((resolve, reject) => {
|
|
597
|
+
gzip(data, opts, (err, result) => {
|
|
598
|
+
if (err) {
|
|
599
|
+
reject(err);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
resolve(result.toString("base64"));
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function gunzipPromised(data, opts) {
|
|
607
|
+
return new Promise((resolve, reject) => {
|
|
608
|
+
gunzip(Buffer.from(data, "base64"), opts, (err, result) => {
|
|
609
|
+
if (err) {
|
|
610
|
+
reject(err);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
resolve(result.toString("utf8"));
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}
|
|
594
617
|
function deleteFromBucket(bucket, fileId) {
|
|
595
618
|
return new Promise(((resolve, reject) => {
|
|
596
619
|
bucket.delete(fileId, error => {
|
|
@@ -607,20 +630,22 @@ function deleteFromBucket(bucket, fileId) {
|
|
|
607
630
|
}));
|
|
608
631
|
}
|
|
609
632
|
const defaultPredicate = () => true;
|
|
610
|
-
function copyRecursive(target, source, predicate) {
|
|
611
|
-
predicate = predicate || defaultPredicate;
|
|
633
|
+
function copyRecursive(target, source, predicate, copies) {
|
|
612
634
|
if (isPrimitive(source) || isDate(source) || isFunction(source))
|
|
613
635
|
return source;
|
|
636
|
+
if (copies.has(source))
|
|
637
|
+
return copies.get(source);
|
|
614
638
|
if (isArray(source)) {
|
|
615
639
|
target = isArray(target) ? Array.from(target) : [];
|
|
616
640
|
source.forEach((item, index) => {
|
|
617
641
|
if (!predicate(item, index, target, source))
|
|
618
642
|
return;
|
|
619
643
|
if (target.length > index)
|
|
620
|
-
target[index] = copyRecursive(target[index], item, predicate);
|
|
644
|
+
target[index] = copyRecursive(target[index], item, predicate, copies);
|
|
621
645
|
else
|
|
622
|
-
target.push(copyRecursive(null, item, predicate));
|
|
646
|
+
target.push(copyRecursive(null, item, predicate, copies));
|
|
623
647
|
});
|
|
648
|
+
copies.set(source, target);
|
|
624
649
|
return target;
|
|
625
650
|
}
|
|
626
651
|
if (isBuffer(source))
|
|
@@ -644,24 +669,25 @@ function copyRecursive(target, source, predicate) {
|
|
|
644
669
|
else {
|
|
645
670
|
target = Object.assign({}, target || {});
|
|
646
671
|
}
|
|
672
|
+
// Set to copies to prevent circular references
|
|
673
|
+
copies.set(source, target);
|
|
647
674
|
// Copy map entries
|
|
648
675
|
if (target instanceof Map) {
|
|
649
676
|
if (source instanceof Map) {
|
|
650
677
|
for (let [key, value] of source.entries()) {
|
|
651
678
|
if (!predicate(value, key, target, source))
|
|
652
679
|
continue;
|
|
653
|
-
target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate));
|
|
680
|
+
target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate, copies));
|
|
654
681
|
}
|
|
655
682
|
}
|
|
656
683
|
return target;
|
|
657
684
|
}
|
|
658
685
|
// Copy object members
|
|
659
686
|
let keys = Object.keys(source);
|
|
660
|
-
|
|
661
|
-
if (!predicate(source[key], key,
|
|
662
|
-
return
|
|
663
|
-
|
|
664
|
-
return result;
|
|
687
|
+
keys.forEach(key => {
|
|
688
|
+
if (!predicate(source[key], key, target, source))
|
|
689
|
+
return;
|
|
690
|
+
target[key] = !shouldCopy(key, source[key]) ? source[key] : copyRecursive(target[key], source[key], predicate, copies);
|
|
665
691
|
}, target);
|
|
666
692
|
// Copy object properties
|
|
667
693
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
@@ -672,13 +698,13 @@ function copyRecursive(target, source, predicate) {
|
|
|
672
698
|
return target;
|
|
673
699
|
}
|
|
674
700
|
function filter(obj, predicate) {
|
|
675
|
-
return copyRecursive(null, obj, predicate);
|
|
701
|
+
return copyRecursive(null, obj, predicate || defaultPredicate, new Map());
|
|
676
702
|
}
|
|
677
703
|
function copy(obj) {
|
|
678
|
-
return copyRecursive(null, obj);
|
|
704
|
+
return copyRecursive(null, obj, defaultPredicate, new Map());
|
|
679
705
|
}
|
|
680
706
|
function assign(target, source, predicate) {
|
|
681
|
-
return copyRecursive(target, source, predicate);
|
|
707
|
+
return copyRecursive(target, source, predicate, new Map());
|
|
682
708
|
}
|
|
683
709
|
function md5(data) {
|
|
684
710
|
if (isObject(data)) {
|
|
@@ -1211,6 +1237,13 @@ class LazyAsset extends BaseEntity {
|
|
|
1211
1237
|
});
|
|
1212
1238
|
});
|
|
1213
1239
|
}
|
|
1240
|
+
async load() {
|
|
1241
|
+
await super.load();
|
|
1242
|
+
if (this.deleted)
|
|
1243
|
+
return this;
|
|
1244
|
+
this.data.jobParams = JSON.parse(await gunzipPromised(this.data.jobParams));
|
|
1245
|
+
return this;
|
|
1246
|
+
}
|
|
1214
1247
|
async loadAsset() {
|
|
1215
1248
|
await this.load();
|
|
1216
1249
|
if (this.deleted)
|
|
@@ -1701,8 +1734,9 @@ let LazyAssets = class LazyAssets {
|
|
|
1701
1734
|
this.jobMan = jobMan;
|
|
1702
1735
|
this.collection = connector.database.collection("lazyassets");
|
|
1703
1736
|
}
|
|
1704
|
-
async create(jobType,
|
|
1705
|
-
const jobName = this.jobMan.tryResolve(jobType, { ...
|
|
1737
|
+
async create(jobType, jobParamsObj = {}, jobQue = "main") {
|
|
1738
|
+
const jobName = this.jobMan.tryResolve(jobType, { ...jobParamsObj, lazyId: "" });
|
|
1739
|
+
const jobParams = await gzipPromised(JSON.stringify(jobParamsObj));
|
|
1706
1740
|
const data = {
|
|
1707
1741
|
jobName,
|
|
1708
1742
|
jobParams,
|
|
@@ -2713,6 +2747,13 @@ let AssetsController = class AssetsController {
|
|
|
2713
2747
|
const asset = await this.getAsset("Asset", id, lazy, res);
|
|
2714
2748
|
return asset.download();
|
|
2715
2749
|
}
|
|
2750
|
+
async getMetadata(id, lazy, res) {
|
|
2751
|
+
const asset = await this.assetResolver.resolve(id, lazy);
|
|
2752
|
+
if (!asset) {
|
|
2753
|
+
throw new HttpError(404, `Asset with id: '${id}' not found.`);
|
|
2754
|
+
}
|
|
2755
|
+
return asset.metadata;
|
|
2756
|
+
}
|
|
2716
2757
|
async getImageRotation(id, params, res, rotation = 0) {
|
|
2717
2758
|
const asset = await this.getAsset("Image", id, params.lazy, res);
|
|
2718
2759
|
if (rotation !== 0) {
|
|
@@ -2785,6 +2826,15 @@ __decorate([
|
|
|
2785
2826
|
__metadata("design:paramtypes", [String, Boolean, Object]),
|
|
2786
2827
|
__metadata("design:returntype", Promise)
|
|
2787
2828
|
], AssetsController.prototype, "getFile", null);
|
|
2829
|
+
__decorate([
|
|
2830
|
+
Get("/metadata/:id"),
|
|
2831
|
+
__param(0, Param("id")),
|
|
2832
|
+
__param(1, QueryParam("lazy")),
|
|
2833
|
+
__param(2, Res()),
|
|
2834
|
+
__metadata("design:type", Function),
|
|
2835
|
+
__metadata("design:paramtypes", [String, Boolean, Object]),
|
|
2836
|
+
__metadata("design:returntype", Promise)
|
|
2837
|
+
], AssetsController.prototype, "getMetadata", null);
|
|
2788
2838
|
__decorate([
|
|
2789
2839
|
Get("/image/:id/:rotation"),
|
|
2790
2840
|
__param(0, Param("id")),
|
|
@@ -4317,5 +4367,5 @@ async function setupBackend(config, providers, parent) {
|
|
|
4317
4367
|
* Generated bundle index. Do not edit.
|
|
4318
4368
|
*/
|
|
4319
4369
|
|
|
4320
|
-
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 };
|
|
4370
|
+
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 };
|
|
4321
4371
|
//# sourceMappingURL=stemy-backend.mjs.map
|