Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/test-server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
AWS_S3_PREFIX: test/
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
JWT_ACCESS_TOKEN_VALIDITY: ${{ secrets.JWT_ACCESS_TOKEN_VALIDITY }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import jakarta.persistence.NoResultException;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.tuna.zoopzoop.backend.domain.datasource.repository.DataSourceRepository;
import org.tuna.zoopzoop.backend.domain.datasource.repository.TagRepository;
Expand All @@ -18,6 +21,7 @@
import org.tuna.zoopzoop.backend.global.aws.S3Service;
import org.tuna.zoopzoop.backend.global.clients.liveblocks.LiveblocksClient;

@Slf4j
@Service
@RequiredArgsConstructor
public class SpaceService {
Expand All @@ -28,6 +32,9 @@ public class SpaceService {
private final TagRepository tagRepository;
private final DataSourceRepository dataSourceRepository;

@Value("${spring.cloud.aws.s3.prefix}")
private String s3Prefix;

// ======================== 스페이스 조회 ======================== //

/**
Expand Down Expand Up @@ -174,9 +181,10 @@ public void updateSpaceThumbnail(Integer spaceId, Member requester, MultipartFil
}

try {
//String fileName = "space/" + spaceId + "/thumbnail/" + System.currentTimeMillis() + "_" +
//String fileName = "space-thumbnail/prefix/space_id.jpg";
// S3 저장 시 파일 이름 고정 (덮어쓰기)
String fileName = "space-thumbnail/space_" + spaceId ;
String extension = StringUtils.getFilenameExtension(image.getOriginalFilename());
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null pointer exception if image.getOriginalFilename() returns null or if StringUtils.getFilenameExtension() returns null. Consider adding null checks or providing a default extension.

Suggested change
String extension = StringUtils.getFilenameExtension(image.getOriginalFilename());
String extension = StringUtils.getFilenameExtension(image.getOriginalFilename());
if (extension == null || extension.isEmpty()) {
extension = "jpg"; // default extension
}

Copilot uses AI. Check for mistakes.
String fileName = "space-thumbnail/" + s3Prefix + "/space_" + spaceId + "." + extension;
String baseImageUrl = s3Service.upload(image, fileName);

// DB 용으로 현재 시간을 쿼리 파라미터에 추가 (캐시 무효화)
Expand All @@ -186,6 +194,7 @@ public void updateSpaceThumbnail(Integer spaceId, Member requester, MultipartFil
space.setThumbnailUrl(finalImageUrl);
spaceRepository.save(space);
} catch (Exception e) {
log.error("Space thumbnail upload failed: ", e);
throw new RuntimeException("스페이스 썸네일 이미지 업로드에 실패했습니다.");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ spring:
static: ap-northeast-2
s3:
bucket: ${AWS_S3_BUCKET_NAME}
prefix: ${AWS_S3_PREFIX}
stack:
auto: false


#Spring doc 설정
springdoc:
default-produces-media-type: application/json;charset=UTF-8
Expand Down