@optimiser/common 1.0.365 → 1.0.367
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/dist/aws/awsservices.d.ts +39 -39
- package/dist/aws/awsservices.js +398 -398
- package/dist/constants.d.ts +35 -35
- package/dist/constants.js +36 -36
- package/dist/enums/databasetype.enum.d.ts +7 -7
- package/dist/enums/databasetype.enum.js +11 -11
- package/dist/enums/log.enum.d.ts +22 -22
- package/dist/enums/log.enum.js +26 -26
- package/dist/index.d.ts +25 -25
- package/dist/index.js +69 -61
- package/dist/lib/activity.d.ts +1 -1
- package/dist/lib/activity.js +44 -44
- package/dist/lib/calculatedbsize.d.ts +15 -15
- package/dist/lib/calculatedbsize.js +75 -75
- package/dist/lib/connection.d.ts +116 -116
- package/dist/lib/connection.js +595 -595
- package/dist/lib/convertfilesize.d.ts +2 -2
- package/dist/lib/convertfilesize.js +15 -15
- package/dist/lib/countrycode.d.ts +2 -2
- package/dist/lib/countrycode.js +255 -255
- package/dist/lib/event.d.ts +26 -26
- package/dist/lib/event.js +252 -248
- package/dist/lib/helper.d.ts +94 -93
- package/dist/lib/helper.js +1016 -1009
- package/dist/lib/memoryserverclient.d.ts +40 -40
- package/dist/lib/memoryserverclient.js +256 -252
- package/dist/lib/operautilitycommon.d.ts +65 -65
- package/dist/lib/operautilitycommon.js +620 -620
- package/dist/lib/redis.d.ts +21 -21
- package/dist/lib/redis.js +46 -46
- package/dist/lib/socketidfromredis.d.ts +3 -3
- package/dist/lib/socketidfromredis.js +5 -5
- package/dist/lib/taskutils.d.ts +40 -40
- package/dist/lib/taskutils.js +656 -656
- package/dist/lib/utility.d.ts +300 -298
- package/dist/lib/utility.js +5626 -5621
- package/dist/lib/validateRequest.d.ts +3 -3
- package/dist/lib/validateRequest.js +13 -13
- package/dist/logs/auditlog.d.ts +25 -25
- package/dist/logs/auditlog.js +1033 -1029
- package/dist/logs/checklogtable.d.ts +3 -3
- package/dist/logs/checklogtable.js +67 -67
- package/dist/logs/log.table.d.ts +7 -7
- package/dist/logs/log.table.js +127 -127
- package/dist/modals/connection.modal.d.ts +32 -32
- package/dist/modals/connection.modal.js +2 -2
- package/dist/modals/globalNotification.modal.d.ts +8 -8
- package/dist/modals/globalNotification.modal.js +2 -2
- package/dist/modals/log.modal.d.ts +64 -64
- package/dist/modals/log.modal.js +2 -2
- package/dist/modals/mail.modal.d.ts +6 -6
- package/dist/modals/mail.modal.js +2 -2
- package/dist/modals/notificationData.modal.d.ts +29 -29
- package/dist/modals/notificationData.modal.js +2 -2
- package/dist/modals/redisconfig.modal.d.ts +6 -6
- package/dist/modals/redisconfig.modal.js +2 -2
- package/dist/modals/sqsconfig.modal.d.ts +8 -8
- package/dist/modals/sqsconfig.modal.js +2 -2
- package/dist/modals/utility.modal.d.ts +17 -17
- package/dist/modals/utility.modal.js +2 -2
- package/dist/utility/crypto.d.ts +4 -4
- package/dist/utility/crypto.js +43 -43
- package/dist/utility/errorHandler.d.ts +30 -30
- package/dist/utility/errorHandler.js +24 -24
- package/dist/utility/errorHandlerForServices.d.ts +22 -22
- package/dist/utility/errorHandlerForServices.js +19 -19
- package/dist/utility/mail.d.ts +21 -21
- package/dist/utility/mail.js +91 -87
- package/package.json +3 -3
package/dist/aws/awsservices.js
CHANGED
|
@@ -1,398 +1,398 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
43
|
-
var axios_1 = __importDefault(require("axios"));
|
|
44
|
-
var request_1 = __importDefault(require("request"));
|
|
45
|
-
var fs_1 = __importDefault(require("fs"));
|
|
46
|
-
var unzipper_1 = __importDefault(require("unzipper"));
|
|
47
|
-
var AwsServices = /** @class */ (function () {
|
|
48
|
-
/**
|
|
49
|
-
* @param accesskeyId access key id
|
|
50
|
-
* @param secretaccesskey secret access key
|
|
51
|
-
* @param cloudfrontPublicKey region
|
|
52
|
-
* @param cloudfrontPrivateKey
|
|
53
|
-
* @description credentials for aws
|
|
54
|
-
*/
|
|
55
|
-
function AwsServices(accesskeyId, secretaccesskey, cloudfrontPublicKey, cloudfrontPrivateKey) {
|
|
56
|
-
aws_sdk_1.default.config.update({ accessKeyId: accesskeyId, secretAccessKey: secretaccesskey });
|
|
57
|
-
this.s3 = new aws_sdk_1.default.S3();
|
|
58
|
-
this.cfSigner = new aws_sdk_1.default.CloudFront.Signer(cloudfrontPublicKey, cloudfrontPrivateKey);
|
|
59
|
-
this.accessKeyId = accesskeyId;
|
|
60
|
-
this.secretAccessKey = secretaccesskey;
|
|
61
|
-
}
|
|
62
|
-
AwsServices.prototype.CreateNewBucket = function (BucketName, Region) {
|
|
63
|
-
var _this = this;
|
|
64
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
67
|
-
this.s3.createBucket({ 'Bucket': BucketName, 'CreateBucketConfiguration': { 'LocationConstraint': Region } }, function (err, data) {
|
|
68
|
-
if (err) {
|
|
69
|
-
reject(err);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
resolve(data);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return [2 /*return*/];
|
|
76
|
-
});
|
|
77
|
-
}); });
|
|
78
|
-
};
|
|
79
|
-
AwsServices.prototype.CheckIFBucketExist = function (BucketName, Region) {
|
|
80
|
-
var _this = this;
|
|
81
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
-
return __generator(this, function (_a) {
|
|
83
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
84
|
-
this.s3.headBucket({ Bucket: BucketName }, function (err, data) {
|
|
85
|
-
if (err) {
|
|
86
|
-
reject(err);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
resolve(data);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
});
|
|
94
|
-
}); });
|
|
95
|
-
};
|
|
96
|
-
AwsServices.prototype.DeleteFile = function (Bucket, Key, id, db) {
|
|
97
|
-
var _this = this;
|
|
98
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
this.s3.deleteObject({
|
|
101
|
-
Bucket: Bucket,
|
|
102
|
-
Key: Key
|
|
103
|
-
}, function (err, data) {
|
|
104
|
-
if (err) {
|
|
105
|
-
resolve(err);
|
|
106
|
-
}
|
|
107
|
-
else
|
|
108
|
-
resolve({
|
|
109
|
-
data: data,
|
|
110
|
-
id: id,
|
|
111
|
-
key: Key,
|
|
112
|
-
db: db
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
return [2 /*return*/];
|
|
116
|
-
});
|
|
117
|
-
}); });
|
|
118
|
-
};
|
|
119
|
-
AwsServices.prototype.GetFile = function (BucketName, Region, FilePath) {
|
|
120
|
-
var _this = this;
|
|
121
|
-
return new Promise(function (resolve, reject) {
|
|
122
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
123
|
-
_this.s3.getObject({
|
|
124
|
-
Bucket: BucketName, Key: FilePath,
|
|
125
|
-
}, function (err, data) {
|
|
126
|
-
if (err) {
|
|
127
|
-
reject(err);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
resolve(data);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
AwsServices.prototype.getDownloadUrl = function (CDN, FilePath, FileName, action, expiry) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
-
var exp, encodedurl, signingParams, signedUrl, err_1;
|
|
138
|
-
return __generator(this, function (_a) {
|
|
139
|
-
switch (_a.label) {
|
|
140
|
-
case 0:
|
|
141
|
-
_a.trys.push([0, 2, , 3]);
|
|
142
|
-
exp = expiry ? expiry : 20;
|
|
143
|
-
if (action == 'preview') {
|
|
144
|
-
encodedurl = CDN
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
FileName = FileName.replace(/[;]/g, "%3b").replace(/[,]/g, "%2c").replace(/[']/g, "%27"); //converting special character to UTF-8
|
|
148
|
-
encodedurl = CDN
|
|
149
|
-
}
|
|
150
|
-
signingParams = {
|
|
151
|
-
url: encodedurl,
|
|
152
|
-
expires: Math.floor((new Date()).getTime() / 1000) + (exp)
|
|
153
|
-
};
|
|
154
|
-
return [4 /*yield*/, this.cfSigner.getSignedUrl(signingParams)];
|
|
155
|
-
case 1:
|
|
156
|
-
signedUrl = _a.sent();
|
|
157
|
-
return [2 /*return*/, signedUrl];
|
|
158
|
-
case 2:
|
|
159
|
-
err_1 = _a.sent();
|
|
160
|
-
console.error("Error While Creating Signed Url:", err_1);
|
|
161
|
-
return [3 /*break*/, 3];
|
|
162
|
-
case 3: return [2 /*return*/];
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
AwsServices.prototype.GetFileStream = function (CDN, Key, FileName) {
|
|
168
|
-
var _this = this;
|
|
169
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
170
|
-
var url;
|
|
171
|
-
return __generator(this, function (_a) {
|
|
172
|
-
switch (_a.label) {
|
|
173
|
-
case 0: return [4 /*yield*/, this.getDownloadUrl(CDN, Key, FileName, 'download')];
|
|
174
|
-
case 1:
|
|
175
|
-
url = _a.sent();
|
|
176
|
-
resolve(request_1.default(url));
|
|
177
|
-
return [2 /*return*/];
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}); });
|
|
181
|
-
};
|
|
182
|
-
AwsServices.prototype.ChangesACL = function (BucketName, FilePath) {
|
|
183
|
-
var _this = this;
|
|
184
|
-
return new Promise(function (resolve, reject) {
|
|
185
|
-
var params = { ACL: 'private', Bucket: BucketName, Key: FilePath };
|
|
186
|
-
_this.s3.putObjectAcl(params, function (err, data) {
|
|
187
|
-
if (err)
|
|
188
|
-
resolve(err);
|
|
189
|
-
else
|
|
190
|
-
resolve(data);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
AwsServices.prototype.GetSignedUrl = function (BucketName, Region, FilePath) {
|
|
195
|
-
var cdn = "https://cdn.optimiser.com";
|
|
196
|
-
if (BucketName == "optimiser-mumbai") {
|
|
197
|
-
cdn = 'https://cdn-india.optimiser.com';
|
|
198
|
-
}
|
|
199
|
-
return cdn;
|
|
200
|
-
};
|
|
201
|
-
AwsServices.prototype.UploadZip = function (params, callback) {
|
|
202
|
-
return this.s3.upload(params, callback);
|
|
203
|
-
};
|
|
204
|
-
AwsServices.prototype.UploadFile = function (BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UniqueID, Socketid, req) {
|
|
205
|
-
var _this = this;
|
|
206
|
-
return new Promise(function (resolve, reject) {
|
|
207
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
208
|
-
var CacheControlHeader = 'max-age=604800';
|
|
209
|
-
_this.s3.upload({
|
|
210
|
-
Key: FilePath,
|
|
211
|
-
Bucket: BucketName,
|
|
212
|
-
Body: File,
|
|
213
|
-
ACL: Acltype,
|
|
214
|
-
ContentType: ContentType,
|
|
215
|
-
CacheControl: CacheControlHeader
|
|
216
|
-
}, function (err, data) {
|
|
217
|
-
if (err) {
|
|
218
|
-
reject(err);
|
|
219
|
-
}
|
|
220
|
-
}).send(function (err, data) {
|
|
221
|
-
if (err) {
|
|
222
|
-
reject(err);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
resolve(data);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
AwsServices.prototype.UploadToS3 = function (BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req) {
|
|
231
|
-
var _this = this;
|
|
232
|
-
return new Promise(function (resolve, reject) {
|
|
233
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
234
|
-
_this.CheckIFBucketExist(BucketName, Region).then(function () {
|
|
235
|
-
_this.UploadFile(BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req).then(function (sucess) {
|
|
236
|
-
resolve(sucess);
|
|
237
|
-
}).catch(function (err) {
|
|
238
|
-
reject(err);
|
|
239
|
-
});
|
|
240
|
-
}).catch(function () {
|
|
241
|
-
//Bucket does not exist in that particular region
|
|
242
|
-
_this.CreateNewBucket(BucketName, Region).then(function (BucketDetails) {
|
|
243
|
-
_this.UploadFile(BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req).then(function (sucess) {
|
|
244
|
-
resolve(sucess);
|
|
245
|
-
}).catch(function (err) {
|
|
246
|
-
reject(err);
|
|
247
|
-
});
|
|
248
|
-
}).catch(function (err) {
|
|
249
|
-
console.log("Error While Uploading Files:", err);
|
|
250
|
-
reject(err);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
AwsServices.prototype.GetFileFromS3 = function (BucketName, Region, FilePath) {
|
|
256
|
-
var _this = this;
|
|
257
|
-
return new Promise(function (resolve, reject) {
|
|
258
|
-
_this.GetFile(BucketName, Region, FilePath).then(function (filedetails) {
|
|
259
|
-
resolve(filedetails.Body);
|
|
260
|
-
}).catch(function (err) {
|
|
261
|
-
reject(err);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
AwsServices.prototype.GeneratePreSignedUrlNotAccelerated = function (params) {
|
|
266
|
-
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;
|
|
267
|
-
// added by Mohan ason 28-01-2022. To overwrite acl variable.
|
|
268
|
-
// acl variable will have public-read OR private value. default is private
|
|
269
|
-
if (params.accessType != '' && params.accessType != undefined && params.accessType != null) {
|
|
270
|
-
acl = params.accessType;
|
|
271
|
-
}
|
|
272
|
-
var S3 = new aws_sdk_1.default.S3({
|
|
273
|
-
accessKeyId: accessKeyId,
|
|
274
|
-
secretAccessKey: secretAccessKey,
|
|
275
|
-
region: region,
|
|
276
|
-
s3ForcePathStyle: true,
|
|
277
|
-
signatureVersion: 'v4'
|
|
278
|
-
});
|
|
279
|
-
var Params = { Bucket: bucket, Key: path, Expires: expires, ACL: acl, ContentType: contentType };
|
|
280
|
-
return new Promise(function (resolve, reject) {
|
|
281
|
-
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
282
|
-
if (err) {
|
|
283
|
-
resolve(err);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
resolve(url);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
AwsServices.prototype.GeneratePreSignedUrl = function (Bucket, Path, Acl, Region, ContentType, FileName, ContryRegionName) {
|
|
292
|
-
var _this = this;
|
|
293
|
-
return new Promise(function (resolve, reject) {
|
|
294
|
-
// to use transfer acceleration endpoint
|
|
295
|
-
var S3 = new aws_sdk_1.default.S3({
|
|
296
|
-
accessKeyId: _this.accessKeyId,
|
|
297
|
-
secretAccessKey: _this.secretAccessKey,
|
|
298
|
-
endpoint: new aws_sdk_1.default.Endpoint("optimiser-"
|
|
299
|
-
useAccelerateEndpoint: true,
|
|
300
|
-
region: Region,
|
|
301
|
-
s3ForcePathStyle: true,
|
|
302
|
-
signatureVersion: 'v4'
|
|
303
|
-
});
|
|
304
|
-
var Params = {
|
|
305
|
-
Bucket: Bucket,
|
|
306
|
-
Key: Path,
|
|
307
|
-
Expires: 60,
|
|
308
|
-
ACL: 'private',
|
|
309
|
-
ContentType: 'application/octet-stream'
|
|
310
|
-
};
|
|
311
|
-
_this.CheckIFBucketExist(Bucket, Region).then(function () {
|
|
312
|
-
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
313
|
-
if (err) {
|
|
314
|
-
resolve(err);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
resolve(url);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}).catch(function () {
|
|
321
|
-
_this.CreateNewBucket(Bucket, Region).then(function (BucketDetails) {
|
|
322
|
-
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
323
|
-
if (err) {
|
|
324
|
-
resolve(err);
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
resolve(url);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
AwsServices.prototype.ImageUpload = function (BucketName, Region, FilePath, base64String, ContentType, FileName, FileType, UploadType, Acltype, Socketid, req) {
|
|
335
|
-
var _this = this;
|
|
336
|
-
return new Promise(function (resolve, reject) {
|
|
337
|
-
aws_sdk_1.default.config.update({ region: Region });
|
|
338
|
-
var base64Data = Buffer.from(base64String.replace(/^data:image\/\w+;base64,/, ""), 'base64');
|
|
339
|
-
var params = {
|
|
340
|
-
Bucket: BucketName,
|
|
341
|
-
Key: FilePath,
|
|
342
|
-
Body: base64Data,
|
|
343
|
-
ACL: Acltype,
|
|
344
|
-
ContentEncoding: 'base64',
|
|
345
|
-
ContentType: ContentType
|
|
346
|
-
};
|
|
347
|
-
_this.s3.upload(params, function (err, data) {
|
|
348
|
-
if (err) {
|
|
349
|
-
reject(err);
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
resolve(data);
|
|
353
|
-
}
|
|
354
|
-
}).send(function (err, data) {
|
|
355
|
-
if (err) {
|
|
356
|
-
reject(err);
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
resolve(data);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
};
|
|
364
|
-
AwsServices.prototype.uploadFromStream = function (params) {
|
|
365
|
-
return this.s3.upload(params).promise();
|
|
366
|
-
};
|
|
367
|
-
AwsServices.prototype.DownloadFileInStreams = function (urlOfFile, pathToStore, type) {
|
|
368
|
-
return new Promise(function (resolve, reject) {
|
|
369
|
-
var writeStream;
|
|
370
|
-
if (type == "download") {
|
|
371
|
-
writeStream = fs_1.default.createWriteStream(pathToStore);
|
|
372
|
-
writeStream.on("finish", function () {
|
|
373
|
-
writeStream.close();
|
|
374
|
-
resolve();
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
var zipStream = unzipper_1.default.Extract({
|
|
379
|
-
path: pathToStore
|
|
380
|
-
});
|
|
381
|
-
zipStream.on("close", function () {
|
|
382
|
-
resolve();
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
axios_1.default({
|
|
386
|
-
url: urlOfFile,
|
|
387
|
-
responseType: "stream",
|
|
388
|
-
method: "get"
|
|
389
|
-
}).then(function (response) {
|
|
390
|
-
response.data.pipe(writeStream);
|
|
391
|
-
}).catch(function (e) {
|
|
392
|
-
reject(e);
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
return AwsServices;
|
|
397
|
-
}());
|
|
398
|
-
exports.default = AwsServices;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
43
|
+
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var request_1 = __importDefault(require("request"));
|
|
45
|
+
var fs_1 = __importDefault(require("fs"));
|
|
46
|
+
var unzipper_1 = __importDefault(require("unzipper"));
|
|
47
|
+
var AwsServices = /** @class */ (function () {
|
|
48
|
+
/**
|
|
49
|
+
* @param accesskeyId access key id
|
|
50
|
+
* @param secretaccesskey secret access key
|
|
51
|
+
* @param cloudfrontPublicKey region
|
|
52
|
+
* @param cloudfrontPrivateKey
|
|
53
|
+
* @description credentials for aws
|
|
54
|
+
*/
|
|
55
|
+
function AwsServices(accesskeyId, secretaccesskey, cloudfrontPublicKey, cloudfrontPrivateKey) {
|
|
56
|
+
aws_sdk_1.default.config.update({ accessKeyId: accesskeyId, secretAccessKey: secretaccesskey });
|
|
57
|
+
this.s3 = new aws_sdk_1.default.S3();
|
|
58
|
+
this.cfSigner = new aws_sdk_1.default.CloudFront.Signer(cloudfrontPublicKey, cloudfrontPrivateKey);
|
|
59
|
+
this.accessKeyId = accesskeyId;
|
|
60
|
+
this.secretAccessKey = secretaccesskey;
|
|
61
|
+
}
|
|
62
|
+
AwsServices.prototype.CreateNewBucket = function (BucketName, Region) {
|
|
63
|
+
var _this = this;
|
|
64
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
67
|
+
this.s3.createBucket({ 'Bucket': BucketName, 'CreateBucketConfiguration': { 'LocationConstraint': Region } }, function (err, data) {
|
|
68
|
+
if (err) {
|
|
69
|
+
reject(err);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
resolve(data);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
});
|
|
77
|
+
}); });
|
|
78
|
+
};
|
|
79
|
+
AwsServices.prototype.CheckIFBucketExist = function (BucketName, Region) {
|
|
80
|
+
var _this = this;
|
|
81
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
84
|
+
this.s3.headBucket({ Bucket: BucketName }, function (err, data) {
|
|
85
|
+
if (err) {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
resolve(data);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
});
|
|
94
|
+
}); });
|
|
95
|
+
};
|
|
96
|
+
AwsServices.prototype.DeleteFile = function (Bucket, Key, id, db) {
|
|
97
|
+
var _this = this;
|
|
98
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
this.s3.deleteObject({
|
|
101
|
+
Bucket: Bucket,
|
|
102
|
+
Key: Key
|
|
103
|
+
}, function (err, data) {
|
|
104
|
+
if (err) {
|
|
105
|
+
resolve(err);
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
resolve({
|
|
109
|
+
data: data,
|
|
110
|
+
id: id,
|
|
111
|
+
key: Key,
|
|
112
|
+
db: db
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return [2 /*return*/];
|
|
116
|
+
});
|
|
117
|
+
}); });
|
|
118
|
+
};
|
|
119
|
+
AwsServices.prototype.GetFile = function (BucketName, Region, FilePath) {
|
|
120
|
+
var _this = this;
|
|
121
|
+
return new Promise(function (resolve, reject) {
|
|
122
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
123
|
+
_this.s3.getObject({
|
|
124
|
+
Bucket: BucketName, Key: FilePath,
|
|
125
|
+
}, function (err, data) {
|
|
126
|
+
if (err) {
|
|
127
|
+
reject(err);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
resolve(data);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
AwsServices.prototype.getDownloadUrl = function (CDN, FilePath, FileName, action, expiry) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var exp, encodedurl, signingParams, signedUrl, err_1;
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
switch (_a.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
_a.trys.push([0, 2, , 3]);
|
|
142
|
+
exp = expiry ? expiry : 20;
|
|
143
|
+
if (action == 'preview') {
|
|
144
|
+
encodedurl = "".concat(CDN, "/").concat(FilePath);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
FileName = FileName.replace(/[;]/g, "%3b").replace(/[,]/g, "%2c").replace(/[']/g, "%27"); //converting special character to UTF-8
|
|
148
|
+
encodedurl = "".concat(CDN, "/").concat(FilePath, "?response-content-disposition=").concat(encodeURIComponent("attachment;filename=" + FileName));
|
|
149
|
+
}
|
|
150
|
+
signingParams = {
|
|
151
|
+
url: encodedurl,
|
|
152
|
+
expires: Math.floor((new Date()).getTime() / 1000) + (exp)
|
|
153
|
+
};
|
|
154
|
+
return [4 /*yield*/, this.cfSigner.getSignedUrl(signingParams)];
|
|
155
|
+
case 1:
|
|
156
|
+
signedUrl = _a.sent();
|
|
157
|
+
return [2 /*return*/, signedUrl];
|
|
158
|
+
case 2:
|
|
159
|
+
err_1 = _a.sent();
|
|
160
|
+
console.error("Error While Creating Signed Url:", err_1);
|
|
161
|
+
return [3 /*break*/, 3];
|
|
162
|
+
case 3: return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
AwsServices.prototype.GetFileStream = function (CDN, Key, FileName) {
|
|
168
|
+
var _this = this;
|
|
169
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
170
|
+
var url;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0: return [4 /*yield*/, this.getDownloadUrl(CDN, Key, FileName, 'download')];
|
|
174
|
+
case 1:
|
|
175
|
+
url = _a.sent();
|
|
176
|
+
resolve((0, request_1.default)(url));
|
|
177
|
+
return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}); });
|
|
181
|
+
};
|
|
182
|
+
AwsServices.prototype.ChangesACL = function (BucketName, FilePath) {
|
|
183
|
+
var _this = this;
|
|
184
|
+
return new Promise(function (resolve, reject) {
|
|
185
|
+
var params = { ACL: 'private', Bucket: BucketName, Key: FilePath };
|
|
186
|
+
_this.s3.putObjectAcl(params, function (err, data) {
|
|
187
|
+
if (err)
|
|
188
|
+
resolve(err);
|
|
189
|
+
else
|
|
190
|
+
resolve(data);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
AwsServices.prototype.GetSignedUrl = function (BucketName, Region, FilePath) {
|
|
195
|
+
var cdn = "https://cdn.optimiser.com";
|
|
196
|
+
if (BucketName == "optimiser-mumbai") {
|
|
197
|
+
cdn = 'https://cdn-india.optimiser.com';
|
|
198
|
+
}
|
|
199
|
+
return cdn;
|
|
200
|
+
};
|
|
201
|
+
AwsServices.prototype.UploadZip = function (params, callback) {
|
|
202
|
+
return this.s3.upload(params, callback);
|
|
203
|
+
};
|
|
204
|
+
AwsServices.prototype.UploadFile = function (BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UniqueID, Socketid, req) {
|
|
205
|
+
var _this = this;
|
|
206
|
+
return new Promise(function (resolve, reject) {
|
|
207
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
208
|
+
var CacheControlHeader = 'max-age=604800';
|
|
209
|
+
_this.s3.upload({
|
|
210
|
+
Key: FilePath,
|
|
211
|
+
Bucket: BucketName,
|
|
212
|
+
Body: File,
|
|
213
|
+
ACL: Acltype,
|
|
214
|
+
ContentType: ContentType,
|
|
215
|
+
CacheControl: CacheControlHeader
|
|
216
|
+
}, function (err, data) {
|
|
217
|
+
if (err) {
|
|
218
|
+
reject(err);
|
|
219
|
+
}
|
|
220
|
+
}).send(function (err, data) {
|
|
221
|
+
if (err) {
|
|
222
|
+
reject(err);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
resolve(data);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
AwsServices.prototype.UploadToS3 = function (BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req) {
|
|
231
|
+
var _this = this;
|
|
232
|
+
return new Promise(function (resolve, reject) {
|
|
233
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
234
|
+
_this.CheckIFBucketExist(BucketName, Region).then(function () {
|
|
235
|
+
_this.UploadFile(BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req).then(function (sucess) {
|
|
236
|
+
resolve(sucess);
|
|
237
|
+
}).catch(function (err) {
|
|
238
|
+
reject(err);
|
|
239
|
+
});
|
|
240
|
+
}).catch(function () {
|
|
241
|
+
//Bucket does not exist in that particular region
|
|
242
|
+
_this.CreateNewBucket(BucketName, Region).then(function (BucketDetails) {
|
|
243
|
+
_this.UploadFile(BucketName, Region, FilePath, File, ContentType, FileName, FileType, UploadType, Acltype, UploadTime, SocketID, req).then(function (sucess) {
|
|
244
|
+
resolve(sucess);
|
|
245
|
+
}).catch(function (err) {
|
|
246
|
+
reject(err);
|
|
247
|
+
});
|
|
248
|
+
}).catch(function (err) {
|
|
249
|
+
console.log("Error While Uploading Files:", err);
|
|
250
|
+
reject(err);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
AwsServices.prototype.GetFileFromS3 = function (BucketName, Region, FilePath) {
|
|
256
|
+
var _this = this;
|
|
257
|
+
return new Promise(function (resolve, reject) {
|
|
258
|
+
_this.GetFile(BucketName, Region, FilePath).then(function (filedetails) {
|
|
259
|
+
resolve(filedetails.Body);
|
|
260
|
+
}).catch(function (err) {
|
|
261
|
+
reject(err);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
AwsServices.prototype.GeneratePreSignedUrlNotAccelerated = function (params) {
|
|
266
|
+
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;
|
|
267
|
+
// added by Mohan ason 28-01-2022. To overwrite acl variable.
|
|
268
|
+
// acl variable will have public-read OR private value. default is private
|
|
269
|
+
if (params.accessType != '' && params.accessType != undefined && params.accessType != null) {
|
|
270
|
+
acl = params.accessType;
|
|
271
|
+
}
|
|
272
|
+
var S3 = new aws_sdk_1.default.S3({
|
|
273
|
+
accessKeyId: accessKeyId,
|
|
274
|
+
secretAccessKey: secretAccessKey,
|
|
275
|
+
region: region,
|
|
276
|
+
s3ForcePathStyle: true,
|
|
277
|
+
signatureVersion: 'v4'
|
|
278
|
+
});
|
|
279
|
+
var Params = { Bucket: bucket, Key: path, Expires: expires, ACL: acl, ContentType: contentType };
|
|
280
|
+
return new Promise(function (resolve, reject) {
|
|
281
|
+
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
282
|
+
if (err) {
|
|
283
|
+
resolve(err);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
resolve(url);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
AwsServices.prototype.GeneratePreSignedUrl = function (Bucket, Path, Acl, Region, ContentType, FileName, ContryRegionName) {
|
|
292
|
+
var _this = this;
|
|
293
|
+
return new Promise(function (resolve, reject) {
|
|
294
|
+
// to use transfer acceleration endpoint
|
|
295
|
+
var S3 = new aws_sdk_1.default.S3({
|
|
296
|
+
accessKeyId: _this.accessKeyId,
|
|
297
|
+
secretAccessKey: _this.secretAccessKey,
|
|
298
|
+
endpoint: new aws_sdk_1.default.Endpoint("optimiser-".concat(ContryRegionName, ".s3-accelerate.amazonaws.com")),
|
|
299
|
+
useAccelerateEndpoint: true,
|
|
300
|
+
region: Region,
|
|
301
|
+
s3ForcePathStyle: true,
|
|
302
|
+
signatureVersion: 'v4'
|
|
303
|
+
});
|
|
304
|
+
var Params = {
|
|
305
|
+
Bucket: Bucket,
|
|
306
|
+
Key: Path,
|
|
307
|
+
Expires: 60,
|
|
308
|
+
ACL: 'private',
|
|
309
|
+
ContentType: 'application/octet-stream'
|
|
310
|
+
};
|
|
311
|
+
_this.CheckIFBucketExist(Bucket, Region).then(function () {
|
|
312
|
+
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
313
|
+
if (err) {
|
|
314
|
+
resolve(err);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
resolve(url);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}).catch(function () {
|
|
321
|
+
_this.CreateNewBucket(Bucket, Region).then(function (BucketDetails) {
|
|
322
|
+
S3.getSignedUrl('putObject', Params, function (err, url) {
|
|
323
|
+
if (err) {
|
|
324
|
+
resolve(err);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
resolve(url);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
AwsServices.prototype.ImageUpload = function (BucketName, Region, FilePath, base64String, ContentType, FileName, FileType, UploadType, Acltype, Socketid, req) {
|
|
335
|
+
var _this = this;
|
|
336
|
+
return new Promise(function (resolve, reject) {
|
|
337
|
+
aws_sdk_1.default.config.update({ region: Region });
|
|
338
|
+
var base64Data = Buffer.from(base64String.replace(/^data:image\/\w+;base64,/, ""), 'base64');
|
|
339
|
+
var params = {
|
|
340
|
+
Bucket: BucketName,
|
|
341
|
+
Key: FilePath,
|
|
342
|
+
Body: base64Data,
|
|
343
|
+
ACL: Acltype,
|
|
344
|
+
ContentEncoding: 'base64', // required
|
|
345
|
+
ContentType: ContentType
|
|
346
|
+
};
|
|
347
|
+
_this.s3.upload(params, function (err, data) {
|
|
348
|
+
if (err) {
|
|
349
|
+
reject(err);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
resolve(data);
|
|
353
|
+
}
|
|
354
|
+
}).send(function (err, data) {
|
|
355
|
+
if (err) {
|
|
356
|
+
reject(err);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
resolve(data);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
AwsServices.prototype.uploadFromStream = function (params) {
|
|
365
|
+
return this.s3.upload(params).promise();
|
|
366
|
+
};
|
|
367
|
+
AwsServices.prototype.DownloadFileInStreams = function (urlOfFile, pathToStore, type) {
|
|
368
|
+
return new Promise(function (resolve, reject) {
|
|
369
|
+
var writeStream;
|
|
370
|
+
if (type == "download") {
|
|
371
|
+
writeStream = fs_1.default.createWriteStream(pathToStore);
|
|
372
|
+
writeStream.on("finish", function () {
|
|
373
|
+
writeStream.close();
|
|
374
|
+
resolve();
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
var zipStream = unzipper_1.default.Extract({
|
|
379
|
+
path: pathToStore
|
|
380
|
+
});
|
|
381
|
+
zipStream.on("close", function () {
|
|
382
|
+
resolve();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
(0, axios_1.default)({
|
|
386
|
+
url: urlOfFile,
|
|
387
|
+
responseType: "stream",
|
|
388
|
+
method: "get"
|
|
389
|
+
}).then(function (response) {
|
|
390
|
+
response.data.pipe(writeStream);
|
|
391
|
+
}).catch(function (e) {
|
|
392
|
+
reject(e);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
return AwsServices;
|
|
397
|
+
}());
|
|
398
|
+
exports.default = AwsServices;
|