Skip to content
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

feat: s3 버킷 endpoint CloudFront 도메인으로 변경 및 profile별 동적 폴더 구조 되도록 구성 (#34) #57

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
pparkjs marked this conversation as resolved.
Show resolved Hide resolved
return cursorId == null ? null : lists.id.lt(cursorId);
}

Expand Down
Loading