@maioradv/nestjs-core 1.4.7 → 1.4.9
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.
|
@@ -14,6 +14,7 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const sharp_1 = __importDefault(require("sharp"));
|
|
16
16
|
let ImageCompressionPipe = class ImageCompressionPipe {
|
|
17
|
+
//private readonly logger = LoggerFactory(this.constructor.name);
|
|
17
18
|
async transform(file, metadata) {
|
|
18
19
|
try {
|
|
19
20
|
const compressedBuffer = await (0, sharp_1.default)(file.buffer).webp({
|
|
@@ -22,10 +23,13 @@ let ImageCompressionPipe = class ImageCompressionPipe {
|
|
|
22
23
|
file.buffer = compressedBuffer;
|
|
23
24
|
file.mimetype = 'image/webp';
|
|
24
25
|
file.size = compressedBuffer.length;
|
|
25
|
-
file.originalname = file.originalname.replace((0, path_1.extname)(file.originalname), '.webp');
|
|
26
|
+
file.originalname = file.originalname.replace((0, path_1.extname)(file.originalname), '.webp').replaceAll(' ', '-');
|
|
26
27
|
return file;
|
|
27
28
|
}
|
|
28
29
|
catch (error) {
|
|
30
|
+
/*const {buffer,stream, ...log} = file
|
|
31
|
+
this.logger.error(log)
|
|
32
|
+
this.logger.error(error)*/
|
|
29
33
|
throw new common_1.BadRequestException(`Error processing the image: ${error?.message}`);
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_MAX_IMAGE_SIZE = 10;
|
|
2
|
-
export declare const DEFAULT_MIMETYPES_SUPPORT = ".(webp|avif|png|gif|jpeg|jpg
|
|
2
|
+
export declare const DEFAULT_MIMETYPES_SUPPORT = ".(webp|avif|png|gif|jpeg|jpg)";
|
|
3
3
|
export type ImagePipeValidatorOptions = {
|
|
4
4
|
maxSize?: number;
|
|
5
|
-
mimeTypes?: ('webp' | 'avif' | 'png' | 'gif' | 'jpeg' | 'jpg'
|
|
5
|
+
mimeTypes?: ('webp' | 'avif' | 'png' | 'gif' | 'jpeg' | 'jpg')[];
|
|
6
6
|
};
|
|
7
7
|
export declare const ImagePipeValidator: (options?: ImagePipeValidatorOptions) => import("@nestjs/common").ParseFilePipe;
|
|
@@ -4,7 +4,7 @@ exports.ImagePipeValidator = exports.DEFAULT_MIMETYPES_SUPPORT = exports.DEFAULT
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
exports.DEFAULT_MAX_IMAGE_SIZE = 10;
|
|
6
6
|
//heic uploaded as application/octet-stream
|
|
7
|
-
exports.DEFAULT_MIMETYPES_SUPPORT = '.(webp|avif|png|gif|jpeg|jpg
|
|
7
|
+
exports.DEFAULT_MIMETYPES_SUPPORT = '.(webp|avif|png|gif|jpeg|jpg)';
|
|
8
8
|
const ImagePipeValidator = (options) => new common_1.ParseFilePipeBuilder()
|
|
9
9
|
.addFileTypeValidator({ fileType: options?.mimeTypes ? `.(${options.mimeTypes.join('|')})` : exports.DEFAULT_MIMETYPES_SUPPORT })
|
|
10
10
|
.addMaxSizeValidator({ maxSize: (options?.maxSize ?? exports.DEFAULT_MAX_IMAGE_SIZE) * 1e6 })
|