|
1 | 1 | package com.example.backend.search.service; |
2 | 2 |
|
| 3 | +import com.amazonaws.HttpMethod; |
| 4 | +import com.amazonaws.services.s3.AmazonS3; |
| 5 | +import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; |
3 | 6 | import com.example.backend.common.domain.CaseEntity; |
4 | 7 | import com.example.backend.search.domain.SearchSpecification; |
5 | 8 | import com.example.backend.search.dto.*; |
6 | 9 | import com.example.backend.search.repository.SearchRepository; |
7 | 10 | import lombok.RequiredArgsConstructor; |
| 11 | +import org.springframework.beans.factory.annotation.Value; |
8 | 12 | import org.springframework.data.domain.*; |
9 | 13 | import org.springframework.data.jpa.domain.Specification; |
10 | 14 | import org.springframework.stereotype.Service; |
11 | 15 | import org.springframework.transaction.annotation.Transactional; |
12 | 16 |
|
13 | 17 | import java.time.LocalDateTime; |
| 18 | +import java.util.Date; |
14 | 19 | import java.util.List; |
| 20 | +import java.util.concurrent.TimeUnit; |
15 | 21 | import java.util.stream.Collectors; |
16 | 22 |
|
17 | 23 | @Service |
@@ -58,11 +64,29 @@ public SearchResult getCheckLog(String category, LocalDateTime startDate, LocalD |
58 | 64 | .build(); |
59 | 65 | } |
60 | 66 |
|
| 67 | + @Value("${cloud.aws.bucket}") |
| 68 | + private String bucket; |
| 69 | + private final AmazonS3 s3Client; |
61 | 70 | public DetailResponse getLogById(Integer id) { |
62 | 71 | CaseEntity caseEntity = searchRepository.findById(id) |
63 | 72 | .orElseThrow(() -> new IllegalArgumentException("해당 ID의 로그를 찾을 수 없습니다.")); |
64 | 73 |
|
65 | | - return DetailResponse.fromEntity(caseEntity); |
| 74 | + String videoKey = caseEntity.getVideo(); |
| 75 | + |
| 76 | + // Presigned URL 유효기간 설정 (30분) |
| 77 | + Date expiration = new Date(); |
| 78 | + long expTime = expiration.getTime(); |
| 79 | + expTime += TimeUnit.MINUTES.toMillis(30); // 30 minute |
| 80 | + expiration.setTime(expTime); |
| 81 | + |
| 82 | + GeneratePresignedUrlRequest presignRequest = |
| 83 | + new GeneratePresignedUrlRequest(bucket, videoKey) |
| 84 | + .withMethod(HttpMethod.GET) |
| 85 | + .withExpiration(expiration); |
| 86 | + |
| 87 | + String presignedUrl = s3Client.generatePresignedUrl(presignRequest).toString(); |
| 88 | + |
| 89 | + return DetailResponse.fromEntity(caseEntity, presignedUrl); |
66 | 90 | } |
67 | 91 |
|
68 | 92 |
|
|
0 commit comments