Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): file type validator #9832

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

thiagomini
Copy link
Contributor

add regex support when checking a file mime-type as requested here.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

FileTypePipe only checks against common strings.

What is the new behavior?

FileTypePipe now can check against regular expressions.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

add regex support when checking a file mime-type
@coveralls
Copy link

Pull Request Test Coverage Report for Build db003176-c1db-4d09-a5f7-494250e09f5d

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 0.0%

Totals Coverage Status
Change from base Build 65d9da58-6dff-463f-9e0b-31e9b55ab12d: 0.0%
Covered Lines: 0
Relevant Lines: 0

💛 - Coveralls

@@ -25,6 +29,8 @@ export class FileTypeValidator extends FileValidator<FileTypeValidatorOptions> {
return false;
}

return (file.mimetype as string).endsWith(this.validationOptions.fileType);
return Boolean(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about the use of Boolean here 😄 What about just !! instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use Boolean cast because I think it is more explicit than using !!, and IMHO, quoting Uncle Bob:

We want code to be as expressive as possible

But if using !! is preferred for standardization reasons I can change it as well, just let me know!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's just Boolean not new Boolean, I'm OK with that! I've assumed you're instantiating a boxing type here that wraps a primitive value (instead of just coercing the value).

@kamilmysliwiec kamilmysliwiec merged commit 349fb28 into nestjs:9.0.0 Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants