-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 사진 다운로드 로직 구현 및 CDN 설정 #53
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f404797
#45 chore: 브랜치 변경을 위한 임시 커밋
zyovn ac2f10c
#45 feat: 다운로드용 presignedUrl 발급 API
zyovn 7e0b5b0
#45 feat: 사진 목록 조회 및 내가 띱한 사진 조회 썸네일 이미지 cdn 로직으로 수정
zyovn 554ddb5
#45 feat: 사진 상세 조회 원본, 썸네일 이미지 cdn으로 수장
zyovn 417a4d4
#45 feat: 다운로드 response fileName 추출 로직 추가
zyovn 57c0971
#45 feat: 1시간 이내 다운로드 이력 존재 시, 다운로드 방지 로직 추가
zyovn 461a791
#45 feat: validateDownload 수정
zyovn 5864974
#45 docs: swagger 작성
zyovn 88096be
#45 fix: 피드백 반영
zyovn 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.cheeeese.global.util; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| public class S3Util { | ||
|
|
||
| public static String extractObjectKey(String imageUrl) { | ||
| if (imageUrl == null) { | ||
| throw new NullPointerException("image url is null"); | ||
| } | ||
|
|
||
| try { | ||
| URI uri = new URI(imageUrl); | ||
| String path = uri.getPath(); | ||
| if (path != null && !path.isBlank()) { | ||
| return path.startsWith("/") ? path.substring(1) : path; | ||
| } | ||
| } catch (URISyntaxException e) { | ||
|
|
||
| } | ||
| if (imageUrl.startsWith("album/")) { | ||
| return imageUrl; | ||
| } | ||
| return imageUrl; | ||
| } | ||
|
|
||
| public static String extractFileName(String imageUrl) { | ||
| if (imageUrl == null || imageUrl.isBlank()) { | ||
| return "unnamed.jpg"; | ||
| } | ||
| String normalized = imageUrl.replace('\\', '/'); | ||
|
|
||
| int lastSlashIdx = normalized.lastIndexOf('/'); | ||
| String fileName = (lastSlashIdx >= 0) | ||
| ? normalized.substring(lastSlashIdx + 1) | ||
| : normalized; | ||
|
|
||
| int underscoreIdx = fileName.indexOf('_'); | ||
| if (underscoreIdx >= 0 && underscoreIdx < fileName.length() - 1) { | ||
| fileName = fileName.substring(underscoreIdx + 1); | ||
| } | ||
|
|
||
| return fileName; | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/cheeeese/global/util/resolver/CdnUrlResolver.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,36 @@ | ||
| package com.cheeeese.global.util.resolver; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class CdnUrlResolver { | ||
|
|
||
| @Value("${cdn.original-domain}") | ||
| private String originalDomain; | ||
|
|
||
| @Value("${cdn.thumbnail-domain}") | ||
| private String thumbnailDomain; | ||
|
|
||
| @Value("${cdn.4cut-domain}") | ||
| private String cutDomain; | ||
|
|
||
| public String resolveOriginal(String path) { | ||
| return resolve(originalDomain, path); | ||
| } | ||
|
|
||
| public String resolveThumbnail(String path) { | ||
| return resolve(thumbnailDomain, path); | ||
| } | ||
|
|
||
| public String resolveCut(String path) { | ||
| return resolve(cutDomain, path); | ||
| } | ||
|
|
||
| private String resolve(String domain, String path) { | ||
| if (path == null || path.isBlank()) return null; | ||
| if (path.startsWith("http")) return path; | ||
| if (path.startsWith("/")) path = path.substring(1); | ||
| return domain + "/" + path; | ||
| } | ||
| } |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/cheeeese/photo/dto/request/PhotoDownloadRequest.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,17 @@ | ||
| package com.cheeeese.photo.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| @Schema(description = "사진 다운로드 presigned url 발급 API") | ||
| public record PhotoDownloadRequest( | ||
| @Schema(description = "앨범 코드", example = "1f0b7ea8-fab6-6581-95e3-0720bc07603e") | ||
| String code, | ||
|
|
||
| @Schema(description = "사진 고유 ID", example = "[1, 2, 3]") | ||
| List<Long> photoIds | ||
| ) { | ||
| } |
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.