nestjs-form-data
Advanced tools
Comparing version 1.9.6 to 1.9.7
@@ -7,5 +7,6 @@ "use strict"; | ||
storage: MemoryStoredFile_1.MemoryStoredFile, | ||
autoDeleteFile: true, | ||
cleanupAfterSuccessHandle: true, | ||
cleanupAfterFailedHandle: true, | ||
fileSystemStoragePath: '/tmp/nestjs-tmp-storage', | ||
}; | ||
//# sourceMappingURL=default.config.js.map |
import { ValidationOptions } from 'class-validator'; | ||
import { MetaSource } from '../../interfaces/MetaFieldSource'; | ||
export declare function HasMimeType(allowedMimeTypes: string[] | string, strictSource?: MetaSource | ValidationOptions, validationOptions?: ValidationOptions): PropertyDecorator; | ||
export type AllowedMimeTypes = Array<AllowedMimeType>; | ||
export type AllowedMimeType = string | RegExp; | ||
export declare function HasMimeType(allowedMimeTypes: AllowedMimeTypes | AllowedMimeType, strictSource?: MetaSource | ValidationOptions, validationOptions?: ValidationOptions): PropertyDecorator; | ||
//# sourceMappingURL=has-mime-type.validator.d.ts.map |
@@ -19,3 +19,28 @@ "use strict"; | ||
const mimeWithSource = value.mimeTypeWithSource; | ||
return allowedMimeTypes.includes(mimeWithSource.value) && (!strictSource || strictSource === mimeWithSource.source); | ||
const hasSourceMatch = !strictSource || strictSource === mimeWithSource.source; | ||
if (!hasSourceMatch) { | ||
return false; | ||
} | ||
for (let mimeType of allowedMimeTypes) { | ||
switch (true) { | ||
case typeof mimeType === 'string' && !mimeType.includes('*'): | ||
if (mimeType === mimeWithSource.value) { | ||
return true; | ||
} | ||
break; | ||
case typeof mimeType === 'string' && mimeType.includes('*'): | ||
const regex = new RegExp(`^${mimeType}$`.replace('*', '.+')); | ||
if (regex.test(mimeWithSource.value)) { | ||
return true; | ||
} | ||
break; | ||
case mimeType instanceof RegExp: | ||
if (mimeType.test(mimeWithSource.value)) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
throw new Error(`Unknown mime type for validate`); | ||
} | ||
} | ||
} | ||
@@ -22,0 +47,0 @@ return false; |
@@ -6,6 +6,11 @@ "use strict"; | ||
function checkConfig(config, defaults = default_config_1.DEFAULT_CONFIG) { | ||
config = Object.assign({}, config); | ||
if (!config.storage) | ||
config.storage = defaults.storage; | ||
if (config.autoDeleteFile === undefined) | ||
config.autoDeleteFile = defaults.autoDeleteFile; | ||
if (config.cleanupAfterSuccessHandle === undefined) { | ||
config.cleanupAfterSuccessHandle = defaults.cleanupAfterSuccessHandle; | ||
} | ||
if (config.cleanupAfterFailedHandle === undefined) { | ||
config.cleanupAfterFailedHandle = defaults.cleanupAfterFailedHandle; | ||
} | ||
if (!config.fileSystemStoragePath) | ||
@@ -12,0 +17,0 @@ config.fileSystemStoragePath = defaults.fileSystemStoragePath; |
@@ -47,7 +47,7 @@ "use strict"; | ||
}), (0, rxjs_1.catchError)((err) => { | ||
if (config.autoDeleteFile) | ||
if (config.cleanupAfterFailedHandle || config.autoDeleteFile) | ||
formReader.deleteFiles(); | ||
return (0, rxjs_1.throwError)(err); | ||
}), (0, operators_1.tap)((res) => { | ||
if (config.autoDeleteFile) | ||
}), (0, operators_1.tap)(() => { | ||
if (config.cleanupAfterSuccessHandle || config.autoDeleteFile) | ||
formReader.deleteFiles(); | ||
@@ -54,0 +54,0 @@ })); |
@@ -6,3 +6,23 @@ import { StoredFile } from '../classes/storage'; | ||
fileSystemStoragePath?: string; | ||
/** | ||
* @deprecated | ||
* Use `cleanupAfterSuccessHandle` and `cleanupAfterFailedHandle` instead; | ||
*/ | ||
autoDeleteFile?: boolean; | ||
/** | ||
* Indicates whether cleanup should be performed after successful handling. | ||
* If set to true, all processed and uploaded files will be deleted after successful processing by the final method. | ||
* This means that the `delete` method will be called on all files (StoredFile) | ||
* @type {boolean} | ||
* @default true | ||
*/ | ||
cleanupAfterSuccessHandle?: boolean; | ||
/** | ||
* Indicates whether cleanup should be performed after error handling. | ||
* If set to true, all processed and uploaded files will be deleted after unsuccessful processing by the final method. | ||
* This means that the `delete` method will be called on all files (StoredFile) | ||
* @type {boolean} | ||
* @default true | ||
*/ | ||
cleanupAfterFailedHandle?: boolean; | ||
limits?: FormDataInterceptorLimitsConfig; | ||
@@ -9,0 +29,0 @@ /** |
{ | ||
"name": "nestjs-form-data", | ||
"version": "1.9.6", | ||
"version": "1.9.7", | ||
"description": "NestJS middleware for handling multipart/form-data, which is primarily used for uploading files", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
@@ -170,3 +170,4 @@ [![npm version](https://badge.fury.io/js/nestjs-form-data.svg)](https://badge.fury.io/js/nestjs-form-data) | ||
- `fileSystemStoragePath` - The path to the directory for storing temporary files, used only for `storage: FileSystemStoredFile` (Default: /tmp/nestjs-tmp-storage) | ||
- `autoDeleteFile` - Automatically delete files after the request ends (Default true) | ||
- `cleanupAfterSuccessHandle` - If set to true, all processed and uploaded files will be deleted after successful processing by the final method. This means that the `delete` method will be called on all files (StoredFile) | ||
- `cleanupAfterFailedHandle` - If set to true, all processed and uploaded files will be deleted after unsuccessful processing by the final method. This means that the `delete` method will be called on all files (StoredFile) | ||
- `limits` - [busboy](https://www.npmjs.com/package/busboy#busboy-methods) limits configuration. Constraints in this declaration are handled at the serialization stage, so using these parameters is preferable for performance. | ||
@@ -220,6 +221,19 @@ ## File storage types | ||
```ts | ||
@HasMimeType(allowedMimeTypes: string[] | string, strictSource?: MetaSource | ValidationOptions, validationOptions?: ValidationOptions) | ||
type AllowedMimeTypes = Array<AllowedMimeType> | ||
type AllowedMimeType = string | RegExp; | ||
@HasMimeType(allowedMimeTypes: AllowedMimeTypes | AllowedMimeType, strictSource?: MetaSource | ValidationOptions, validationOptions?: ValidationOptions) | ||
``` | ||
You can also use partial matching, just pass the unimportant parameter as `*`, for example: | ||
```ts | ||
@HasMimeType('image/*') | ||
``` | ||
also as array: | ||
```ts | ||
@HasMimeType(['image/*', 'text/*']) | ||
``` | ||
### HasExtension | ||
@@ -226,0 +240,0 @@ Check the extension type of the file |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97344
1056
311