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

Refactor : S3 이미지 삭제 로직 변경 #56

Merged
merged 1 commit into from
Aug 31, 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
3 changes: 2 additions & 1 deletion src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public String uploadFile(String keyName, MultipartFile file)throws IOException {
return amazonS3.getUrl(amazonConfig.getBucket(),keyName).toString();
}
public void deleteFile(String photoUrl){
amazonS3.deleteObject(new DeleteObjectRequest(amazonConfig.getBucket(),photoUrl));
String s3Key = photoUrl.replace("https://umc-7th.s3.ap-northeast-2.amazonaws.com/", "");
amazonS3.deleteObject(new DeleteObjectRequest(amazonConfig.getBucket(), s3Key));
}
public String generatePhotoKeyName(Uuid uuid) {
return amazonConfig.getPhotoPath() + '/' + uuid.getUuid() + ".png";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SchedulerServiceImpl implements SchedulerService{
public void deletePhoto() {
List<Photo> photoList = photoRepository.findAll();
photoList.stream()
.filter(photo -> Duration.between(photo.getCreatedAt(), LocalDateTime.now()).toHours()>=2)
.filter(photo -> Duration.between(photo.getCreatedAt(), LocalDateTime.now()).toMinutes() >= 1)
.forEach(photo -> {
s3Manager.deleteFile(photo.getPhotoUrl());

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cloud:
static: ap-northeast-2
stack:
auto: false
cron: "0 0 */1 * * *"
cron: "0 * * * * *"
credentials:
accessKey: ${aws.access.key.id}
secretKey: ${aws.secret.access.key}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cloud:
static: ap-northeast-2
stack:
auto: false
cron: "0 */2 * * * *"
cron: "0 * * * * *"
credentials:
accessKey: ${aws.access.key.id}
secretKey: ${aws.secret.access.key}
Loading