chore(common): temporarily move file-type to regular deps

This commit is contained in:
Kamil Myśliwiec
2025-04-15 17:56:26 +02:00
parent 55ca078df1
commit d9a69a32a4
3 changed files with 17 additions and 7 deletions

View File

@@ -18,6 +18,7 @@
},
"license": "MIT",
"dependencies": {
"file-type": "20.4.1",
"iterare": "1.2.1",
"tslib": "2.8.1",
"uid": "2.0.2"
@@ -25,7 +26,6 @@
"peerDependencies": {
"class-transformer": "*",
"class-validator": "*",
"file-type": "^20.4.1",
"reflect-metadata": "^0.1.12 || ^0.2.0",
"rxjs": "^7.1.0"
},
@@ -35,9 +35,6 @@
},
"class-transformer": {
"optional": true
},
"file-type": {
"optional": true
}
}
}

View File

@@ -25,6 +25,19 @@ export class FileTypeValidator extends FileValidator<
FileTypeValidatorOptions,
IFile
> {
constructor(validationOptions: FileTypeValidatorOptions) {
super(validationOptions);
// check if file-type is installed
try {
require.resolve('file-type');
} catch (e) {
throw new Error(
`FileTypeValidator requires the file-type package. Please install it: npm i file-type`,
);
}
}
buildErrorMessage(file?: IFile): string {
if (file?.mimetype) {
return `Validation failed (current file type is ${file.mimetype}, expected type is ${this.validationOptions.fileType})`;

View File

@@ -1,8 +1,8 @@
import {
BadRequestException,
PipeTransform,
Injectable,
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform,
} from '@nestjs/common';
@Injectable()