Skip to content

Commit 09f3a83

Browse files
authored
Merge pull request #14 from WishPool-dev/refactor/image-s3
Refactor/image s3
2 parents 0064835 + 5da0dfd commit 09f3a83

12 files changed

Lines changed: 100 additions & 277 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ out/
4343
**/src/main/resources/fifth-boulder-465815-c9-f67e0c16635d.json
4444
**/src/main/resources/application.yml
4545
**/src/main/resources/application-dev.yml
46+
47+
48+
upload

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ dependencies {
2929
implementation 'org.springframework.boot:spring-boot-starter-web'
3030
runtimeOnly 'com.mysql:mysql-connector-j:8.0.33'
3131

32-
// ✨ Google Cloud Platform Storage (버전 삭제 -> BOM이 관리)
33-
implementation 'com.google.cloud:spring-cloud-gcp-starter-storage'
34-
3532
// Spring Security & OAuth2
3633
implementation 'org.springframework.boot:spring-boot-starter-security'
3734
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

docker-compose.app.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docker-compose.db.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/deploy.sh

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/main/java/WishPool/Be/common/MetaData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
44
import lombok.Getter;
5-
import org.threeten.bp.LocalDateTime;
5+
6+
import java.time.LocalDateTime;
67

78
/**
89
* http 예외 발생 시 발생 API 경로 및 시간을 표현하는 클래스

src/main/java/WishPool/Be/config/GcsStorageConfig.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package WishPool.Be.config;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import java.nio.file.Path;
8+
import java.nio.file.Paths;
9+
10+
@Configuration
11+
public class UploadConfig {
12+
@Value("${file.upload.path}")
13+
private String uploadDir;
14+
15+
@Bean
16+
public Path uploadPath() {
17+
return Paths.get(uploadDir).toAbsolutePath().normalize();
18+
}
19+
}

src/main/java/WishPool/Be/file/infra/GcsService.java

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package WishPool.Be.file.infra;
2+
3+
import WishPool.Be.file.application.service.FileService;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.scheduling.annotation.Async;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.io.IOException;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.StandardOpenOption;
14+
15+
@Service
16+
@Slf4j
17+
@RequiredArgsConstructor
18+
public class NginxFileService implements FileService {
19+
private final Path uploadPath;
20+
21+
@Value("${file.image-url}")
22+
private String accessUrl;
23+
24+
@Override
25+
@Async
26+
public void uploadImageAsync(byte[] fileBytes, String key, String contentType) {
27+
log.info("비동기 로컬 파일 저장 시작: key={}", key);
28+
try {
29+
// 2. 저장할 최종 경로 생성 (설정된 기본경로 + 파일명)
30+
Path targetLocation = this.uploadPath.resolve(key);
31+
Files.createDirectories(targetLocation.getParent());
32+
33+
// 3. 파일 쓰기 (byte[] 데이터를 파일로 저장)
34+
// StandardOpenOption.CREATE: 없으면 생성
35+
// StandardOpenOption.TRUNCATE_EXISTING: 있으면 덮어쓰기
36+
Files.write(targetLocation, fileBytes,
37+
StandardOpenOption.CREATE,
38+
StandardOpenOption.TRUNCATE_EXISTING);
39+
40+
log.info("비동기 로컬 파일 저장 성공: key={}", key);
41+
42+
} catch (IOException e) {
43+
log.error("비동기 로컬 파일 저장 실패: key={}", key, e);
44+
throw new RuntimeException("비동기 파일 저장에 실패했습니다.", e);
45+
}
46+
}
47+
@Override
48+
public boolean deleteImage(String key) {
49+
try {
50+
//var/www/wishpool
51+
Path targetLocation = this.uploadPath.resolve(key);
52+
return Files.deleteIfExists(targetLocation);
53+
} catch (IOException e) {
54+
log.error("로컬 파일 삭제 실패: key={}", key, e);
55+
return false;
56+
}
57+
}
58+
59+
@Override
60+
public String getImageURL(String key) {
61+
return accessUrl + key;
62+
}
63+
}

0 commit comments

Comments
 (0)