import { InvalidMimeTypeError } from '@/application/errors' ; export type Extension = 'png' | 'jpg' ; export class AllowedMimeTypes { constructor ( private readonly allowed , private readonly mimeType ) { } validate ( ) { let isValid = false ; if ( this . isPng ( ) ) isValid = true ; else if ( this . isJpg ( ) ) isValid = true ; if ( ! isValid ) return new InvalidMimeTypeError ( this . allowed ) ; } private isPng ( ) { return this . allowed . includes ( 'png' ) && this . mimeType === 'image/png' ; } private isJpg ( ) { return this . allowed . includes ( 'jpg' ) && /image\/jpe?g/ . test ( this . mimeType ) ; } }