drapcode-utility 1.5.3 → 1.5.5

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.
@@ -12,7 +12,7 @@ interface S3Config {
12
12
  append: boolean;
13
13
  }
14
14
  export declare const createS3Client: (awsConfig: AWSConfig) => S3Client | null;
15
- export declare const fileUploadToS3: (files: any, s3Client: S3Client, s3Config: S3Config, publicS3Client: S3Client, publicS3Config: S3Config, encryption: Encryption, options?: {}) => Promise<{
15
+ export declare const fileUploadToS3: (files: any, s3Client: S3Client, s3Config: S3Config, publicS3Client: S3Client, publicS3Config: S3Config, isGenerateIcons: boolean, encryption: Encryption, options?: {}) => Promise<{
16
16
  status: string;
17
17
  data: string;
18
18
  message: string;
@@ -74,7 +74,7 @@ var createS3Client = function (awsConfig) {
74
74
  return s3client;
75
75
  };
76
76
  exports.createS3Client = createS3Client;
77
- var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, publicS3Config, encryption, options) {
77
+ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options) {
78
78
  if (options === void 0) { options = {}; }
79
79
  return __awaiter(void 0, void 0, void 0, function () {
80
80
  var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _i, index, file, fileSlug, fileObj, fileSlug, fileObj;
@@ -120,7 +120,7 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
120
120
  if (s3Config.append) {
121
121
  s3Config.key = s3Key + "/" + uuid_1.v4() + "/" + fileSlug;
122
122
  }
123
- return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, publicS3Client, publicS3Config, encryption, options, encryption ? true : false)];
123
+ return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encryption ? true : false)];
124
124
  case 4:
125
125
  fileObj = _c.sent();
126
126
  if (fileObj) {
@@ -141,7 +141,7 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
141
141
  if (s3Config.append) {
142
142
  s3Config.key = s3Config.key + "/" + uuid_1.v4() + "/" + fileSlug;
143
143
  }
144
- return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, publicS3Client, publicS3Config, encryption, options, encryption ? true : false)];
144
+ return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encryption ? true : false)];
145
145
  case 8:
146
146
  fileObj = _c.sent();
147
147
  return [2 /*return*/, fileObj];
@@ -150,7 +150,7 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
150
150
  });
151
151
  };
152
152
  exports.fileUploadToS3 = fileUploadToS3;
153
- var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client, publicS3Config, encryption, options, encrypt) {
153
+ var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encrypt) {
154
154
  if (options === void 0) { options = {}; }
155
155
  if (encrypt === void 0) { encrypt = false; }
156
156
  return __awaiter(void 0, void 0, void 0, function () {
@@ -177,13 +177,15 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client,
177
177
  return [4 /*yield*/, parallelUploads3.done()];
178
178
  case 4:
179
179
  data = _b.sent();
180
- return [4 /*yield*/, handleIconUpload(file.path, contentType, publicS3Client, publicS3Config, key, options)];
180
+ return [4 /*yield*/, handleIconUpload(file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options)];
181
181
  case 5:
182
182
  _a = _b.sent(), smallIcon = _a.smallIcon, mediumIcon = _a.mediumIcon, largeIcon = _a.largeIcon;
183
- if (encryptedFilePath) {
184
- fs_1.default.unlinkSync(encryptedFilePath);
183
+ if (data) {
184
+ if (encryptedFilePath) {
185
+ fs_1.default.unlinkSync(encryptedFilePath);
186
+ }
187
+ fs_1.default.unlinkSync(file.path);
185
188
  }
186
- fs_1.default.unlinkSync(file.path);
187
189
  originalname = file.originalname, mimetype = file.mimetype, size = file.size;
188
190
  return [2 /*return*/, {
189
191
  originalname: originalname,
@@ -204,20 +206,23 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client,
204
206
  });
205
207
  });
206
208
  };
207
- var handleIconUpload = function (filePath, contentType, publicS3Client, publicS3Config, key, options) {
209
+ var handleIconUpload = function (file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options) {
208
210
  if (options === void 0) { options = {}; }
209
211
  return __awaiter(void 0, void 0, void 0, function () {
210
- var iconSizes, iconLabels, iconFiles, bucket_1, acl_1, iconUploads, _a, smallKey, mediumKey, largeKey, iconError_1;
212
+ var filePath, fileSize, iconSizes, iconLabels, iconFiles, bucket_1, acl_1, iconUploads, _a, smallKey, mediumKey, largeKey, iconError_1;
211
213
  return __generator(this, function (_b) {
212
214
  switch (_b.label) {
213
215
  case 0:
216
+ filePath = file.path, fileSize = file.size;
214
217
  iconSizes = [200, 300, 500];
215
218
  iconLabels = ["small", "medium", "large"];
216
219
  _b.label = 1;
217
220
  case 1:
218
221
  _b.trys.push([1, 6, , 7]);
219
- if (!["image/png", "image/jpeg", "image/gif", "application/pdf"].includes(contentType)) return [3 /*break*/, 4];
220
- return [4 /*yield*/, generateDynamicIcons(filePath, iconSizes)];
222
+ if (!(isGenerateIcons &&
223
+ fileSize < 157286400 && //150mb
224
+ ["image/png", "image/jpeg", "image/gif", "application/pdf"].includes(contentType))) return [3 /*break*/, 4];
225
+ return [4 /*yield*/, generateDynamicIcons(filePath, iconSizes, contentType)];
221
226
  case 2:
222
227
  iconFiles = _b.sent();
223
228
  bucket_1 = publicS3Config.bucket, acl_1 = publicS3Config.acl;
@@ -266,13 +271,15 @@ var handleIconUpload = function (filePath, contentType, publicS3Client, publicS3
266
271
  });
267
272
  });
268
273
  };
269
- var generateDynamicIcons = function (filePath, sizes) {
274
+ var generateDynamicIcons = function (filePath, sizes, contentType) {
270
275
  return Promise.all(sizes.map(function (size) {
271
276
  var outputFilePath = filePath + "_" + size + ".png";
272
277
  return new Promise(function (resolve, reject) {
273
- gm_1.default(filePath)
274
- .resize(size, size)
275
- .write(outputFilePath, function (err) {
278
+ var gmInstance = gm_1.default(filePath);
279
+ if (contentType === "application/pdf") {
280
+ gmInstance = gmInstance.selectFrame(0);
281
+ }
282
+ gmInstance.resize(size, size).write(outputFilePath, function (err) {
276
283
  if (err) {
277
284
  reject(err);
278
285
  }
@@ -20,7 +20,7 @@ export declare const arraysEqual: (array1: any, array2: any) => boolean;
20
20
  export declare const convertItemToArray: (itemValue: any) => any[];
21
21
  export declare const validateAlphanumericString: (str: string) => false | "String should contain only numbers and letters";
22
22
  export declare const formatCustomCSSClasses: (customClasses: any) => string;
23
- export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, sessionValue: any, envConstants: any, sessionFormValue: any) => string;
23
+ export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, sessionValue: any, envConstants: any, sessionFormValue: any, localStorageValue: any, cookiesValue: any) => string;
24
24
  export declare const parseJsonString: (str: string) => any;
25
25
  export declare const parseValueFromData: (data: any, fieldName: string) => any;
26
26
  export declare const unflattenObject: (obj: any) => {};
@@ -287,7 +287,7 @@ var formatCustomCSSClasses = function (customClasses) {
287
287
  return projectCustomCSSClassesData;
288
288
  };
289
289
  exports.formatCustomCSSClasses = formatCustomCSSClasses;
290
- var replaceDataValueIntoExpression = function (expression, data, user, tenant, sessionValue, envConstants, sessionFormValue) {
290
+ var replaceDataValueIntoExpression = function (expression, data, user, tenant, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue) {
291
291
  var _a;
292
292
  var contentList = (_a = expression
293
293
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
@@ -320,6 +320,27 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
320
320
  dataOfItem = lodash_1.default.get(sessionFormValue, prop);
321
321
  }
322
322
  }
323
+ else if (prop.includes("SESSION_STORAGE")) {
324
+ prop = prop.replace("SESSION_STORAGE.", "");
325
+ if (Object.keys(sessionValue).length > 0) {
326
+ //Session will contain multi level data
327
+ dataOfItem = lodash_1.default.get(sessionValue, prop);
328
+ }
329
+ }
330
+ else if (prop.includes("LOCAL_STORAGE")) {
331
+ prop = prop.replace("LOCAL_STORAGE.", "");
332
+ if (Object.keys(localStorageValue).length > 0) {
333
+ //Session will contain multi level data
334
+ dataOfItem = lodash_1.default.get(localStorageValue, prop);
335
+ }
336
+ }
337
+ else if (prop.includes("COOKIES")) {
338
+ prop = prop.replace("COOKIES.", "");
339
+ if (Object.keys(cookiesValue).length > 0) {
340
+ //Session will contain multi level data
341
+ dataOfItem = lodash_1.default.get(cookiesValue, prop);
342
+ }
343
+ }
323
344
  else if (prop.includes("environment_variable")) {
324
345
  prop = prop.replace("environment_variable.", "");
325
346
  if (Object.keys(envConstants).length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -34,8 +34,8 @@
34
34
  "@types/gm": "^1.25.4",
35
35
  "@types/voca": "^1.4.2",
36
36
  "axios": "^1.1.2",
37
- "drapcode-constant": "^1.4.5",
38
- "drapcode-logger": "^1.1.6",
37
+ "drapcode-constant": "^1.4.7",
38
+ "drapcode-logger": "^1.1.7",
39
39
  "drapcode-redis": "^1.0.5",
40
40
  "express": "^4.17.1",
41
41
  "gm": "^1.25.0",