-
Notifications
You must be signed in to change notification settings - Fork 4
뉴젯 웰컴 뉴스레터 전송 기능 오류 수정 #139
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
base: dev
Are you sure you want to change the base?
Changes from all commits
5575cbb
a1b598b
d184054
6c69e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.newzet.api.common.storage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import com.amazonaws.services.s3.AmazonS3; | ||
| import com.amazonaws.services.s3.model.AmazonS3Exception; | ||
| import com.amazonaws.services.s3.model.GetObjectRequest; | ||
| import com.amazonaws.services.s3.model.S3Object; | ||
| import com.amazonaws.services.s3.model.S3ObjectInputStream; | ||
| import com.newzet.api.common.exception.InternalErrorException; | ||
| import com.newzet.api.config.storage.StorageConfig; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
| public class StorageService { | ||
|
|
||
| private final AmazonS3 awsS3Client; | ||
| private final AmazonS3 supabaseS3Client; | ||
| private final StorageConfig storageConfig; | ||
|
|
||
| public StorageService(@Qualifier("awsS3Client") AmazonS3 awsS3Client, | ||
| @Qualifier("supabaseS3Client") AmazonS3 supabaseS3Client, | ||
| StorageConfig storageConfig) { | ||
| this.awsS3Client = awsS3Client; | ||
| this.supabaseS3Client = supabaseS3Client; | ||
| this.storageConfig = storageConfig; | ||
| } | ||
|
|
||
| public String getContent(String key, boolean isSaveInStorage) { | ||
| AmazonS3 client; | ||
| String bucketName; | ||
|
|
||
| if (isSaveInStorage) { | ||
| client = supabaseS3Client; | ||
| bucketName = storageConfig.getSupabaseBucketName(); | ||
| } else { | ||
| client = awsS3Client; | ||
| bucketName = storageConfig.getAwsBucketName(); | ||
| } | ||
|
|
||
| GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key); | ||
|
|
||
| try (S3Object s3Object = client.getObject(getObjectRequest); | ||
| S3ObjectInputStream inputStream = s3Object.getObjectContent()) { | ||
|
|
||
| byte[] contentBytes = inputStream.readAllBytes(); | ||
| return new String(contentBytes, StandardCharsets.UTF_8); | ||
|
|
||
| } catch (AmazonS3Exception e) { | ||
| log.error("Storage에서 객체를 가져오는 중 오류가 발생했습니다. Key: {}", key, e); | ||
| throw new InternalErrorException("아티클을 불러오는 과정에서 에러가 발생하였습니다."); | ||
| } catch (IOException e) { | ||
| log.error("Storage 파일 내용을 읽는 중 I/O 오류가 발생했습니다.", e); | ||
| throw new InternalErrorException("아티클을 불러오는 과정에서 에러가 발생하였습니다."); | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.newzet.api.config.storage; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import com.amazonaws.auth.AWSCredentials; | ||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| import com.amazonaws.auth.BasicAWSCredentials; | ||
| import com.amazonaws.client.builder.AwsClientBuilder; | ||
| import com.amazonaws.services.s3.AmazonS3; | ||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Configuration | ||
| @Getter | ||
| public class StorageConfig { | ||
|
|
||
| // AWS S3 Credentials | ||
| @Value("${cloud.aws.s3.bucket}") | ||
| private String awsBucketName; | ||
| @Value("${cloud.aws.region.static}") | ||
| private String awsRegion; | ||
| @Value("${cloud.aws.credentials.access-key}") | ||
| private String awsAccessKey; | ||
| @Value("${cloud.aws.credentials.secret-key}") | ||
| private String awsSecretKey; | ||
|
|
||
| // Supabase S3-compatible Storage Credentials | ||
| @Value("${cloud.supabase.storage.bucket}") | ||
| private String supabaseBucketName; | ||
| @Value("${cloud.supabase.storage.region}") | ||
| private String supabaseRegion; | ||
| @Value("${cloud.supabase.storage.endpoint-url}") | ||
| private String supabaseEndpointUrl; | ||
| @Value("${cloud.supabase.storage.credentials.access-key}") | ||
| private String supabaseAccessKey; | ||
| @Value("${cloud.supabase.storage.credentials.secret-key}") | ||
| private String supabaseSecretKey; | ||
|
|
||
| @Bean | ||
| @Qualifier("awsS3Client") | ||
| public AmazonS3 awsS3Client() { | ||
| AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); | ||
| return AmazonS3ClientBuilder.standard() | ||
| .withRegion(awsRegion) | ||
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| @Qualifier("supabaseS3Client") | ||
| public AmazonS3 supabaseS3Client() { | ||
| AWSCredentials credentials = new BasicAWSCredentials(supabaseAccessKey, supabaseSecretKey); | ||
| AwsClientBuilder.EndpointConfiguration endpointConfig = | ||
| new AwsClientBuilder.EndpointConfiguration(supabaseEndpointUrl, supabaseRegion); | ||
|
|
||
| return AmazonS3ClientBuilder.standard() | ||
| .withEndpointConfiguration(endpointConfig) | ||
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||
| import org.springframework.stereotype.Service; | ||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||
|
|
||||||
| import org.springframework.beans.factory.annotation.Value; | ||||||
| import com.newzet.api.article.business.service.ArticleService; | ||||||
| import com.newzet.api.article.domain.Article; | ||||||
| import com.newzet.api.fcm.business.service.FcmSenderService; | ||||||
|
|
@@ -18,21 +19,20 @@ | |||||
| @RequiredArgsConstructor | ||||||
| @Transactional | ||||||
| public class WelcomeOrchestrator { | ||||||
|
|
||||||
| private static final UUID NEWZET_NEWSLETTER_ID = UUID.fromString("c4922e54-f58a-4270-80da-2dc6d59bc4fa"); | ||||||
|
|
||||||
| private static final String WELCOME_MAIL_TITLE = "💌 뉴젯과 더욱 친해지는 방법 💌"; | ||||||
| private static final String WELCOME_MAIL_URL = "newzet_content/welcome_letter"; | ||||||
| private static final String WELCOME_MAIL_IMAGE_URL = "https://newzet-lib.s3.ap-northeast-2.amazonaws.com/newsletter-image/trend_issue/nz_logo.webp"; | ||||||
|
|
||||||
| private static final String WELCOME_MAIL_URL = "welcome_letter"; | ||||||
|
||||||
| private static final String WELCOME_MAIL_URL = "welcome_letter"; | |
| private static final String WELCOME_MAIL_URL = "newzet_content/welcome_letter"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for determining storage type based on file extension '.html' seems fragile. Consider using a more explicit field or enum to indicate storage type rather than inferring from file extension.