-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 유저 정보 설정시 이미지 S3에 저장 - auth.module에 jpg, jpeg, png 파일 필터링, 파일 크기 제한 10MB - auth.module에 uuid를 통해 unique한 이미지로 저장되도록 설정 - auth.controller에 UseInterceptors(FileInterceptor)를 통해 Multer가 사용되도록 설정 - auth.controller에 UploadedFile 데코레이터를 통해 저장된 파일에 대한 정보를 불러옴 - auth.controller에 ApiConsumes를 통해 api문서에서 multipart/form-data라는걸 명시 * refactor: multer모듈 config 환경변수화 * feat: get info controller 작성 * fix: auth/info controller에서 반환 결과 수정
- Loading branch information
1 parent
54ec603
commit dee6cce
Showing
11 changed files
with
2,015 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,8 @@ | ||
export enum ENV { | ||
IMAGE_ENDPOINT = 'IMAGE_ENDPOINT', | ||
IMAGE_ACCESSKEY = 'IMAGE_ACCESSKEY', | ||
IMAGE_SECRETKEY = 'IMAGE_SECRETKEY', | ||
IMAGE_REGION = 'IMAGE_REGION', | ||
IMAGE_BUCKET = 'IMAGE_BUCKET', | ||
CDN_ENDPOINT = 'CDN_ENDPOINT', | ||
} |
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,37 @@ | ||
import * as path from 'path'; | ||
import * as multerS3 from 'multer-s3'; | ||
import { S3Client } from '@aws-sdk/client-s3'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface'; | ||
import { ENV } from './const/env-keys.const'; | ||
|
||
export const multerConfig = (configService: ConfigService): MulterOptions => ({ | ||
fileFilter: (req, file, callback) => { | ||
const ext = path.extname(file.originalname); | ||
if (ext !== '.jpg' && ext !== '.jpeg' && ext !== '.png') { | ||
return callback( | ||
new BadRequestException('jpg/jpeg/png 파일만 업로드 가능합니다!'), | ||
false, | ||
); | ||
} | ||
return callback(null, true); | ||
}, | ||
limits: { fileSize: 1024 * 1024 * 10 }, //10MB | ||
storage: multerS3({ | ||
s3: new S3Client({ | ||
endpoint: configService.get(ENV.IMAGE_ENDPOINT), | ||
credentials: { | ||
accessKeyId: configService.get(ENV.IMAGE_ACCESSKEY), | ||
secretAccessKey: configService.get(ENV.IMAGE_SECRETKEY), | ||
}, | ||
region: configService.get(ENV.IMAGE_REGION), | ||
}), | ||
bucket: configService.get(ENV.IMAGE_BUCKET), | ||
key: function (req, file, callback) { | ||
const fileExtension = path.extname(file.originalname); | ||
callback(null, `IMG_${uuid()}${fileExtension}`); | ||
}, | ||
}), | ||
}); |
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 |
---|---|---|
|
@@ -2,29 +2,20 @@ import { PickType } from '@nestjs/mapped-types'; | |
import { UsersModel } from '../entity/users.entity'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class CreateUserDto extends PickType(UsersModel, [ | ||
'nickname', | ||
'email', | ||
'image_url', | ||
]) { | ||
export class CreateUserDto extends PickType(UsersModel, ['nickname', 'email']) { | ||
@ApiProperty({ | ||
type: 'string', | ||
example: '어린콩', | ||
description: '닉네임', | ||
required: false, | ||
}) | ||
nickname: string; | ||
|
||
@ApiProperty({ | ||
type: 'string', | ||
example: 'https://sldkjfds/dsflkdsjf.png', | ||
description: '이미지 링크', | ||
}) | ||
image_url: string; | ||
|
||
@ApiProperty({ | ||
type: 'string', | ||
example: '[email protected]', | ||
description: '이메일', | ||
required: true, | ||
}) | ||
email: string; | ||
} |
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
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