@maioradv/nestjs-core 1.9.8 → 1.9.10
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.
|
@@ -13,6 +13,7 @@ export declare class S3Service {
|
|
|
13
13
|
private readonly config;
|
|
14
14
|
readonly client: S3Client;
|
|
15
15
|
private sdkConfigs;
|
|
16
|
+
private readonly logger;
|
|
16
17
|
constructor(config: ConfigService);
|
|
17
18
|
uploadImage(file: Express.Multer.File): Promise<UploadImageResponse>;
|
|
18
19
|
removeFile(fileName: string): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
|
|
@@ -15,9 +15,11 @@ const config_1 = require("@nestjs/config");
|
|
|
15
15
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
16
16
|
const crypto_1 = require("crypto");
|
|
17
17
|
const image_size_1 = require("image-size");
|
|
18
|
+
const logger_1 = require("../logger");
|
|
18
19
|
let S3Service = class S3Service {
|
|
19
20
|
constructor(config) {
|
|
20
21
|
this.config = config;
|
|
22
|
+
this.logger = (0, logger_1.LoggerFactory)(this.constructor.name);
|
|
21
23
|
this.sdkConfigs = this.config.get('aws.s3sdk');
|
|
22
24
|
this.client = new client_s3_1.S3Client({
|
|
23
25
|
region: this.sdkConfigs.region,
|
|
@@ -28,33 +30,42 @@ let S3Service = class S3Service {
|
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
async uploadImage(file) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
try {
|
|
34
|
+
let fileName = `${this.randomString(6)}-${file.originalname}`;
|
|
35
|
+
this.logger.log('randome', fileName);
|
|
36
|
+
/*try {
|
|
37
|
+
const check = await this.client.send(
|
|
38
|
+
new HeadObjectCommand({
|
|
39
|
+
Bucket: this.sdkConfigs.bucketName,
|
|
40
|
+
Key: `${this.sdkConfigs.folder}/${fileName}`,
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
if(check) fileName = `${this.randomString(5)}-${fileName}`
|
|
44
|
+
} catch(e) {}*/
|
|
45
|
+
const response = await this.client.send(new client_s3_1.PutObjectCommand({
|
|
46
|
+
Bucket: this.sdkConfigs.bucketName,
|
|
47
|
+
Key: `${this.sdkConfigs.folder}/${fileName}`,
|
|
48
|
+
Body: file.buffer,
|
|
49
|
+
ContentType: file.mimetype
|
|
50
|
+
}));
|
|
51
|
+
this.logger.log('response', response);
|
|
52
|
+
const size = (0, image_size_1.imageSize)(file.buffer);
|
|
53
|
+
this.logger.log('sizeof', size);
|
|
54
|
+
const checksum = (0, crypto_1.createHash)('md5').update(file.buffer).digest("base64");
|
|
55
|
+
return {
|
|
56
|
+
src: `${this.sdkConfigs.baseUrl}/${this.sdkConfigs.folder}/${fileName}`,
|
|
57
|
+
width: size.width,
|
|
58
|
+
height: size.height,
|
|
59
|
+
checksum: checksum,
|
|
60
|
+
fileName: fileName,
|
|
61
|
+
mimeType: file.mimetype,
|
|
62
|
+
size: file.size
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
this.logger.error(e);
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
async removeFile(fileName) {
|
|
60
71
|
return this.client.send(new client_s3_1.DeleteObjectCommand({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maioradv/nestjs-core",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.10",
|
|
4
4
|
"description": "NestJS helpers by MaiorADV",
|
|
5
5
|
"repository": "https://github.com/maioradv/nestjs-core.git",
|
|
6
6
|
"author": "Maior ADV Srl",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"bcrypt": "^6.0.0",
|
|
63
63
|
"class-transformer": "^0.5.1",
|
|
64
64
|
"class-validator": "^0.14.2",
|
|
65
|
+
"file-type": "^20.5.0",
|
|
65
66
|
"handlebars": "^4.7.8",
|
|
66
67
|
"image-size": "^2.0.2",
|
|
67
68
|
"nest-winston": "^1.10.2",
|