dmitriy-nz / nestjs-form-data

NestJS middleware for handling multipart/form-data, which is primarily used for uploading files.
https://www.npmjs.com/package/nestjs-form-data
MIT License
117 stars 23 forks source link

MetaSource not exported? #52

Closed kamilmclearcode closed 7 months ago

kamilmclearcode commented 9 months ago

I try to use HasMimeType like that: @HasMimeType(['image/png'], 'bufferMagicNumber'), but I'm getting an error Argument of type '"bufferMagicNumber"' is not assignable to parameter of type 'MetaSource | ValidationOptions'

I'm trying to import MetaSource to use the enum value: import { MetaSource } from 'nestjs-form-data'; but it says: Module '"nestjs-form-data"' has no exported member 'MetaSource'

Am I doing something wrong, or MetaSource is not publicly available?

Maybe, I don't need it in the first place? I wish the validation DOES check the magic number using file-type lib, README says The default is simple mode, which does not check the data source, but you can pass a second argument to strictly check the mime-type and data source., but it doesn't show example usage, how to do it?

dmitriy-nz commented 9 months ago

Hi @kamilmclearcode , you are right, it is not exported. I fixed it in the version nestjs-form-data@1.9.4, it is already available. Please try it out. Use HasExtension decorator:

@HasMimeType(allowedMimeTypes: string[] | string, strictSource?: MetaSource | ValidationOptions, validationOptions?: ValidationOptions)
kamilmclearcode commented 9 months ago

Hello @dmitriy-nz Thanks for the fix, however there is something wrong with the export. This is what my IDE says: image

And it makes me do the import this way: import { MetaSource } from 'nestjs-form-data/dist/interfaces'; - should it be like that?

BTW, just to clarify - tests I made in my app suggests that MetaSource.bufferMagicNumber is the default setting, if you don't set it explicitely on the decorator. Is that correct?

dmitriy-nz commented 8 months ago

@kamilmclearcode yeah, it's still my bad, fixed in nestjs-form-data@1.9.5

kamilmclearcode commented 7 months ago

@dmitriy-nz thank you, all good now