@maioradv/nestjs-core 1.9.11 → 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([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.9.11",
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",