|
13 | 13 | import PodoeMarket.podoemarket.product.dto.response.ScriptDetailResponseDTO; |
14 | 14 | import PodoeMarket.podoemarket.product.dto.response.ScriptListResponseDTO; |
15 | 15 | import PodoeMarket.podoemarket.product.type.SortType; |
16 | | -import PodoeMarket.podoemarket.service.S3Service; |
17 | 16 | import PodoeMarket.podoemarket.service.ViewCountService; |
18 | 17 | import com.itextpdf.io.source.ByteArrayOutputStream; |
19 | 18 | import com.itextpdf.kernel.pdf.PdfDocument; |
|
36 | 35 | import java.io.ByteArrayInputStream; |
37 | 36 | import java.io.IOException; |
38 | 37 | import java.io.InputStream; |
39 | | -import java.io.UnsupportedEncodingException; |
40 | 38 | import java.net.URI; |
41 | 39 | import java.net.URLEncoder; |
42 | 40 | import java.nio.charset.StandardCharsets; |
@@ -191,6 +189,26 @@ public String toggleLike(UserEntity userInfo, UUID productId) { |
191 | 189 | } |
192 | 190 | } |
193 | 191 |
|
| 192 | + public ResponseEntity<StreamingResponseBody> generateFullScriptDirect(String preSignedURL) { |
| 193 | + StreamingResponseBody streamingResponseBody = outputStream -> { |
| 194 | + try (InputStream inputStream = new URI(preSignedURL).toURL().openStream()) { |
| 195 | + byte[] buffer = new byte[8192]; |
| 196 | + int bytesRead; |
| 197 | + while ((bytesRead = inputStream.read(buffer)) != -1) { |
| 198 | + outputStream.write(buffer, 0, bytesRead); |
| 199 | + outputStream.flush(); |
| 200 | + } |
| 201 | + } catch (Exception e) { |
| 202 | + log.error("PDF 스트리밍 중 오류 발생: {}", e.getMessage()); |
| 203 | + } |
| 204 | + }; |
| 205 | + |
| 206 | + return ResponseEntity.ok() |
| 207 | + .contentType(MediaType.APPLICATION_PDF) |
| 208 | + .body(streamingResponseBody); |
| 209 | + } |
| 210 | + |
| 211 | + |
194 | 212 | // ============== private (protected) method =============== |
195 | 213 | private Sort createSort(SortType sortType) { |
196 | 214 | return sortType.createSort(); |
|
0 commit comments