Skip to content

Commit

Permalink
Refactor : S3 이미지 삭제 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonda02 committed Aug 31, 2024
1 parent 9238e44 commit 6f4fdf8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
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}

0 comments on commit 6f4fdf8

Please sign in to comment.