-
Notifications
You must be signed in to change notification settings - Fork 1
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
presigned url 적용 #147
Merged
Merged
presigned url 적용 #147
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
51797dd
feat : Object Storage의 Presigned URL 생성
5tarry 9a5204c
feat : 광고 이미지 presigned url 반환
5tarry 6e5ca6d
feat : 프로필 이미지 presigned url 반환
5tarry 40f452f
refactor : 프로필 이미지 파일을 url로 변경
5tarry 3931c77
refactor : 랜덤 비디오 응답, 썸네일 클릭 시 비디오 정보 반환 api 썸네일, 프로필 이미지 url로 수정
5tarry bd1aa22
refactor : 회원가입 api 이미지 파일 업로드 부분 제거
5tarry 7beca20
feat : 비디오, 썸네일 이미지 업로드 하는 presigned url 반환
5tarry a574d7a
refactor : 비디오 업로드 api 파일 부분 제거, 비디오ID uuid->objectId로 변경
5tarry fe98104
refactor : Swagger 태그 변경
5tarry 78e6f58
refactor : 프로필 변경 api에서 이미지 파일 부분 제거
5tarry 1d1c5f1
feat : 만료된 get presigned url 재발급 API
5tarry 8d5cba1
chore : presigned url 모듈 분리
5tarry c09bf4b
feat : presigned url 응답 명세
5tarry 722fa6b
refactor : 함수 반환 수정
5tarry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,32 @@ | ||
import { HttpRequest } from '@smithy/protocol-http'; | ||
import { S3RequestPresigner } from '@aws-sdk/s3-request-presigner'; | ||
import { parseUrl } from '@smithy/url-parser'; | ||
import { formatUrl } from '@aws-sdk/util-format-url'; | ||
import { Hash } from '@smithy/hash-node'; | ||
|
||
export const createPresignedUrl = async ( | ||
bucketName: string, | ||
objectName: string, | ||
method: string, | ||
) => { | ||
const region = 'kr-standard'; | ||
const endPoint = 'https://kr.object.ncloudstorage.com'; | ||
const canonicalURI = `/${bucketName}/${objectName}`; | ||
const apiUrl = `${endPoint}${canonicalURI}`; | ||
const url = parseUrl(apiUrl); | ||
|
||
const presigner = new S3RequestPresigner({ | ||
credentials: { | ||
accessKeyId: process.env.ACCESS_KEY, | ||
secretAccessKey: process.env.SECRET_KEY, | ||
}, | ||
region, | ||
sha256: Hash.bind(null, 'sha256'), | ||
}); | ||
|
||
const signedUrlObject = await presigner.presign( | ||
new HttpRequest({ ...url, method }), | ||
{ expiresIn: 100 }, | ||
); | ||
return formatUrl(signedUrlObject); | ||
}; |
7 changes: 7 additions & 0 deletions
7
server/src/presigned-url/dto/advertisement-presigned-url-request.dto.ts
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,7 @@ | ||
export class AdvertisementPresignedUrlRequestDto { | ||
/** | ||
* 특정 광고 이미지의 presigned url만 받고 싶은 경우 | ||
* @example 'test.webp' | ||
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
*/ | ||
name?: string; | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/presigned-url/dto/advertisement-presigned-url-response.dto.ts
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,21 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
class PresignedUrlDto { | ||
/** | ||
* 파일 이름 | ||
* @example 'test.webp' | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* 파일을 가져올 수 있는 presigned url | ||
* @example "https://kr.object.ncloudstorage.com/" | ||
*/ | ||
url: string; | ||
} | ||
|
||
export class AdvertisementPresignedUrlResponseDto { | ||
@ApiProperty({ type: [PresignedUrlDto] }) | ||
advertisements: [PresignedUrlDto]; | ||
} |
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,7 @@ | ||
export class PresignedUrlResponseDto { | ||
/** | ||
* presigned url | ||
* @example 'https://kr.object.ncloudstorage.com/' | ||
*/ | ||
presignedUrl: string; | ||
} |
15 changes: 15 additions & 0 deletions
15
server/src/presigned-url/dto/profile-presigned-url-request.dto.ts
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,15 @@ | ||
import { IsUUID } from 'class-validator'; | ||
|
||
export class ProfilePresignedUrlRequestDto { | ||
/** | ||
* user uuid | ||
*/ | ||
@IsUUID() | ||
uuid: string; | ||
|
||
/** | ||
* 프로필 이미지 확장자 | ||
* @example 'webp' | ||
*/ | ||
profileExtension: string; | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/presigned-url/dto/reissue-presigned-url-request.dto.ts
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,21 @@ | ||
import { IsEnum } from 'class-validator'; | ||
|
||
enum TypeEnum { | ||
thumbnail = 'thumbnail', | ||
profile = 'profile', | ||
} | ||
|
||
export class ReissuePresignedUrlRequestDto { | ||
/** | ||
* 요청하는 이미지 종류 | ||
* @example 'thumbnail' | ||
*/ | ||
@IsEnum(TypeEnum) | ||
type: TypeEnum; | ||
|
||
/** | ||
* 이미지 확장자 | ||
* @example 'webp' | ||
*/ | ||
extension: string; | ||
} |
13 changes: 13 additions & 0 deletions
13
server/src/presigned-url/dto/video-presigned-url-request.dto.ts
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,13 @@ | ||
export class VIdeoPresignedUrlRequestDto { | ||
/** | ||
* 비디오 확장자 | ||
* @example 'mp4' | ||
*/ | ||
videoExtension: string; | ||
|
||
/** | ||
* 썸네일 이미지 확장자 | ||
* @example 'webp' | ||
*/ | ||
thumbnailExtension: string; | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/presigned-url/dto/video-presigned-url-response.dto.ts
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,21 @@ | ||
import { Types } from 'mongoose'; | ||
|
||
export class VideoPresignedUrlResponseDto { | ||
/** | ||
* 비디오 ID | ||
* @example '6567eb9aa1efacad06e24b81' | ||
*/ | ||
videoId: Types.ObjectId; | ||
|
||
/** | ||
* 비디오 업로드 presigned url | ||
* @example 'https://kr.object.ncloudstorage.com' | ||
*/ | ||
videoUrl: string; | ||
|
||
/** | ||
* 썸네일 업로드 presigned url | ||
* @example 'https://kr.object.ncloudstorage.com' | ||
*/ | ||
thumbnailUrl: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiParam, ApiTags } from '@nestjs/swagger'; | ||
import { ApiFailResponse } from 'src/decorators/api-fail-response'; | ||
import { AuthGuard } from 'src/auth/auth.guard'; | ||
import { InvalidTokenException } from 'src/exceptions/invalid-token.exception'; | ||
import { TokenExpiredException } from 'src/exceptions/token-expired.exception'; | ||
import { ApiSuccessResponse } from 'src/decorators/api-succes-response'; | ||
import { PresignedUrlService } from './presigned-url.service'; | ||
import { AdvertisementPresignedUrlRequestDto } from './dto/advertisement-presigned-url-request.dto'; | ||
import { ProfilePresignedUrlRequestDto } from './dto/profile-presigned-url-request.dto'; | ||
import { VIdeoPresignedUrlRequestDto } from './dto/video-presigned-url-request.dto'; | ||
import { ReissuePresignedUrlRequestDto } from './dto/reissue-presigned-url-request.dto'; | ||
import { AdvertisementPresignedUrlResponseDto } from './dto/advertisement-presigned-url-response.dto'; | ||
import { PresignedUrlResponseDto } from './dto/presigned-url-response.dto'; | ||
import { VideoPresignedUrlResponseDto } from './dto/video-presigned-url-response.dto'; | ||
|
||
@ApiTags('PRESIGNED URL') | ||
@ApiBearerAuth() | ||
@UseGuards(AuthGuard) | ||
@ApiFailResponse('인증 실패', [InvalidTokenException, TokenExpiredException]) | ||
@Controller('presigned-url') | ||
export class PresignedUrlController { | ||
constructor(private presignedUrlService: PresignedUrlService) {} | ||
|
||
/** | ||
* 광고 이미지를 GET하는 url 발급 | ||
*/ | ||
@Get('advertisements') | ||
@ApiSuccessResponse( | ||
200, | ||
'광고 이미지 가져오는 url 발급 성공', | ||
AdvertisementPresignedUrlResponseDto, | ||
) | ||
getAdvertisementPresignedUrl( | ||
@Query() query: AdvertisementPresignedUrlRequestDto, | ||
) { | ||
return this.presignedUrlService.getAdvertisementPresignedUrl(query.name); | ||
} | ||
|
||
/** | ||
* 프로필 이미지를 PUT하는 url 발급 | ||
*/ | ||
@Get('profile') | ||
@ApiSuccessResponse( | ||
200, | ||
'프로필 이미지를 업로드하는 url 발급 성공', | ||
PresignedUrlResponseDto, | ||
) | ||
putProfilePresignedUrl(@Query() query: ProfilePresignedUrlRequestDto) { | ||
return this.presignedUrlService.putProfilePresignedUrl(query); | ||
} | ||
|
||
/** | ||
* 비디오, 썸네일 이미지를 PUT하는 url 발급 | ||
*/ | ||
@Get('video') | ||
@ApiSuccessResponse( | ||
200, | ||
'비디오/썸네일을 업로드하는 url 발급 성공', | ||
VideoPresignedUrlResponseDto, | ||
) | ||
putVideoPresignedUrl(@Query() query: VIdeoPresignedUrlRequestDto) { | ||
return this.presignedUrlService.putVideoPresignedUrl(query); | ||
} | ||
|
||
/** | ||
* 만료된 presigned url 재발급 | ||
*/ | ||
@Get('reissue/:id') | ||
@ApiParam({ | ||
name: 'id', | ||
description: '썸네일 재발급 시 비디오ID, 프로필 재발급 시 유저 UUID', | ||
}) | ||
@ApiSuccessResponse(200, 'presigned url 재발급 성공', PresignedUrlResponseDto) | ||
getImagePresignedUrl( | ||
@Param('id') id: string, | ||
@Query() query: ReissuePresignedUrlRequestDto, | ||
) { | ||
return this.presignedUrlService.getImagePresignedUrl(id, query); | ||
} | ||
} |
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,4 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
@Module({}) | ||
export class PresignedUrlModule {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LEGACY 태그로 기존 코드 구분하신게 좋은거 같아요!