-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: ThumbnailManager 인터페이스화 * chore: s3 업로드 프록시 서버 프로젝트 생성 * chore: RestAssured 의존성 추가 * chore: 저장소 설정값을 저장할 서브모듈 추가 * chore: 기본 프로파일 설정값 세팅 * feat: 업로드 기능 구현 * feat: 예외 핸들링 로직 작성 * test: Service 통합테스트, S3Uploader 단위 테스트 작성 * refactor: RequestMapping -> PostMapping 어노테이션으로 대체 * fix: StorageConfig의 local, test 설정 오류 수정 * feat: 삭제 기능 구현 * test: 삭제 관련 Service 및 단위 테스트 구현 * refactor: 예외의 로깅 레벨을 warn을 기본값으로 설정 * feat: logback 로깅 설정 * fix: 응답 헤더의 url이 잘못된 문제 해결 * chore: cloud.aws.stack.auto=false 부여 * chore: 배포 쉘스크립트 작성 * feat: S3Proxy를 이용해 파일 업로드하도록 변경 * refactor: Amazon Cloud 관련 의존성 및 객체 삭제 * refactor: S3ProxyUploader 예외 구체화 * fix: 스크립트 수정 * chore: gradle 버전 다운그레이드 * chore: API 문서화 * test: S3Proxy 단위 테스트 작성 * docs: API 문서 구체화 * refactor: API 문서 내용 일관화 * docs: API 문서 제목 설정 * test: 테스트에 사용할 샘플 png 파일 업로드 * fix: thumbnails 디렉토리명 수정 * test: S3Proxy 예외 케이스 추가 * chore: 주석처리한 의존성 삭제 * chore: 서브모듈 최신화 * refactor: 빈 생성자 파라미터에 final 속성 부여 * refactor: 예외 미발생 테스트코드들 assertDoesNotThrow() 이용 * refactor: S3Uploader MultiPartFile의 InputStream close() 메소드 호출 * fix: 병합으로 인한 컴파일 에러 해결 * style: S3ProxyUploader 상수 오타 수정 Co-authored-by: Jungseok Sung <[email protected]> * fix: S3ProxyUploader 상수 오타 수정으로 인한 컴파일 오류 해결 * refactor: 썸네일 업로드할 디렉토리 네임을 config를 통해 받음 dev 서버의 이미지 유실을 방지합니다. * chore: 서브모듈에 s3proxy 관련 설정 업로드 * chore: local, test 프로파일일 때 올라가는 썸네일 디렉토리명 변경 * refactor: ThumbnailManagerImpl 패키지 위치 이동 * refactor: 썸네일을 위해 변환된 파일 삭제 불가시 예외 발생 * refactor: S3ProxyUploader 패키지 변경 * refactor: S3ProxyUploaderTest 패키지 경로 이동 * test: ThumbnailManagerImpl에 대한 테스트 코드 작성 Co-authored-by: Jungseok Sung <[email protected]>
- Loading branch information
1 parent
7ca0aca
commit c5b1ae3
Showing
60 changed files
with
1,620 additions
and
230 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.idea | ||
.DS_Store | ||
|
||
|
||
s3proxy/src/main/resources/static/docs/index.html |
This file contains 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 |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
path = backend/src/main/resources/config | ||
url = [email protected]:zzimkkong/config.git | ||
branch = main | ||
[submodule "s3proxy/src/main/resources/s3proxy-config"] | ||
path = s3proxy/src/main/resources/s3proxy-config | ||
url = [email protected]:zzimkkong/s3proxy-config.git | ||
branch = main |
This file contains 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
39 changes: 0 additions & 39 deletions
39
backend/src/main/java/com/woowacourse/zzimkkong/config/StorageConfig.java
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
backend/src/main/java/com/woowacourse/zzimkkong/config/WebConfig.java
This file contains 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
11 changes: 11 additions & 0 deletions
11
...om/woowacourse/zzimkkong/exception/infrastructure/CannotDeleteConvertedFileException.java
This file contains 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,11 @@ | ||
package com.woowacourse.zzimkkong.exception.infrastructure; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class CannotDeleteConvertedFileException extends InfrastructureMalfunctionException { | ||
private static final String MESSAGE = "변환된 이미지를 삭제하는 데에 실패했습니다. 관리자에게 문의하세요."; | ||
|
||
public CannotDeleteConvertedFileException() { | ||
super(MESSAGE, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ava/com/woowacourse/zzimkkong/exception/infrastructure/S3ProxyRespondedFailException.java
This file contains 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,11 @@ | ||
package com.woowacourse.zzimkkong.exception.infrastructure; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class S3ProxyRespondedFailException extends InfrastructureMalfunctionException { | ||
private static final String MESSAGE = "이미지 버킷 업로드에 실패했습니다."; | ||
|
||
public S3ProxyRespondedFailException() { | ||
super(MESSAGE, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
This file contains 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
78 changes: 78 additions & 0 deletions
78
...end/src/main/java/com/woowacourse/zzimkkong/infrastructure/thumbnail/S3ProxyUploader.java
This file contains 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,78 @@ | ||
package com.woowacourse.zzimkkong.infrastructure.thumbnail; | ||
|
||
import com.woowacourse.zzimkkong.exception.infrastructure.S3ProxyRespondedFailException; | ||
import com.woowacourse.zzimkkong.exception.infrastructure.S3UploadException; | ||
import com.woowacourse.zzimkkong.infrastructure.thumbnail.StorageUploader; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.ByteArrayResource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.MultipartBodyBuilder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Objects; | ||
|
||
@Component | ||
public class S3ProxyUploader implements StorageUploader { | ||
private static final String PATH_DELIMITER = "/"; | ||
private static final String API_PATH = "/api/storage"; | ||
private static final String CONTENT_DISPOSITION_HEADER_VALUE_FORMAT = "form-data; name=file; filename=%s"; | ||
|
||
private final WebClient proxyServerClient; | ||
|
||
public S3ProxyUploader( | ||
@Value("${s3proxy.server-uri}") final String serverUri) { | ||
this.proxyServerClient = WebClient.builder() | ||
.baseUrl(serverUri) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public String upload(String directoryName, File uploadFile) { | ||
try { | ||
byte[] byteArrayOfFile = Files.readAllBytes(uploadFile.toPath()); | ||
|
||
MultipartBodyBuilder multipartBodyBuilder = new MultipartBodyBuilder(); | ||
multipartBodyBuilder.part("file", new ByteArrayResource(byteArrayOfFile)) | ||
.header(HttpHeaders.CONTENT_DISPOSITION, | ||
String.format(CONTENT_DISPOSITION_HEADER_VALUE_FORMAT, uploadFile.getName())); | ||
|
||
return proxyServerClient | ||
.method(HttpMethod.POST) | ||
.uri(String.join(PATH_DELIMITER, API_PATH, directoryName)) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) | ||
.body(BodyInserters.fromMultipartData(multipartBodyBuilder.build())) | ||
.exchangeToMono(clientResponse -> { | ||
if (clientResponse.statusCode().equals(HttpStatus.CREATED)) { | ||
String location = Objects.requireNonNull( | ||
clientResponse.headers().asHttpHeaders().get(HttpHeaders.LOCATION)) | ||
.stream().findFirst() | ||
.orElseThrow(S3UploadException::new); | ||
return Mono.just(location); | ||
} | ||
return Mono.error(S3ProxyRespondedFailException::new); | ||
}) | ||
.block(); | ||
} catch (IOException exception) { | ||
throw new S3UploadException(exception); | ||
} | ||
} | ||
|
||
@Override | ||
public void delete(String directoryName, String fileName) { | ||
proxyServerClient | ||
.method(HttpMethod.DELETE) | ||
.uri(String.join(PATH_DELIMITER, API_PATH, directoryName, fileName)) | ||
.retrieve() | ||
.bodyToMono(String.class) | ||
.block(); | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
backend/src/main/java/com/woowacourse/zzimkkong/infrastructure/thumbnail/S3Uploader.java
This file was deleted.
Oops, something went wrong.
37 changes: 3 additions & 34 deletions
37
...nd/src/main/java/com/woowacourse/zzimkkong/infrastructure/thumbnail/ThumbnailManager.java
This file contains 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 |
---|---|---|
@@ -1,40 +1,9 @@ | ||
package com.woowacourse.zzimkkong.infrastructure.thumbnail; | ||
|
||
import com.woowacourse.zzimkkong.domain.Map; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
public interface ThumbnailManager { | ||
String uploadMapThumbnail(final String svgData, final Map map); | ||
|
||
@Component | ||
public class ThumbnailManager { | ||
public static final String THUMBNAILS_DIRECTORY_NAME = "thumbnails"; | ||
public static final String THUMBNAIL_EXTENSION = ".png"; | ||
private static final String THUMBNAIL_FILE_FORMAT = "%s"; | ||
|
||
private final SvgConverter svgConverter; | ||
private final StorageUploader storageUploader; | ||
|
||
public ThumbnailManager(final SvgConverter svgConverter, final StorageUploader storageUploader) { | ||
this.svgConverter = svgConverter; | ||
this.storageUploader = storageUploader; | ||
} | ||
|
||
public String uploadMapThumbnail(final String svgData, final Map map) { | ||
String fileName = makeThumbnailFileName(map); | ||
File pngFile = svgConverter.convertSvgToPngFile(svgData, fileName); | ||
|
||
String thumbnailUrl = storageUploader.upload(THUMBNAILS_DIRECTORY_NAME, pngFile); | ||
|
||
pngFile.delete(); | ||
return thumbnailUrl; | ||
} | ||
|
||
public void deleteThumbnail(final Map map) { | ||
String fileName = makeThumbnailFileName(map); | ||
storageUploader.delete(THUMBNAILS_DIRECTORY_NAME, fileName + THUMBNAIL_EXTENSION); | ||
} | ||
|
||
private String makeThumbnailFileName(final Map map) { | ||
return String.format(THUMBNAIL_FILE_FORMAT, map.getId().toString()); | ||
} | ||
void deleteThumbnail(final Map map); | ||
} |
49 changes: 49 additions & 0 deletions
49
...rc/main/java/com/woowacourse/zzimkkong/infrastructure/thumbnail/ThumbnailManagerImpl.java
This file contains 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,49 @@ | ||
package com.woowacourse.zzimkkong.infrastructure.thumbnail; | ||
|
||
import com.woowacourse.zzimkkong.domain.Map; | ||
import com.woowacourse.zzimkkong.exception.infrastructure.CannotDeleteConvertedFileException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
|
||
@Component | ||
public class ThumbnailManagerImpl implements ThumbnailManager { | ||
public static final String THUMBNAIL_EXTENSION = ".png"; | ||
private static final String THUMBNAIL_FILE_FORMAT = "%s"; | ||
|
||
private final SvgConverter svgConverter; | ||
private final StorageUploader storageUploader; | ||
private final String thumbnailsDirectoryName; | ||
|
||
public ThumbnailManagerImpl( | ||
final SvgConverter svgConverter, | ||
final StorageUploader storageUploader, | ||
@Value("${s3proxy.thumbnails-directory}") final String thumbnailsDirectoryName) { | ||
this.svgConverter = svgConverter; | ||
this.storageUploader = storageUploader; | ||
this.thumbnailsDirectoryName = thumbnailsDirectoryName; | ||
|
||
} | ||
|
||
public String uploadMapThumbnail(final String svgData, final Map map) { | ||
String fileName = makeThumbnailFileName(map); | ||
File pngFile = svgConverter.convertSvgToPngFile(svgData, fileName); | ||
|
||
String thumbnailUrl = storageUploader.upload(thumbnailsDirectoryName, pngFile); | ||
|
||
if (!pngFile.delete()) { | ||
throw new CannotDeleteConvertedFileException(); | ||
} | ||
return thumbnailUrl; | ||
} | ||
|
||
public void deleteThumbnail(final Map map) { | ||
String fileName = makeThumbnailFileName(map); | ||
storageUploader.delete(thumbnailsDirectoryName, fileName + THUMBNAIL_EXTENSION); | ||
} | ||
|
||
private String makeThumbnailFileName(final Map map) { | ||
return String.format(THUMBNAIL_FILE_FORMAT, map.getId().toString()); | ||
} | ||
} |
This file contains 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 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 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
Submodule config
updated
from 6505dd to 700248
Oops, something went wrong.