Skip to content

Commit 61f1519

Browse files
update
2 parents 9918892 + c22ddca commit 61f1519

File tree

6 files changed

+205
-126
lines changed

6 files changed

+205
-126
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ jobs:
6363
password: ${{ secrets.DOCKERHUB_TOKEN }}
6464

6565
- name: Build against builder
66-
uses: docker/build-push-action@v3
66+
uses: docker/build-push-action@v4
6767
with:
6868
builder: ${{ steps.builder.outputs.name }}
6969
file: ${{ env.DOCKERFILE }}
7070
target: builder
7171

7272
- name: Build against main and push
73-
uses: docker/build-push-action@v3
73+
uses: docker/build-push-action@v4
7474
with:
7575
builder: ${{ steps.main.outputs.name }}
7676
file: ${{ env.DOCKERFILE }}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ack-nestjs-boilerplate-kafka",
3-
"version": "3.3.5",
3+
"version": "3.3.6",
44
"description": "Ack NestJs Boilerplate Kafka",
55
"repository": {
66
"type": "git",
@@ -48,7 +48,7 @@
4848
"rollback": "yarn rollback:setting && yarn rollback:apikey"
4949
},
5050
"dependencies": {
51-
"@aws-sdk/client-s3": "^3.259.0",
51+
"@aws-sdk/client-s3": "^3.262.0",
5252
"@faker-js/faker": "^7.6.0",
5353
"@joi/date": "^2.1.0",
5454
"@nestjs/axios": "^1.0.1",
@@ -115,10 +115,10 @@
115115
"@types/supertest": "^2.0.12",
116116
"@types/ua-parser-js": "^0.7.36",
117117
"@types/uuid": "^9.0.0",
118-
"@typescript-eslint/eslint-plugin": "^5.49.0",
119-
"@typescript-eslint/parser": "^5.49.0",
118+
"@typescript-eslint/eslint-plugin": "^5.50.0",
119+
"@typescript-eslint/parser": "^5.50.0",
120120
"cspell": "^6.19.2",
121-
"eslint": "^8.32.0",
121+
"eslint": "^8.33.0",
122122
"eslint-config-prettier": "^8.6.0",
123123
"eslint-plugin-import": "^2.27.5",
124124
"husky": "^8.0.3",
@@ -130,6 +130,6 @@
130130
"ts-node": "^10.9.1",
131131
"ts-prune": "^0.10.3",
132132
"tsconfig-paths": "^4.1.2",
133-
"typescript": "^4.9.4"
133+
"typescript": "^4.9.5"
134134
}
135135
}

src/common/file/constants/file.enum.constant.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ export enum ENUM_FILE_VIDEO_MIME {
2020
MP4 = 'video/mp4',
2121
APPLICATION_MP4 = 'application/mp4',
2222
}
23+
24+
export enum ENUM_FILE_TYPE {
25+
AUDIO = 'audio',
26+
IMAGE = 'image',
27+
EXCEL = 'excel',
28+
VIDEO = 'video',
29+
}

src/common/request/request.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { MinGreaterThanConstraint } from './validations/request.min-greater-than
2323
import { IsOnlyDigitsConstraint } from './validations/request.only-digits.validation';
2424
import { SafeStringConstraint } from './validations/request.safe-string.validation';
2525
import { SkipConstraint } from './validations/request.skip.validation';
26+
import { MaxBinaryFileConstraint } from 'src/common/request/validations/request.max-binary-file.validation';
2627

2728
@Module({
2829
controllers: [],
@@ -64,6 +65,7 @@ import { SkipConstraint } from './validations/request.skip.validation';
6465
MinDateTodayConstraint,
6566
MobileNumberAllowedConstraint,
6667
MaxDateTodayConstraint,
68+
MaxBinaryFileConstraint,
6769
],
6870
imports: [RequestMiddlewareModule],
6971
})
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
import {
4+
registerDecorator,
5+
ValidationArguments,
6+
ValidationOptions,
7+
ValidatorConstraint,
8+
ValidatorConstraintInterface,
9+
} from 'class-validator';
10+
import { ENUM_FILE_TYPE } from 'src/common/file/constants/file.enum.constant';
11+
12+
@ValidatorConstraint({ async: true })
13+
@Injectable()
14+
export class MaxBinaryFileConstraint implements ValidatorConstraintInterface {
15+
constructor(private readonly configService: ConfigService) {}
16+
17+
validate(value: string, args: ValidationArguments): boolean {
18+
const [type] = args.constraints;
19+
let fileSize = 0;
20+
21+
switch (type) {
22+
case ENUM_FILE_TYPE.AUDIO:
23+
fileSize = this.configService.get<number>(
24+
'file.audio.maxFileSize'
25+
);
26+
break;
27+
case ENUM_FILE_TYPE.EXCEL:
28+
fileSize = this.configService.get<number>(
29+
'file.excel.maxFileSize'
30+
);
31+
break;
32+
case ENUM_FILE_TYPE.IMAGE:
33+
fileSize = this.configService.get<number>(
34+
'file.image.maxFileSize'
35+
);
36+
break;
37+
case ENUM_FILE_TYPE.VIDEO:
38+
fileSize = this.configService.get<number>(
39+
'file.video.maxFileSize'
40+
);
41+
break;
42+
default:
43+
break;
44+
}
45+
46+
return fileSize <= value.length;
47+
}
48+
}
49+
50+
export function MaxBinaryFile(
51+
type: ENUM_FILE_TYPE,
52+
validationOptions?: ValidationOptions
53+
) {
54+
return function (object: Record<string, any>, propertyName: string): any {
55+
registerDecorator({
56+
name: 'MaxBinaryFile',
57+
target: object.constructor,
58+
propertyName: propertyName,
59+
options: validationOptions,
60+
constraints: [type],
61+
validator: MaxBinaryFileConstraint,
62+
});
63+
};
64+
}

0 commit comments

Comments
 (0)