Skip to content

Commit

Permalink
feat: s3 버킷 endpoint CloudFront 도메인으로 변경 및 profile별 동적 폴더 구조 되도록 구성 (#34
Browse files Browse the repository at this point in the history
) (#57)

* feature:  s3 버킷 endpoint CloudFront 도메인으로 변경, profile dev or local 폴더로 동적 정하도록 구현 (#34)

* refactor: 도메인 URL과 프로필 관련 한수 ImageService로 이동 (#34)
  • Loading branch information
pparkjs authored Feb 5, 2024
1 parent baf3523 commit 01c6cb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

@Getter
@AllArgsConstructor
public enum UrlConstants {
public enum EnvironmentConstants {

IMAGE_DOMAIN_URL("https://image.listy-wave.today"),
LOCAL("local"),
DEV("dev"),
;

private String value;
private final String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import com.listywave.list.repository.ItemRepository;
import com.listywave.list.repository.ListRepository;
import com.listywave.user.application.domain.User;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -30,11 +32,13 @@
@RequiredArgsConstructor
public class ImageService {

private static final String IMAGE_DOMAIN_URL = "https://image.listywave.com";
private static final String LOCAL = "local";
private static final String DEV = "dev";

@Value("${cloud.s3.bucket}")
private String bucket;
//TODO: endPoint는 cloudFron 적용하면 지우기
@Value("${cloud.s3.endpoint}")
private String endPoint;
private final Environment environment;
private final AmazonS3 amazonS3;
private final UserUtil userUtil;
private final ItemRepository itemRepository;
Expand Down Expand Up @@ -93,7 +97,6 @@ public void uploadCompleteItemImages(Long ownerId, Long listId, List<ExtensionRa
item.updateItemImageUrl(imageUrl);
}
);

}

private String createReadImageUrl(
Expand All @@ -102,10 +105,9 @@ private String createReadImageUrl(
String imageKey,
ImageFileExtension imageFileExtension
) {
//TODO: CloudFront 적용되면 endpoint를 UrlConstants.IMAGE_DOMAIN_URL.getValue()로 교체;
return endPoint
return IMAGE_DOMAIN_URL
+ "/"
+ "local"
+ getCurrentProfile()
+ "/"
+ imageType.getValue()
+ "/"
Expand All @@ -122,8 +124,7 @@ private String createFileName(
String imageKey,
ImageFileExtension imageFileExtension
) {
//TODO: 맨앞에 prefix는 현제 작업 환경의 profile 이름 가져오는 Util 별도 제작
return "local"
return getCurrentProfile()
+ "/"
+ imageType.getValue()
+ "/"
Expand Down Expand Up @@ -183,4 +184,15 @@ private Lists findListById(Long listId) {
.findById(listId)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND, "존재하지 않는 리스트입니다."));
}

public String getCurrentProfile() {
return Arrays.stream(environment.getActiveProfiles())
.filter(this::isActivateDev)
.findFirst()
.orElse(LOCAL);
}

private boolean isActivateDev(String profile) {
return profile.equals(DEV);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<Lists> findFeedLists(Long userId, String type, CategoryType category
userIdEq(userId),
typeEq(type),
categoryEq(category),
listIdGt(cursorId)
listIdLt(cursorId)
)
.distinct()
.limit(size + 1)
Expand All @@ -35,7 +35,7 @@ public List<Lists> findFeedLists(Long userId, String type, CategoryType category
return fetch;
}

private BooleanExpression listIdGt(Long cursorId) {
private BooleanExpression listIdLt(Long cursorId) {
return cursorId == null ? null : lists.id.lt(cursorId);
}

Expand Down

0 comments on commit 01c6cb0

Please sign in to comment.