diff --git a/src/main/java/com/smart/watchboard/common/support/AwsS3Uploader.java b/src/main/java/com/smart/watchboard/common/support/AwsS3Uploader.java index 3e7f4db..21d2e65 100644 --- a/src/main/java/com/smart/watchboard/common/support/AwsS3Uploader.java +++ b/src/main/java/com/smart/watchboard/common/support/AwsS3Uploader.java @@ -40,7 +40,7 @@ public String uploadFile(S3Dto s3Dto) { objectMetadata.setContentLength(s3Dto.getFile().getSize()); String directoryName = s3Dto.getFile().getContentType(); - String fileName = directoryName + "/" + s3Dto.getDocumentId() + "." + s3Dto.getFile().getOriginalFilename(); + String fileName = directoryName + "/" + s3Dto.getUserId() + "_" + s3Dto.getDocumentId() + "." + s3Dto.getDataType(); try (InputStream inputStream = s3Dto.getFile().getInputStream()) { amazonS3Client.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) @@ -67,7 +67,7 @@ public String uploadTextPdfFile(S3Dto s3Dto) { objectMetadata.setContentLength(s3Dto.getFile().getSize()); String directoryName = s3Dto.getFile().getContentType(); - String fileName = directoryName + "/" + s3Dto.getDocumentId() + "." + s3Dto.getFile().getOriginalFilename(); + String fileName = directoryName + "/" + s3Dto.getUserId() + "_" + s3Dto.getDocumentId() + "." + s3Dto.getDataType(); try (InputStream inputStream = s3Dto.getFile().getInputStream()) { amazonS3Client.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) diff --git a/src/main/java/com/smart/watchboard/controller/AudioFileController.java b/src/main/java/com/smart/watchboard/controller/AudioFileController.java index e121e79..4f3181b 100644 --- a/src/main/java/com/smart/watchboard/controller/AudioFileController.java +++ b/src/main/java/com/smart/watchboard/controller/AudioFileController.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static com.smart.watchboard.common.support.PdfConverter.convertStringToPdf; @@ -43,19 +44,22 @@ public class AudioFileController { private final MindmapService mindmapService; private final WhiteboardService whiteboardService; private final KeywordService keywordService; + private final JwtService jwtService; @PostMapping("/{documentID}/audio") public ResponseEntity uploadAudioFile(@PathVariable(value = "documentID") long documentId, @RequestParam("audio") MultipartFile audioFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException, DocumentException { - // 토큰 검증 + Optional id = jwtService.extractUserId(accessToken); + Long userId = id.orElse(null); + // s3에 오디오 파일 저장 - S3Dto s3Dto = new S3Dto(audioFile, documentId); + S3Dto s3Dto = new S3Dto(audioFile, documentId, userId, "mp3"); String path = awsS3Uploader.uploadFile(s3Dto); // STT //String sttResult = sttService.getSTT(path); ResponseEntity sttResponseEntity = sttService.getSTT(path); String sttResult = sttService.getText(sttResponseEntity); // convert - String sttFileName = "sttResult.pdf"; + String sttFileName = String.valueOf(userId) + "_" + String.valueOf(documentId) + ".pdf"; File textPdfFile = convertStringToPdf(sttResult, sttFileName); String contentType = "application/pdf"; @@ -64,7 +68,7 @@ public ResponseEntity uploadAudioFile(@PathVariable(value = "documentID") lon FileInputStream fileInputStream = new FileInputStream(textPdfFile); MultipartFile multipartFile = new MockMultipartFile(name, originalFilename, contentType, fileInputStream); - S3Dto s3DtoForSTT = new S3Dto(multipartFile, 26L); + S3Dto s3DtoForSTT = new S3Dto(multipartFile, documentId, userId, "pdf"); String textPdfPath = awsS3Uploader.uploadTextPdfFile(s3DtoForSTT); List data = sttService.getSTTData(sttResponseEntity); @@ -87,7 +91,10 @@ public ResponseEntity uploadAudioFile(@PathVariable(value = "documentID") lon @PutMapping("/{documentID}/audio") public ResponseEntity updateAudioFile(@PathVariable(value = "documentID") long documentId, @RequestParam("audio") MultipartFile audioFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException, DocumentException { - S3Dto s3Dto = new S3Dto(audioFile, documentId); + Optional id = jwtService.extractUserId(accessToken); + Long userId = id.orElse(null); + + S3Dto s3Dto = new S3Dto(audioFile, documentId, userId, "mp3"); String path = awsS3Uploader.uploadFile(s3Dto); ResponseEntity sttResponseEntity = sttService.getSTT(path); @@ -96,7 +103,8 @@ public ResponseEntity updateAudioFile(@PathVariable(value = "documentID") lon lectureNoteService.updateLectureNote(documentId, data, sttResult); // convert - String sttFileName = "sttResult.pdf"; + + String sttFileName = String.valueOf(userId) + "_" + String.valueOf(documentId) + ".pdf"; File textPdfFile = convertStringToPdf(sttResult, sttFileName); String contentType = "application/pdf"; @@ -105,7 +113,7 @@ public ResponseEntity updateAudioFile(@PathVariable(value = "documentID") lon FileInputStream fileInputStream = new FileInputStream(textPdfFile); MultipartFile multipartFile = new MockMultipartFile(name, originalFilename, contentType, fileInputStream); - S3Dto s3DtoForSTT = new S3Dto(multipartFile, 26L); + S3Dto s3DtoForSTT = new S3Dto(multipartFile, documentId, userId, "pdf"); String textPdfPath = awsS3Uploader.uploadTextPdfFile(s3DtoForSTT); ResponseEntity responseEntity = requestService.requestSTTKeywords(textPdfPath); diff --git a/src/main/java/com/smart/watchboard/controller/LearningFileController.java b/src/main/java/com/smart/watchboard/controller/LearningFileController.java index e38d96e..fbfafae 100644 --- a/src/main/java/com/smart/watchboard/controller/LearningFileController.java +++ b/src/main/java/com/smart/watchboard/controller/LearningFileController.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; @RestController @RequestMapping("/documents") @@ -30,10 +31,14 @@ public class LearningFileController { private final WhiteboardService whiteboardService; private final SummaryService summaryService; private final KeywordService keywordService; + private final JwtService jwtService; @PostMapping("/{documentID}/pdf") public ResponseEntity uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { - S3Dto s3Dto = new S3Dto(pdfFile, documentId); + Optional id = jwtService.extractUserId(accessToken); + Long userId = id.orElse(null); + + S3Dto s3Dto = new S3Dto(pdfFile, documentId, userId, "pdf"); String path = awsS3Uploader.uploadFile(s3Dto); ResponseEntity responseEntity = requestService.requestPdfKeywords(path); keywordService.createKeywords(responseEntity, documentId); @@ -47,7 +52,10 @@ public ResponseEntity uploadLearningFile(@PathVariable(value = "documentID") @PutMapping("/{documentID}/pdf") public ResponseEntity updateLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException { - S3Dto s3Dto = new S3Dto(pdfFile, documentId); + Optional id = jwtService.extractUserId(accessToken); + Long userId = id.orElse(null); + + S3Dto s3Dto = new S3Dto(pdfFile, documentId, userId, "pdf"); String path = awsS3Uploader.uploadFile(s3Dto); ResponseEntity responseEntity = requestService.requestPdfKeywords(path); keywordService.renewKeywords(responseEntity, documentId); @@ -76,7 +84,10 @@ public ResponseEntity getLearningFile(@PathVariable(value = "documentID") lon @GetMapping("/test") public ResponseEntity test(@RequestHeader("Authorization") String accessToken, @RequestParam("pdf") MultipartFile pdfFile) throws JsonProcessingException { - S3Dto s3Dto = new S3Dto(pdfFile, 11L); + Optional id = jwtService.extractUserId(accessToken); + Long userId = id.orElse(null); + + S3Dto s3Dto = new S3Dto(pdfFile, 11L, userId, "pdf"); String path = awsS3Uploader.uploadFile(s3Dto); //System.out.println(path); //String path = "abcd"; diff --git a/src/main/java/com/smart/watchboard/dto/S3Dto.java b/src/main/java/com/smart/watchboard/dto/S3Dto.java index 65bf62f..3213615 100644 --- a/src/main/java/com/smart/watchboard/dto/S3Dto.java +++ b/src/main/java/com/smart/watchboard/dto/S3Dto.java @@ -11,11 +11,13 @@ public class S3Dto { private MultipartFile file; private Long documentId; - //private Long fileId; + private Long userId; + private String dataType; - public S3Dto(MultipartFile file, long documentId) { + public S3Dto(MultipartFile file, Long documentId, Long userId, String dataType) { this.file = file; this.documentId = documentId; - //this.fileId = fileId; + this.userId = userId; + this.dataType = dataType; } }