@@ -181,7 +181,7 @@ public void moveMany(List<Integer> ids, int targetFolderId) {
181181 public void hardDeleteOne (int dataSourceId ) {
182182 DataSource ds = dataSourceRepository .findById (dataSourceId )
183183 .orElseThrow (() -> new NoResultException ("존재하지 않는 자료입니다." ));
184- deleteOwnedImageIfAny (ds );
184+ // deleteOwnedImageIfAny(ds);
185185 dataSourceRepository .delete (ds );
186186 }
187187
@@ -190,7 +190,7 @@ public void hardDeleteMany(List<Integer> ids) {
190190 if (ids == null || ids .isEmpty ()) return ;
191191 List <DataSource > list = dataSourceRepository .findAllById (ids );
192192 if (list .size () != ids .size ()) throw new NoResultException ("존재하지 않는 자료 포함" );
193- for (DataSource ds : list ) deleteOwnedImageIfAny (ds );
193+ // for (DataSource ds : list) deleteOwnedImageIfAny(ds);
194194 dataSourceRepository .deleteAll (list );
195195 }
196196
@@ -321,19 +321,15 @@ public String uploadThumbnailAndReturnFinalUrl(MultipartFile image, String key)
321321
322322 // ===== S3 삭제 관련 유틸 =====
323323 // 소유한 이미지가 있으면 S3에서 삭제
324- private void deleteOwnedImageIfAny (DataSource ds ) {
325- String url = ds .getImageUrl ();
326- if (url == null || url .isBlank ()) return ;
327- if (!isOurS3Url (url )) return ;
328-
329- String key = extractKeyFromUrl (url );
330- if (key == null || key .isBlank ()) return ;
331-
332- try {
333- s3Service .delete (key );
334- } catch (Exception ignore ) {
335- // 파일 삭제 실패로 전체 삭제를 롤백하지 않음
336- // 필요하면 warn 로그 추가
324+ public void deleteIfOwnedByExactKey (String imageUrl , String expectedKey ) {
325+ if (imageUrl == null || imageUrl .isBlank () || expectedKey == null || expectedKey .isBlank ()) return ;
326+ String key = extractKeyFromUrl (imageUrl );
327+ if (expectedKey .equals (key )) {
328+ try {
329+ s3Service .delete (key );
330+ } catch (Exception ignore ) {
331+ // S3 삭제 실패가 전체 트랜잭션을 막지 않도록 무시
332+ }
337333 }
338334 }
339335
0 commit comments