@maioradv/nestjs-core 1.5.6 → 1.5.7
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.
|
@@ -5,7 +5,7 @@ export type CompressionOptions = {
|
|
|
5
5
|
quality?: number;
|
|
6
6
|
};
|
|
7
7
|
export declare class ImageCompressionPipe implements PipeTransform<Express.Multer.File, Promise<Express.Multer.File>> {
|
|
8
|
-
private readonly options
|
|
8
|
+
private readonly options?;
|
|
9
9
|
constructor(options?: CompressionOptions);
|
|
10
10
|
transform(file: Express.Multer.File, metadata: ArgumentMetadata): Promise<Express.Multer.File>;
|
|
11
11
|
}
|
|
@@ -17,15 +17,14 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const sharp_1 = __importDefault(require("sharp"));
|
|
19
19
|
let ImageCompressionPipe = class ImageCompressionPipe {
|
|
20
|
-
|
|
21
|
-
constructor(options = {}) {
|
|
20
|
+
constructor(options) {
|
|
22
21
|
this.options = options;
|
|
23
22
|
}
|
|
24
23
|
async transform(file, metadata) {
|
|
25
24
|
try {
|
|
26
25
|
const [resolutionCap, quality] = [
|
|
27
|
-
this.options
|
|
28
|
-
this.options
|
|
26
|
+
this.options?.resolutionCap ?? 2560,
|
|
27
|
+
this.options?.quality ?? 70
|
|
29
28
|
];
|
|
30
29
|
const compressedBuffer = await (0, sharp_1.default)(file.buffer, { failOn: 'error' })
|
|
31
30
|
.resize({
|
|
@@ -45,9 +44,6 @@ let ImageCompressionPipe = class ImageCompressionPipe {
|
|
|
45
44
|
return file;
|
|
46
45
|
}
|
|
47
46
|
catch (error) {
|
|
48
|
-
/*const {buffer,stream, ...log} = file
|
|
49
|
-
this.logger.error(log)
|
|
50
|
-
this.logger.error(error)*/
|
|
51
47
|
throw new common_1.BadRequestException(`Error processing the image: ${error?.message}`);
|
|
52
48
|
}
|
|
53
49
|
}
|