@maioradv/nestjs-core 1.4.8 → 1.5.0

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.
@@ -1,6 +1,5 @@
1
1
  /// <reference types="multer" />
2
2
  import { PipeTransform, ArgumentMetadata } from '@nestjs/common';
3
3
  export declare class ImageCompressionPipe implements PipeTransform<Express.Multer.File, Promise<Express.Multer.File>> {
4
- private readonly logger;
5
4
  transform(file: Express.Multer.File, metadata: ArgumentMetadata): Promise<Express.Multer.File>;
6
5
  }
@@ -13,26 +13,23 @@ exports.ImageCompressionPipe = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const path_1 = require("path");
15
15
  const sharp_1 = __importDefault(require("sharp"));
16
- const logger_1 = require("../logger");
17
16
  let ImageCompressionPipe = class ImageCompressionPipe {
18
- constructor() {
19
- this.logger = (0, logger_1.LoggerFactory)(this.constructor.name);
20
- }
17
+ //private readonly logger = LoggerFactory(this.constructor.name);
21
18
  async transform(file, metadata) {
22
19
  try {
23
20
  const compressedBuffer = await (0, sharp_1.default)(file.buffer).webp({
24
- quality: 70,
21
+ quality: 80,
25
22
  }).rotate().toBuffer();
26
23
  file.buffer = compressedBuffer;
27
24
  file.mimetype = 'image/webp';
28
25
  file.size = compressedBuffer.length;
29
- 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(' ', '-');
30
27
  return file;
31
28
  }
32
29
  catch (error) {
33
- const { buffer, stream, ...log } = file;
34
- this.logger.error(log);
35
- this.logger.error(error);
30
+ /*const {buffer,stream, ...log} = file
31
+ this.logger.error(log)
32
+ this.logger.error(error)*/
36
33
  throw new common_1.BadRequestException(`Error processing the image: ${error?.message}`);
37
34
  }
38
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|heic|heif|hevc|octet-stream)";
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' | 'heic' | 'heif' | 'hevc' | 'octet-stream')[];
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|heic|heif|hevc|octet-stream)';
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 })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- import { Stats } from 'fs';
6
- import internal from 'stream';
7
- export declare class StorageHelper {
8
- rootPath: string;
9
- read(path: string): Promise<Buffer>;
10
- write(path: string, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | internal.Stream): Promise<void>;
11
- append(path: string, data: string | Uint8Array): Promise<void>;
12
- delete(path: string): Promise<void>;
13
- stat(path: string): Promise<Stats>;
14
- private safeDirectory;
15
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StorageHelper = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const os_1 = require("os");
7
- const path_helper_1 = require("./path.helper");
8
- class StorageHelper {
9
- constructor() {
10
- this.rootPath = (0, path_helper_1.joinFromRoot)('public');
11
- }
12
- async read(path) {
13
- const realPath = (0, path_1.join)(this.rootPath, path);
14
- return await fs_1.promises.readFile(realPath, {});
15
- }
16
- async write(path, data) {
17
- const realPath = (0, path_1.join)(this.rootPath, path);
18
- await this.safeDirectory(realPath);
19
- return await fs_1.promises.writeFile(realPath, data, 'utf8');
20
- }
21
- async append(path, data) {
22
- const realPath = (0, path_1.join)(this.rootPath, path);
23
- await this.safeDirectory(realPath);
24
- return await fs_1.promises.appendFile(realPath, data + os_1.EOL);
25
- }
26
- async delete(path) {
27
- const realPath = (0, path_1.join)(this.rootPath, path);
28
- try {
29
- return await fs_1.promises.unlink(realPath);
30
- }
31
- catch (e) { }
32
- }
33
- async stat(path) {
34
- const realPath = (0, path_1.join)(this.rootPath, path);
35
- return fs_1.promises.stat(realPath);
36
- }
37
- async safeDirectory(path) {
38
- const dirPath = (0, path_1.dirname)(path);
39
- try {
40
- await fs_1.promises.stat(dirPath);
41
- }
42
- catch (e) {
43
- await fs_1.promises.mkdir(dirPath, { recursive: true });
44
- }
45
- }
46
- }
47
- exports.StorageHelper = StorageHelper;