-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 멤버, 학습로그 이미지 presigned URL 발급 및 컨펌 기능 구현 (#76) #78
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
Merged
Changes from all commits
Commits
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
15 changes: 0 additions & 15 deletions
15
src/main/java/com/ject/studytrip/global/resolver/CdnUrlBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
src/main/java/com/ject/studytrip/image/domain/util/ImageUrlUtil.java
This file contains hidden or 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,67 @@ | ||
| package com.ject.studytrip.image.domain.util; | ||
|
|
||
| import static org.springframework.util.StringUtils.hasText; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.Optional; | ||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public final class ImageUrlUtil { | ||
| // 이미지 최종 경로 생성 | ||
| public static String build(String baseUrl, String key) { | ||
| if (!hasText(baseUrl) || !hasText(key)) { | ||
| return null; | ||
| } | ||
|
|
||
| String normalizedDomain = | ||
| baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl; | ||
|
|
||
| return normalizedDomain + "/" + key.trim(); | ||
| } | ||
|
|
||
| // 이미지 최종 경로에서 이미지 키 추출 | ||
| public static Optional<String> extractKey(String baseUrl, String url) { | ||
| if (url == null || url.isBlank()) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| if (baseUrl == null || baseUrl.isBlank()) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| // URI 파싱 | ||
| URI uri; | ||
| try { | ||
| uri = URI.create(url); | ||
| } catch (IllegalArgumentException e) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| String host = uri.getHost(); | ||
| if (host == null || !host.equals(extractHostName(baseUrl))) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| String path = uri.getPath(); | ||
| if (path == null || path.length() <= 1) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| // 맨 앞의 '/' 제거 | ||
| String key = path.startsWith("/") ? path.substring(1) : path; | ||
| return key.isBlank() ? Optional.empty() : Optional.of(key); | ||
| } | ||
|
|
||
| // 경로에서 Host 추출 | ||
| private static String extractHostName(String baseUrl) { | ||
| if (baseUrl.startsWith("https://")) { | ||
| return baseUrl.substring(8).replaceAll("/$", ""); | ||
| } | ||
| if (baseUrl.startsWith("http://")) { | ||
| return baseUrl.substring(7).replaceAll("/$", ""); | ||
| } | ||
| return baseUrl.replaceAll("/$", ""); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/ject/studytrip/member/application/dto/PresignedProfileImageInfo.java
This file contains hidden or 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 @@ | ||
| package com.ject.studytrip.member.application.dto; | ||
|
|
||
| public record PresignedProfileImageInfo(Long memberId, String tmpKey, String presignedUrl) { | ||
| public static PresignedProfileImageInfo of(Long memberId, String tmpKey, String presignedUrl) { | ||
| return new PresignedProfileImageInfo(memberId, tmpKey, presignedUrl); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
...n/java/com/ject/studytrip/member/presentation/dto/request/ConfirmProfileImageRequest.java
This file contains hidden or 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 @@ | ||
| package com.ject.studytrip.member.presentation.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
|
|
||
| public record ConfirmProfileImageRequest( | ||
| @Schema(description = "업로드된 이미지 임시키") @NotEmpty(message = "업로드된 이미지 임시키는 필수 요청 값입니다.") | ||
| String tmpKey) {} |
8 changes: 8 additions & 0 deletions
8
...n/java/com/ject/studytrip/member/presentation/dto/request/PresignProfileImageRequest.java
This file contains hidden or 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 @@ | ||
| package com.ject.studytrip.member.presentation.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
|
|
||
| public record PresignProfileImageRequest( | ||
| @Schema(description = "업로드할 원본 이미지 파일명") @NotEmpty(message = "원본 이미지 파일명은 필수 요청 값입니다.") | ||
| String originFilename) {} |
13 changes: 13 additions & 0 deletions
13
...java/com/ject/studytrip/member/presentation/dto/response/PresignProfileImageResponse.java
This file contains hidden or 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 @@ | ||
| package com.ject.studytrip.member.presentation.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record PresignProfileImageResponse( | ||
| @Schema(description = "멤버 ID") Long memberId, | ||
| @Schema(description = "멤버 프로필 이미지 임시키") String tmpKey, | ||
| @Schema(description = "멤버 프로필 이미지 업로드용 Presigned URL") String presignedUrl) { | ||
| public static PresignProfileImageResponse of( | ||
| Long memberId, String tmpKey, String presignedUrl) { | ||
| return new PresignProfileImageResponse(memberId, tmpKey, presignedUrl); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ject/studytrip/studylog/application/dto/PresignedStudyLogImageInfo.java
This file contains hidden or 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 @@ | ||
| package com.ject.studytrip.studylog.application.dto; | ||
|
|
||
| public record PresignedStudyLogImageInfo(Long studyLogId, String tmpKey, String presignedUrl) { | ||
| public static PresignedStudyLogImageInfo of( | ||
| Long studyLogId, String tmpKey, String presignedUrl) { | ||
| return new PresignedStudyLogImageInfo(studyLogId, tmpKey, presignedUrl); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.