@maioradv/nestjs-core 1.9.10 → 1.9.12

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.
@@ -7,4 +7,5 @@ export declare class ImageCompressionPipe implements PipeTransform<Express.Multe
7
7
  private readonly options;
8
8
  constructor(options?: CompressionOptions);
9
9
  transform(file: Express.Multer.File, metadata: ArgumentMetadata): Promise<Express.Multer.File>;
10
+ private defaultQuality;
10
11
  }
@@ -22,9 +22,11 @@ let ImageCompressionPipe = class ImageCompressionPipe {
22
22
  }
23
23
  async transform(file, metadata) {
24
24
  try {
25
+ const meta = await (0, sharp_1.default)(file.buffer).metadata();
26
+ const defaultQuality = this.defaultQuality(meta.width, meta.height);
25
27
  const [resolutionCap, quality] = [
26
28
  this.options.resolutionCap ?? 2560,
27
- this.options.quality ?? 70
29
+ this.options.quality ?? defaultQuality
28
30
  ];
29
31
  const compressedBuffer = await (0, sharp_1.default)(file.buffer, { failOn: 'error' })
30
32
  .resize({
@@ -47,6 +49,12 @@ let ImageCompressionPipe = class ImageCompressionPipe {
47
49
  throw new common_1.BadRequestException(`Error processing the image: ${error?.message}`);
48
50
  }
49
51
  }
52
+ defaultQuality(width, height) {
53
+ if (!width || !height)
54
+ return 70;
55
+ const area = width * height;
56
+ return area > 2e6 ? 50 : area > 1e6 ? 60 : 70;
57
+ }
50
58
  };
51
59
  exports.ImageCompressionPipe = ImageCompressionPipe;
52
60
  exports.ImageCompressionPipe = ImageCompressionPipe = __decorate([
@@ -32,7 +32,6 @@ let S3Service = class S3Service {
32
32
  async uploadImage(file) {
33
33
  try {
34
34
  let fileName = `${this.randomString(6)}-${file.originalname}`;
35
- this.logger.log('randome', fileName);
36
35
  /*try {
37
36
  const check = await this.client.send(
38
37
  new HeadObjectCommand({
@@ -48,9 +47,7 @@ let S3Service = class S3Service {
48
47
  Body: file.buffer,
49
48
  ContentType: file.mimetype
50
49
  }));
51
- this.logger.log('response', response);
52
50
  const size = (0, image_size_1.imageSize)(file.buffer);
53
- this.logger.log('sizeof', size);
54
51
  const checksum = (0, crypto_1.createHash)('md5').update(file.buffer).digest("base64");
55
52
  return {
56
53
  src: `${this.sdkConfigs.baseUrl}/${this.sdkConfigs.folder}/${fileName}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.9.10",
3
+ "version": "1.9.12",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",