@stemy/backend 3.1.7 → 3.2.2
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 +262 -147
- 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 +2 -1
- package/esm2015/common-types.js +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 +127 -6
- package/fesm2015/stemy-backend.js +195 -123
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +2 -2
- 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 +14 -2
|
@@ -2,7 +2,7 @@ import { dirname, basename, join, resolve } from 'path';
|
|
|
2
2
|
import { json } from 'body-parser';
|
|
3
3
|
import { sign, verify } from 'jsonwebtoken';
|
|
4
4
|
import { injectable, scoped, Lifecycle, injectAll, singleton, inject, isFactoryProvider, container } from 'tsyringe';
|
|
5
|
-
import { createParamDecorator, BadRequestError, HttpError, getMetadataArgsStorage, Authorized, Post, UploadedFile, Body, Get, Param,
|
|
5
|
+
import { createParamDecorator, BadRequestError, HttpError, getMetadataArgsStorage, Authorized, Post, UploadedFile, Body, Get, Param, QueryParam, Res, QueryParams, Controller, CurrentUser, Middleware, useContainer, useExpressServer } from 'routing-controllers';
|
|
6
6
|
import { OnMessage, ConnectedSocket, MessageBody, SocketController, Middleware as Middleware$1, useContainer as useContainer$1, useSocketServer } from 'socket-controllers';
|
|
7
7
|
import { routingControllersToSpec } from 'routing-controllers-openapi';
|
|
8
8
|
import { defaultMetadataStorage } from 'class-transformer/storage';
|
|
@@ -15,11 +15,11 @@ import { canReportError } from 'rxjs/internal/util/canReportError';
|
|
|
15
15
|
import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync } from 'fs';
|
|
16
16
|
import { Types, model, connect } from 'mongoose';
|
|
17
17
|
import { getValue as getValue$1, setValue } from 'mongoose/lib/utils';
|
|
18
|
-
import {
|
|
18
|
+
import { Readable, PassThrough } from 'stream';
|
|
19
19
|
import { ObjectId } from 'bson';
|
|
20
|
+
import sharp_ from 'sharp';
|
|
20
21
|
import fontKit_ from 'fontkit';
|
|
21
22
|
import { fromBuffer } from 'file-type';
|
|
22
|
-
import sharp_ from 'sharp';
|
|
23
23
|
import axios from 'axios';
|
|
24
24
|
import { GridFSBucket } from 'mongodb';
|
|
25
25
|
import dotenv from 'dotenv';
|
|
@@ -44,6 +44,7 @@ var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
44
44
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
+
const sharp$3 = sharp_;
|
|
47
48
|
const diContainers = {
|
|
48
49
|
appContainer: null
|
|
49
50
|
};
|
|
@@ -112,6 +113,9 @@ function lcFirst(value) {
|
|
|
112
113
|
return "";
|
|
113
114
|
return value[0].toLowerCase() + value.substr(1);
|
|
114
115
|
}
|
|
116
|
+
function isObjectId(id) {
|
|
117
|
+
return typeof id === "string" && id.length == 24 && !isNaN(Number("0x" + id));
|
|
118
|
+
}
|
|
115
119
|
function firstItem(value) {
|
|
116
120
|
return value[0];
|
|
117
121
|
}
|
|
@@ -134,6 +138,9 @@ function regroup(value, comparator) {
|
|
|
134
138
|
});
|
|
135
139
|
return result;
|
|
136
140
|
}
|
|
141
|
+
function uniqueItems(value) {
|
|
142
|
+
return value.filter((v, ix) => value.indexOf(v) === ix);
|
|
143
|
+
}
|
|
137
144
|
function getValue(obj, key, defaultValue, treeFallback = false) {
|
|
138
145
|
key = key || "";
|
|
139
146
|
const keys = key.split(".");
|
|
@@ -209,7 +216,7 @@ function paginate(model, where, params) {
|
|
|
209
216
|
});
|
|
210
217
|
});
|
|
211
218
|
}
|
|
212
|
-
function
|
|
219
|
+
function lookupStages(from, localField, as = null, foreignField = "_id", shouldUnwind = true) {
|
|
213
220
|
as = as || localField.replace("Id", "");
|
|
214
221
|
const pipelines = [
|
|
215
222
|
{
|
|
@@ -219,15 +226,29 @@ function lookupPipelines(from, localField, as = null, foreignField = "_id", shou
|
|
|
219
226
|
foreignField,
|
|
220
227
|
as
|
|
221
228
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
229
|
+
}
|
|
230
|
+
];
|
|
231
|
+
if (shouldUnwind) {
|
|
232
|
+
pipelines.push({
|
|
224
233
|
$unwind: {
|
|
225
234
|
path: `$${as}`,
|
|
226
235
|
preserveNullAndEmptyArrays: true
|
|
227
236
|
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return pipelines;
|
|
240
|
+
}
|
|
241
|
+
function letsLookupStage(from, pipeline, as = null, letFields = null) {
|
|
242
|
+
as = as || from;
|
|
243
|
+
letFields = letFields || { id: "$_id" };
|
|
244
|
+
return {
|
|
245
|
+
$lookup: {
|
|
246
|
+
from,
|
|
247
|
+
let: letFields,
|
|
248
|
+
pipeline,
|
|
249
|
+
as
|
|
228
250
|
}
|
|
229
|
-
|
|
230
|
-
return shouldUnwind ? pipelines : pipelines.slice(0, 0);
|
|
251
|
+
};
|
|
231
252
|
}
|
|
232
253
|
function hydratePopulated(modelType, json) {
|
|
233
254
|
let object = modelType.hydrate(json);
|
|
@@ -284,6 +305,102 @@ function paginateAggregations(model, aggregations, params, metaProjection = {})
|
|
|
284
305
|
return pagination;
|
|
285
306
|
});
|
|
286
307
|
}
|
|
308
|
+
const cropInterface = {
|
|
309
|
+
x: "number",
|
|
310
|
+
y: "number",
|
|
311
|
+
w: "number",
|
|
312
|
+
h: "number"
|
|
313
|
+
};
|
|
314
|
+
function toCropRegion(cropInfo) {
|
|
315
|
+
let crop = cropInfo;
|
|
316
|
+
if (isString(cropInfo)) {
|
|
317
|
+
try {
|
|
318
|
+
crop = JSON.parse(cropInfo);
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!isInterface(crop, cropInterface))
|
|
325
|
+
return null;
|
|
326
|
+
return {
|
|
327
|
+
width: Math.round(crop.w),
|
|
328
|
+
height: Math.round(crop.h),
|
|
329
|
+
top: Math.round(crop.y),
|
|
330
|
+
left: Math.round(crop.x)
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function toImage(src, params, meta) {
|
|
334
|
+
return __awaiter$w(this, void 0, void 0, function* () {
|
|
335
|
+
// Default params and meta
|
|
336
|
+
params = params || {};
|
|
337
|
+
meta = meta || {};
|
|
338
|
+
// Get default crop info
|
|
339
|
+
const crop = toCropRegion(meta.crop);
|
|
340
|
+
// Return the src if there are no params and no default crop exists
|
|
341
|
+
if (meta.extension === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
342
|
+
return src;
|
|
343
|
+
}
|
|
344
|
+
// Parse params
|
|
345
|
+
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
346
|
+
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
347
|
+
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
|
|
348
|
+
params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
|
|
349
|
+
params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
|
|
350
|
+
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
351
|
+
let buffer = src instanceof Readable ? yield streamToBuffer(src) : src;
|
|
352
|
+
try {
|
|
353
|
+
// Get crop info
|
|
354
|
+
const cropBefore = toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
355
|
+
const cropAfter = toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
356
|
+
// Get metadata
|
|
357
|
+
let img = sharp$3(buffer);
|
|
358
|
+
let { width, height } = yield img.metadata();
|
|
359
|
+
// Crop before resize
|
|
360
|
+
if (cropBefore) {
|
|
361
|
+
width = cropBefore.width;
|
|
362
|
+
height = cropBefore.height;
|
|
363
|
+
img = img.extract(cropBefore);
|
|
364
|
+
}
|
|
365
|
+
else if (crop) {
|
|
366
|
+
width = crop.width;
|
|
367
|
+
height = crop.height;
|
|
368
|
+
img = img.extract(crop);
|
|
369
|
+
}
|
|
370
|
+
// Resize canvas
|
|
371
|
+
const canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
372
|
+
const canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
373
|
+
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
374
|
+
width = Math.round(width * params.canvasScaleX);
|
|
375
|
+
height = Math.round(height * params.canvasScaleY);
|
|
376
|
+
img = img.resize({ width, height, background: "#00000000", fit: "contain" });
|
|
377
|
+
}
|
|
378
|
+
// Resize image
|
|
379
|
+
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
380
|
+
width = Math.round(width * params.scaleX);
|
|
381
|
+
height = Math.round(height * params.scaleY);
|
|
382
|
+
img = img.resize({ width, height, background: "#00000000", fit: "fill" });
|
|
383
|
+
}
|
|
384
|
+
// Crop after resize
|
|
385
|
+
if (cropAfter) {
|
|
386
|
+
img = img.extract(cropAfter);
|
|
387
|
+
}
|
|
388
|
+
// Rotate
|
|
389
|
+
if (params.rotation !== 0) {
|
|
390
|
+
buffer = yield img.toBuffer();
|
|
391
|
+
img = sharp$3(buffer).rotate(params.rotation);
|
|
392
|
+
}
|
|
393
|
+
buffer = yield img.toBuffer();
|
|
394
|
+
src = src instanceof Readable ? bufferToStream(buffer) : buffer;
|
|
395
|
+
return src;
|
|
396
|
+
}
|
|
397
|
+
catch (e) {
|
|
398
|
+
console.log("Image conversion error", e);
|
|
399
|
+
src = src instanceof Readable ? bufferToStream(buffer) : buffer;
|
|
400
|
+
return src;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
287
404
|
function bufferToStream(buffer) {
|
|
288
405
|
const readStream = new PassThrough();
|
|
289
406
|
readStream.end(buffer);
|
|
@@ -724,6 +841,9 @@ function jsonHighlight(input, colorOptions) {
|
|
|
724
841
|
}
|
|
725
842
|
return `${color}${match}${ConsoleColor.Reset}`;
|
|
726
843
|
});
|
|
844
|
+
}
|
|
845
|
+
function replaceSpecialChars(str, to = "-") {
|
|
846
|
+
return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
|
|
727
847
|
}
|
|
728
848
|
|
|
729
849
|
var __decorate$x = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -844,7 +964,7 @@ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
844
964
|
});
|
|
845
965
|
};
|
|
846
966
|
var AssetProcessor_1;
|
|
847
|
-
const sharp$
|
|
967
|
+
const sharp$2 = sharp_;
|
|
848
968
|
const fontKit = fontKit_;
|
|
849
969
|
const fontTypes = [
|
|
850
970
|
"application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
|
|
@@ -920,7 +1040,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
|
|
|
920
1040
|
}
|
|
921
1041
|
return buffer;
|
|
922
1042
|
}
|
|
923
|
-
const output = yield sharp$
|
|
1043
|
+
const output = yield sharp$2(buffer).rotate().toBuffer({ resolveWithObject: true });
|
|
924
1044
|
Object.assign(metadata, output.info);
|
|
925
1045
|
return output.data;
|
|
926
1046
|
});
|
|
@@ -1106,104 +1226,11 @@ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
1106
1226
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1107
1227
|
});
|
|
1108
1228
|
};
|
|
1109
|
-
const sharp$2 = sharp_;
|
|
1110
|
-
const cropInterface = {
|
|
1111
|
-
x: "number",
|
|
1112
|
-
y: "number",
|
|
1113
|
-
w: "number",
|
|
1114
|
-
h: "number"
|
|
1115
|
-
};
|
|
1116
1229
|
class Asset extends BaseEntity {
|
|
1117
1230
|
constructor(id, data, collection, bucket) {
|
|
1118
1231
|
super(id, data, collection);
|
|
1119
1232
|
this.bucket = bucket;
|
|
1120
1233
|
}
|
|
1121
|
-
static toCropRegion(cropInfo) {
|
|
1122
|
-
let crop = cropInfo;
|
|
1123
|
-
if (isString(cropInfo)) {
|
|
1124
|
-
try {
|
|
1125
|
-
crop = JSON.parse(cropInfo);
|
|
1126
|
-
}
|
|
1127
|
-
catch (e) {
|
|
1128
|
-
return null;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
if (!isInterface(crop, cropInterface))
|
|
1132
|
-
return null;
|
|
1133
|
-
return {
|
|
1134
|
-
width: Math.round(crop.w),
|
|
1135
|
-
height: Math.round(crop.h),
|
|
1136
|
-
top: Math.round(crop.y),
|
|
1137
|
-
left: Math.round(crop.x)
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
static toImage(stream, meta, params) {
|
|
1141
|
-
return __awaiter$s(this, void 0, void 0, function* () {
|
|
1142
|
-
params = params || {};
|
|
1143
|
-
// Get default crop info
|
|
1144
|
-
const crop = Asset.toCropRegion(meta.crop);
|
|
1145
|
-
// Return the stream if there is no params and no default crop exists
|
|
1146
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.extension) === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
1147
|
-
return stream;
|
|
1148
|
-
}
|
|
1149
|
-
// Parse params
|
|
1150
|
-
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
1151
|
-
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
1152
|
-
params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
|
|
1153
|
-
params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
|
|
1154
|
-
params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
|
|
1155
|
-
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
1156
|
-
// Try to modify image
|
|
1157
|
-
let buffer = yield streamToBuffer(stream);
|
|
1158
|
-
try {
|
|
1159
|
-
// Get crop info
|
|
1160
|
-
const cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
1161
|
-
const cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
1162
|
-
// Get metadata
|
|
1163
|
-
let img = sharp$2(buffer);
|
|
1164
|
-
let { width, height } = yield img.metadata();
|
|
1165
|
-
// Crop before resize
|
|
1166
|
-
if (cropBefore) {
|
|
1167
|
-
width = cropBefore.width;
|
|
1168
|
-
height = cropBefore.height;
|
|
1169
|
-
img = img.extract(cropBefore);
|
|
1170
|
-
}
|
|
1171
|
-
else if (crop) {
|
|
1172
|
-
width = crop.width;
|
|
1173
|
-
height = crop.height;
|
|
1174
|
-
img = img.extract(crop);
|
|
1175
|
-
}
|
|
1176
|
-
// Resize canvas
|
|
1177
|
-
const canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
1178
|
-
const canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
1179
|
-
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
1180
|
-
width = Math.round(width * params.canvasScaleX);
|
|
1181
|
-
height = Math.round(height * params.canvasScaleY);
|
|
1182
|
-
img = img.resize({ width, height, background: "#00000000", fit: "contain" });
|
|
1183
|
-
}
|
|
1184
|
-
// Resize image
|
|
1185
|
-
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
1186
|
-
width = Math.round(width * params.scaleX);
|
|
1187
|
-
height = Math.round(height * params.scaleY);
|
|
1188
|
-
img = img.resize({ width, height, background: "#00000000", fit: "fill" });
|
|
1189
|
-
}
|
|
1190
|
-
// Crop after resize
|
|
1191
|
-
if (cropAfter) {
|
|
1192
|
-
img = img.extract(cropAfter);
|
|
1193
|
-
}
|
|
1194
|
-
// Rotate
|
|
1195
|
-
if (params.rotation !== 0) {
|
|
1196
|
-
buffer = yield img.toBuffer();
|
|
1197
|
-
img = sharp$2(buffer).rotate(params.rotation);
|
|
1198
|
-
}
|
|
1199
|
-
return bufferToStream(yield img.toBuffer());
|
|
1200
|
-
}
|
|
1201
|
-
catch (e) {
|
|
1202
|
-
console.log("Asset image conversion error", e);
|
|
1203
|
-
return bufferToStream(buffer);
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
1234
|
get filename() {
|
|
1208
1235
|
return this.data.filename;
|
|
1209
1236
|
}
|
|
@@ -1238,12 +1265,12 @@ class Asset extends BaseEntity {
|
|
|
1238
1265
|
}
|
|
1239
1266
|
getImage(params = null) {
|
|
1240
1267
|
return __awaiter$s(this, void 0, void 0, function* () {
|
|
1241
|
-
return
|
|
1268
|
+
return toImage(this.stream, params, this.metadata);
|
|
1242
1269
|
});
|
|
1243
1270
|
}
|
|
1244
1271
|
downloadImage(params, metadata) {
|
|
1245
1272
|
return __awaiter$s(this, void 0, void 0, function* () {
|
|
1246
|
-
return
|
|
1273
|
+
return toImage(yield this.download(metadata), params, this.metadata);
|
|
1247
1274
|
});
|
|
1248
1275
|
}
|
|
1249
1276
|
}
|
|
@@ -1285,7 +1312,7 @@ class TempAsset {
|
|
|
1285
1312
|
}
|
|
1286
1313
|
downloadImage(params, metadata) {
|
|
1287
1314
|
Object.assign(this.metadata, metadata || {});
|
|
1288
|
-
return
|
|
1315
|
+
return toImage(this.stream, params, this.metadata);
|
|
1289
1316
|
}
|
|
1290
1317
|
getImage(params) {
|
|
1291
1318
|
return this.downloadImage(params);
|
|
@@ -1422,6 +1449,12 @@ let Assets = class Assets {
|
|
|
1422
1449
|
return result;
|
|
1423
1450
|
});
|
|
1424
1451
|
}
|
|
1452
|
+
deleteMany(where) {
|
|
1453
|
+
return __awaiter$q(this, void 0, void 0, function* () {
|
|
1454
|
+
const assets = yield this.findMany(where);
|
|
1455
|
+
return Promise.all(assets.map(a => a.unlink()));
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1425
1458
|
unlink(id) {
|
|
1426
1459
|
return __awaiter$q(this, void 0, void 0, function* () {
|
|
1427
1460
|
const asset = yield this.read(id);
|
|
@@ -3110,6 +3143,12 @@ let AssetsController = class AssetsController {
|
|
|
3110
3143
|
}
|
|
3111
3144
|
});
|
|
3112
3145
|
}
|
|
3146
|
+
getFile(id, lazy, res) {
|
|
3147
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3148
|
+
const asset = yield this.getAsset("Asset", id, lazy, res);
|
|
3149
|
+
return asset.download();
|
|
3150
|
+
});
|
|
3151
|
+
}
|
|
3113
3152
|
getImageRotation(id, params, res, rotation = 0) {
|
|
3114
3153
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3115
3154
|
const asset = yield this.getAsset("Image", id, params.lazy, res);
|
|
@@ -3124,29 +3163,48 @@ let AssetsController = class AssetsController {
|
|
|
3124
3163
|
return this.getImageRotation(id, params, res);
|
|
3125
3164
|
});
|
|
3126
3165
|
}
|
|
3127
|
-
|
|
3166
|
+
getFileByName(name, res) {
|
|
3128
3167
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3129
|
-
const asset = yield this.
|
|
3168
|
+
const asset = yield this.getAssetByName("Asset", name, res);
|
|
3130
3169
|
return asset.download();
|
|
3131
3170
|
});
|
|
3132
3171
|
}
|
|
3133
|
-
|
|
3172
|
+
getImageByName(name, params, res) {
|
|
3173
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3174
|
+
const asset = yield this.getAssetByName("Image", name, res);
|
|
3175
|
+
return asset.downloadImage(params);
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
3178
|
+
setAssetHeaders(type, asset, res) {
|
|
3134
3179
|
var _a, _b;
|
|
3180
|
+
if ((_a = asset.metadata) === null || _a === void 0 ? void 0 : _a.classified) {
|
|
3181
|
+
throw new HttpError(403, `${type} is classified, and can be only downloaded from a custom url.`);
|
|
3182
|
+
}
|
|
3183
|
+
const ext = (_b = asset.metadata) === null || _b === void 0 ? void 0 : _b.extension;
|
|
3184
|
+
if (ext) {
|
|
3185
|
+
res.header("content-disposition", `inline; filename=${asset.filename}.${ext}`);
|
|
3186
|
+
}
|
|
3187
|
+
if (asset.contentType) {
|
|
3188
|
+
res.header("content-type", asset.contentType);
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
getAsset(type, id, lazy, res) {
|
|
3135
3192
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3136
3193
|
const asset = yield this.assetResolver.resolve(id, lazy);
|
|
3137
3194
|
if (!asset) {
|
|
3138
3195
|
throw new HttpError(404, `${type} with id: '${id}' not found.`);
|
|
3139
3196
|
}
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
}
|
|
3147
|
-
if (asset
|
|
3148
|
-
|
|
3197
|
+
this.setAssetHeaders(type, asset, res);
|
|
3198
|
+
return asset;
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
getAssetByName(type, filename, res) {
|
|
3202
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3203
|
+
const asset = yield this.assets.find({ filename });
|
|
3204
|
+
if (!asset) {
|
|
3205
|
+
throw new HttpError(404, `${type} with filename: '${filename}' not found.`);
|
|
3149
3206
|
}
|
|
3207
|
+
this.setAssetHeaders(type, asset, res);
|
|
3150
3208
|
return asset;
|
|
3151
3209
|
});
|
|
3152
3210
|
}
|
|
@@ -3167,6 +3225,13 @@ __decorate$a([
|
|
|
3167
3225
|
__metadata$7("design:paramtypes", [Object]),
|
|
3168
3226
|
__metadata$7("design:returntype", Promise)
|
|
3169
3227
|
], AssetsController.prototype, "uploadUrl", null);
|
|
3228
|
+
__decorate$a([
|
|
3229
|
+
Get("/:id"),
|
|
3230
|
+
__param$5(0, Param("id")), __param$5(1, QueryParam("lazy")), __param$5(2, Res()),
|
|
3231
|
+
__metadata$7("design:type", Function),
|
|
3232
|
+
__metadata$7("design:paramtypes", [String, Boolean, Object]),
|
|
3233
|
+
__metadata$7("design:returntype", Promise)
|
|
3234
|
+
], AssetsController.prototype, "getFile", null);
|
|
3170
3235
|
__decorate$a([
|
|
3171
3236
|
Get("/image/:id/:rotation"),
|
|
3172
3237
|
__param$5(0, Param("id")), __param$5(1, QueryParams()), __param$5(2, Res()), __param$5(3, Param("rotation")),
|
|
@@ -3182,12 +3247,19 @@ __decorate$a([
|
|
|
3182
3247
|
__metadata$7("design:returntype", Promise)
|
|
3183
3248
|
], AssetsController.prototype, "getImage", null);
|
|
3184
3249
|
__decorate$a([
|
|
3185
|
-
Get("/:
|
|
3186
|
-
__param$5(0, Param("
|
|
3250
|
+
Get("/by-name/:name"),
|
|
3251
|
+
__param$5(0, Param("name")), __param$5(1, Res()),
|
|
3187
3252
|
__metadata$7("design:type", Function),
|
|
3188
|
-
__metadata$7("design:paramtypes", [String,
|
|
3253
|
+
__metadata$7("design:paramtypes", [String, Object]),
|
|
3189
3254
|
__metadata$7("design:returntype", Promise)
|
|
3190
|
-
], AssetsController.prototype, "
|
|
3255
|
+
], AssetsController.prototype, "getFileByName", null);
|
|
3256
|
+
__decorate$a([
|
|
3257
|
+
Get("/by-name/image/:name"),
|
|
3258
|
+
__param$5(0, Param("name")), __param$5(1, QueryParams()), __param$5(2, Res()),
|
|
3259
|
+
__metadata$7("design:type", Function),
|
|
3260
|
+
__metadata$7("design:paramtypes", [String, Object, Object]),
|
|
3261
|
+
__metadata$7("design:returntype", Promise)
|
|
3262
|
+
], AssetsController.prototype, "getImageByName", null);
|
|
3191
3263
|
AssetsController = __decorate$a([
|
|
3192
3264
|
injectable(),
|
|
3193
3265
|
Controller("/assets"),
|
|
@@ -4139,5 +4211,5 @@ function setupBackend(config, providers, parent) {
|
|
|
4139
4211
|
* Generated bundle index. Do not edit.
|
|
4140
4212
|
*/
|
|
4141
4213
|
|
|
4142
|
-
export { AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst,
|
|
4214
|
+
export { AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, promiseTimeout, proxyFunction, proxyFunctions, rand, random, readAndDeleteFile, readFile, regroup, replaceSpecialChars, runCommand, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, valueToPromise, writeFile };
|
|
4143
4215
|
//# sourceMappingURL=stemy-backend.js.map
|