@optimiser/common 1.0.428 → 1.0.430

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.
@@ -33,6 +33,12 @@ export default class AwsServices {
33
33
  GeneratePreSignedUrlNotAccelerated(params: {
34
34
  [key: string]: any;
35
35
  }): Promise<string | Error>;
36
+ GeneratePreSignedUrlForVideoUpload(params: {
37
+ [key: string]: any;
38
+ }): Promise<string | Error>;
39
+ GeneratePreSignedUrlForPlayback(params: {
40
+ [key: string]: any;
41
+ }): Promise<string | Error>;
36
42
  GeneratePreSignedUrl(Bucket: string, Path: string, Acl: string, Region: string, ContentType: string, FileName: string, ContryRegionName: string): Promise<string | Error>;
37
43
  ImageUpload(BucketName: string, Region: string, FilePath: string, base64String: string, ContentType: string, FileName: string, FileType: string, UploadType: string, Acltype: string, Socketid: string, req: Express.Request): Promise<S3.ManagedUpload.SendData | Error>;
38
44
  uploadFromStream(params: S3.Types.PutObjectRequest): Promise<S3.ManagedUpload.SendData>;
@@ -293,6 +293,59 @@ var AwsServices = /** @class */ (function () {
293
293
  });
294
294
  });
295
295
  };
296
+ AwsServices.prototype.GeneratePreSignedUrlForVideoUpload = function (params) {
297
+ var region = params.region, bucket = params.bucket, path = params.path, _a = params.expires, expires = _a === void 0 ? 60 : _a, _b = params.acl, acl = _b === void 0 ? 'private' : _b, _c = params.contentType, contentType = _c === void 0 ? 'application/octet-stream' : _c, _d = params.accessKeyId, accessKeyId = _d === void 0 ? this.accessKeyId : _d, _e = params.secretAccessKey, secretAccessKey = _e === void 0 ? this.secretAccessKey : _e;
298
+ if (params.accessType != '' && params.accessType != undefined && params.accessType != null) {
299
+ acl = params.accessType;
300
+ }
301
+ var S3 = new aws_sdk_1.default.S3({
302
+ accessKeyId: accessKeyId,
303
+ secretAccessKey: secretAccessKey,
304
+ region: region,
305
+ endpoint: new aws_sdk_1.default.Endpoint("optimiser-".concat(params.bucketSuffix, ".s3-accelerate.amazonaws.com")),
306
+ useAccelerateEndpoint: true,
307
+ s3ForcePathStyle: true,
308
+ signatureVersion: 'v4'
309
+ });
310
+ var Params = { Bucket: bucket, Key: path, Expires: expires, ACL: acl, ContentType: contentType };
311
+ return new Promise(function (resolve, reject) {
312
+ S3.getSignedUrl('putObject', Params, function (err, url) {
313
+ if (err) {
314
+ resolve(err);
315
+ }
316
+ else {
317
+ resolve(url);
318
+ }
319
+ });
320
+ });
321
+ };
322
+ AwsServices.prototype.GeneratePreSignedUrlForPlayback = function (params) {
323
+ var region = params.region, bucket = params.bucket, path = params.path, _a = params.expires, expires = _a === void 0 ? 3600 : _a, _b = params.accessKeyId, accessKeyId = _b === void 0 ? this.accessKeyId : _b, _c = params.secretAccessKey, secretAccessKey = _c === void 0 ? this.secretAccessKey : _c;
324
+ var S3 = new aws_sdk_1.default.S3({
325
+ accessKeyId: accessKeyId,
326
+ secretAccessKey: secretAccessKey,
327
+ region: region,
328
+ endpoint: new aws_sdk_1.default.Endpoint("optimiser-".concat(params.bucketSuffix, ".s3-accelerate.amazonaws.com")),
329
+ useAccelerateEndpoint: true,
330
+ s3ForcePathStyle: true,
331
+ signatureVersion: 'v4'
332
+ });
333
+ var Params = {
334
+ Bucket: bucket,
335
+ Key: path,
336
+ Expires: expires
337
+ };
338
+ return new Promise(function (resolve, reject) {
339
+ S3.getSignedUrl('getObject', Params, function (err, url) {
340
+ if (err) {
341
+ reject(err);
342
+ }
343
+ else {
344
+ resolve(url);
345
+ }
346
+ });
347
+ });
348
+ };
296
349
  AwsServices.prototype.GeneratePreSignedUrl = function (Bucket, Path, Acl, Region, ContentType, FileName, ContryRegionName) {
297
350
  var _this = this;
298
351
  return new Promise(function (resolve, reject) {
@@ -106,6 +106,7 @@ var sanitize_html_1 = __importDefault(require("sanitize-html"));
106
106
  var sanitize = require('mongo-sanitize');
107
107
  var phoneUtil = require("google-libphonenumber").PhoneNumberUtil.getInstance();
108
108
  var qrcode = require('qrcode');
109
+ var convert = require('html-to-text').convert;
109
110
  var _settingData = {};
110
111
  function GetObjectByKeyValueFromList(list, key, val) {
111
112
  if (list && list.length > 0) {
@@ -1580,7 +1581,7 @@ exports.GetObjectByString = GetObjectByString;
1580
1581
  function BuildLookupDataField(fieldSchema, updateObj, db) {
1581
1582
  var _a, _b;
1582
1583
  return __awaiter(this, void 0, void 0, function () {
1583
- var fldValue, fldName_2, alias, searchAlias, fldLookupData, aggregateArry, project_1, i, obj, lookupObj, i, i, data, _c, result, _loop_10, j, i, unionDetail, unionPipeline, unionObj, result, i, lookupRecord, j, result, j, result, i, lookupRecord, j, result, i, lookupRecord, fetchFileData, video_Id, thumbnail_Id, error_2, fieldValueType, errMsg;
1584
+ var fldValue, fldName_2, alias, searchAlias, fldLookupData, aggregateArry, project_1, i, obj, lookupObj, i, i, data, _c, result, _loop_10, j, i, unionDetail, unionPipeline, unionObj, result, i, lookupRecord, j, result, j, result, i, lookupRecord, j, result, i, lookupRecord, fetchFileData, video_Id, thumbnail_Id, isManualThumbnail_1, promises, error_2, fieldValueType, errMsg;
1584
1585
  return __generator(this, function (_d) {
1585
1586
  switch (_d.label) {
1586
1587
  case 0:
@@ -1844,39 +1845,42 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1844
1845
  // }
1845
1846
  return [3 /*break*/, 21];
1846
1847
  case 19:
1847
- {
1848
- // // Remove previous lookup data
1848
+ { // Remove previous lookup data
1849
1849
  delete updateObj[fldName_2]['VideoFile_LookupData'];
1850
1850
  delete updateObj[fldName_2]['ThumbnailImage_LookupData'];
1851
1851
  fetchFileData = function (fileId, includeDuration) {
1852
1852
  if (!fileId)
1853
1853
  return Promise.resolve([]);
1854
- var projectQuery = __assign(__assign({}, project_1), { FileName: 1 }); // Keep existing values
1854
+ var parsedId = mongodb_1.ObjectId.isValid(fileId) ? new mongodb_1.ObjectId(fileId) : fileId;
1855
+ var projectQuery = __assign(__assign({}, project_1), { FileName: 1 });
1855
1856
  if (includeDuration) {
1856
1857
  projectQuery['Duration'] = 1;
1858
+ projectQuery['Thumbnail'] = 1;
1857
1859
  }
1858
1860
  return db.collection('Drive').aggregate([
1859
- { $match: { _id: fileId } },
1861
+ { $match: { _id: parsedId } },
1860
1862
  { $project: projectQuery }
1861
1863
  ]).toArray();
1862
1864
  };
1863
1865
  video_Id = fldValue["VideoFile"];
1864
1866
  thumbnail_Id = fldValue["ThumbnailImage"];
1865
- Promise.all([
1867
+ isManualThumbnail_1 = updateObj[fldName_2]['Thumbnail'] === 'manual';
1868
+ promises = [
1866
1869
  fetchFileData(video_Id !== null && video_Id !== void 0 ? video_Id : "", true),
1867
- fetchFileData(thumbnail_Id !== null && thumbnail_Id !== void 0 ? thumbnail_Id : "", false)
1868
- ])
1870
+ isManualThumbnail_1 ? fetchFileData(thumbnail_Id !== null && thumbnail_Id !== void 0 ? thumbnail_Id : "", false) : Promise.resolve([])
1871
+ ];
1872
+ Promise.all(promises)
1869
1873
  .then(function (_a) {
1870
1874
  var videoData = _a[0], thumbnailData = _a[1];
1871
1875
  if (videoData.length > 0) {
1872
1876
  updateObj[fldName_2]['VideoFile_LookupData'] = videoData[0];
1873
1877
  }
1874
- if (thumbnailData.length > 0) {
1878
+ if (thumbnailData.length > 0 && isManualThumbnail_1) {
1875
1879
  updateObj[fldName_2]['ThumbnailImage_LookupData'] = thumbnailData[0];
1876
1880
  }
1877
1881
  })
1878
- .catch(function (error) {
1879
- console.error("Error in Video Upload Process:", error);
1882
+ .catch(function (err) {
1883
+ console.error("Error fetching lookup data:", err);
1880
1884
  });
1881
1885
  }
1882
1886
  return [3 /*break*/, 21];
@@ -4906,7 +4910,7 @@ function ValidateUserInput(options) {
4906
4910
  }
4907
4911
  }
4908
4912
  _loop_20 = function (pageField) {
4909
- var fieldName, fieldData, field, parentData, oldValue, newValue, isSame, searchQuery, result, fld, _k, minValue, maxValue, filter, searchObj, dbConnection, result, searchObj, totalRecord, _l, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _m, fieldData_1, obj, searchObj, totalRecord, searchObj, result, searchVideoObj, searchThumbnailObj, _o, videoResult, thumbnailResult, _p, fieldData_2, obj;
4913
+ var fieldName, fieldData, field, parentData, oldValue, newValue, isSame, searchQuery, result, fld, _k, minValue, maxValue, filter, searchObj, dbConnection, result, searchObj, totalRecord, _l, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _m, fieldData_1, obj, searchObj, totalRecord, searchObj, result, searchVideoObj, videoPromise, thumbnailPromise, searchThumbnailObj, _o, videoResult, thumbnailResult, text, _p, fieldData_2, obj;
4910
4914
  return __generator(this, function (_q) {
4911
4915
  switch (_q.label) {
4912
4916
  case 0:
@@ -5048,10 +5052,10 @@ function ValidateUserInput(options) {
5048
5052
  msg = 'Invalid value for ' + field.DisplayName + '!';
5049
5053
  }
5050
5054
  else if (minValue !== undefined && minValue !== null && fieldData < minValue) {
5051
- msg = field.DisplayName + ' value must be greater then or equal to ' + minValue;
5055
+ msg = field.DisplayName + ' value must be greater than or equal to ' + minValue;
5052
5056
  }
5053
5057
  else if (maxValue !== undefined && maxValue !== null && maxValue < fieldData) {
5054
- msg = field.DisplayName + ' value must be smaller then or equal to ' + maxValue;
5058
+ msg = field.DisplayName + ' value must be smaller than or equal to ' + maxValue;
5055
5059
  }
5056
5060
  }
5057
5061
  return [3 /*break*/, 59];
@@ -5305,29 +5309,40 @@ function ValidateUserInput(options) {
5305
5309
  case 50: return [3 /*break*/, 59];
5306
5310
  case 51:
5307
5311
  searchVideoObj = { _id: fieldData['VideoFile'] };
5308
- searchThumbnailObj = { _id: fieldData['ThumbnailImage'] };
5309
5312
  if (action === 'add') {
5310
5313
  searchVideoObj.IsActive = true;
5311
- searchThumbnailObj.IsActive = true;
5314
+ }
5315
+ videoPromise = db.collection("Drive").findOne(searchVideoObj);
5316
+ thumbnailPromise = Promise.resolve(true);
5317
+ if (fieldData['Thumbnail'] === 'manual') {
5318
+ searchThumbnailObj = { _id: fieldData['ThumbnailImage'] };
5319
+ if (action === 'add') {
5320
+ searchThumbnailObj.IsActive = true;
5321
+ }
5322
+ thumbnailPromise = db.collection("Drive").findOne(searchThumbnailObj);
5312
5323
  }
5313
5324
  return [4 /*yield*/, Promise.all([
5314
- db.collection("Drive").findOne(searchVideoObj),
5315
- db.collection("Drive").findOne(searchThumbnailObj)
5325
+ videoPromise,
5326
+ thumbnailPromise
5316
5327
  ])];
5317
5328
  case 52:
5318
5329
  _o = _q.sent(), videoResult = _o[0], thumbnailResult = _o[1];
5319
5330
  if (!videoResult) {
5320
5331
  msg = field.DisplayName + ' (VideoFile) does not exist!';
5321
5332
  }
5322
- if (!thumbnailResult) {
5333
+ if (fieldData['Thumbnail'] === 'manual' && !thumbnailResult) {
5323
5334
  msg += (msg ? ' ' : '') + field.DisplayName + ' (ThumbnailImage) does not exist!';
5324
5335
  }
5325
5336
  return [3 /*break*/, 59];
5326
5337
  case 53:
5327
5338
  {
5328
- // Maxlength check;
5339
+ // Maxlength check;
5340
+ if (field.UIDataType === 'texteditor') {
5341
+ text = convert(fieldData, { wordwrap: false });
5342
+ fieldData = text.replace(/\n/g, ' ').trim();
5343
+ }
5329
5344
  if (field.MaxLength !== undefined && field.MaxLength !== null && fieldData.length > field.MaxLength) {
5330
- msg = field.DisplayName + ' can not be greater then ' + field.MaxLength + ' characters!';
5345
+ msg = field.DisplayName + ' can not be greater than ' + field.MaxLength + ' characters!';
5331
5346
  }
5332
5347
  if (!IsStringValue(fieldData)) {
5333
5348
  msg = 'Invalid value for ' + field.DisplayName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.428",
3
+ "version": "1.0.430",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -29,6 +29,7 @@
29
29
  "firebase-admin": "^12.0.0",
30
30
  "geoip-lite": "^1.4.2",
31
31
  "google-libphonenumber": "^3.2.30",
32
+ "html-to-text": "^8.2.0",
32
33
  "ioredis": "^4.17.3",
33
34
  "libphonenumber-js": "^1.9.51",
34
35
  "moment": "^2.25.3",