-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PreSignedPostRequest 에서 사용할 IsImageFile 데코레이터 생성/ 해당 데코레이터 exte…
…nsion 에 추가하여 이미지 파일 유효성 검사/ 함수 이름 변경 #88
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const IMAGE_EXTENSIONS = new Set([ | ||
'jpg', | ||
'jpeg', | ||
'png', | ||
'gif', | ||
'bmp', | ||
'tiff', | ||
'tif', | ||
'webp', | ||
'svg', | ||
'heic', | ||
'raw', | ||
'cr2', | ||
'nef', | ||
'arw', | ||
'dng', | ||
'ico', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
registerDecorator, | ||
ValidationArguments, | ||
ValidatorOptions, | ||
} from 'class-validator'; | ||
import { IMAGE_EXTENSIONS } from './storage.constants'; | ||
|
||
export function IsImageFile(validationOptions?: ValidatorOptions) { | ||
return function (object: object, propertyName: string) { | ||
registerDecorator({ | ||
name: 'IsImageFile', | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate(value: any) { | ||
return IMAGE_EXTENSIONS.has(value); | ||
}, | ||
defaultMessage(validationArguments?: ValidationArguments): string { | ||
return `${validationArguments.value} 는 이미지 확장자가 아닙니다.`; | ||
}, | ||
}, | ||
}); | ||
}; | ||
} |