Skip to content

Commit

Permalink
🔨 fix: change file type #63
Browse files Browse the repository at this point in the history
  • Loading branch information
noparamin committed Nov 18, 2023
1 parent b7c8b89 commit 0ff1a3e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ public class JwtAuthenticationProcessingFilter extends OncePerRequestFilter {
private final JwtService jwtService;
private final UserRepository userRepository;

private static final String NO_CHECK_URL = "/login";
private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
if (request.getRequestURI().equals(NO_CHECK_URL)) {
filterChain.doFilter(request, response);
return; // return으로 이후 현재 필터 진행 막기 (안해주면 아래로 내려가서 계속 필터 진행시킴)
}
// 사용자 요청 헤더에서 RefreshToken 추출
// -> RefreshToken이 없거나 유효하지 않다면(DB에 저장된 RefreshToken과 다르다면) null을 반환
// 사용자의 요청 헤더에 RefreshToken이 있는 경우는, AccessToken이 만료되어 요청한 경우밖에 없다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;

import static com.smart.watchboard.common.support.PdfConverter.*;


@RestController
@RequestMapping("/documents")
Expand All @@ -29,7 +36,7 @@ public class AudioFileController {
private final AwsS3Uploader awsS3Uploader;
private final NoteService noteService;
private final LectureNoteService lectureNoteService;
private final RequestService requestService;
//private final RequestService requestService;
private final STTService sttService;
private final SummaryService summaryService;
private final FileService fileService;
Expand Down Expand Up @@ -91,33 +98,55 @@ public ResponseEntity<?> getAudioFile(@PathVariable(value = "documentID") long d

@PostMapping("/testffff")
public ResponseEntity<?> test(@RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException, DocumentException {
String body = """
{"keywords":["eatssss","food","today"]}
""";
String path = "https://watchboard-record-bucket.s3.ap-northeast-2.amazonaws.com/audio/mp4/26.1.m4a";
ResponseEntity<String> responseEntity = sttService.getSTT(path);
//System.out.println(responseEntity.getBody().toString());
List<SttData> sttData = sttService.getSTTData(responseEntity);
String text = sttService.getText(responseEntity);
System.out.println(text);
// String sttResult = "안녕하세요 Hello!!!!";
// String sttFileName = "sttResult.pdf";
// File textPdfFile = convertStringToPdf(sttResult, sttFileName);
// String contentType = "application/pdf";
// String originalFilename = textPdfFile.getName();
// String name = textPdfFile.getName();
//
//
// FileInputStream fileInputStream = new FileInputStream(textPdfFile);
// MultipartFile multipartFile = new MockMultipartFile(name, originalFilename, contentType, fileInputStream);
// S3Dto s3Dto = new S3Dto(multipartFile, 26L);
// String path = awsS3Uploader.uploadTextPdfFile(s3Dto);
// System.out.println(path);
// String body = """
// {"keywords":["eatssss","food","today"]}
// """;
// String path = "https://watchboard-record-bucket.s3.ap-northeast-2.amazonaws.com/audio/mp4/26.1.m4a";
// ResponseEntity<String> responseEntity = sttService.getSTT(path);
// //System.out.println(responseEntity.getBody().toString());
// List<SttData> sttData = sttService.getSTTData(responseEntity);
// String text = sttService.getText(responseEntity);
// System.out.println(text);
String sttResult = "안녕하세요 Hello!!!!";
String sttFileName = "sttResult.pdf";
File textPdfFile = convertStringToPdf(sttResult, sttFileName);
String contentType = "application/pdf";
String originalFilename = textPdfFile.getName();
String name = textPdfFile.getName();


FileInputStream fileInputStream = new FileInputStream(textPdfFile);
MultipartFile multipartFile = new MockMultipartFile(name, originalFilename, contentType, fileInputStream);
S3Dto s3Dto = new S3Dto(multipartFile, 26L, 7L, "pdf");
String path = awsS3Uploader.uploadTextPdfFile(s3Dto);
System.out.println(path);

// String path = "https://s3.ap-northeast-2.amazonaws.com/watchboard-record-bucket/application/pdf/감정분류.pdf";
// ResponseEntity<SummaryDto> responseEntity = requestService.requestPdfSummary(path);
// System.out.println(responseEntity.getBody().getSummary());
return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK);

// String sttResult = "안녕하세요";
// String sttFileName = "hello" + ".txt";
// File textFile = createTextFile(sttResult, sttFileName);
// String contentType = "text/plain";
// String originalFilename = textFile.getName();
// String name = textFile.getName();
//
// FileInputStream fileInputStream = new FileInputStream(textFile);
// MultipartFile multipartFile = createMockMultipartFile(name, originalFilename, textFile);
// //MultipartFile multipartFile = new MockMultipartFile(name, originalFilename, contentType, fileInputStream);
// //System.out.println(multipartFile.getInputStream().read());
// S3Dto s3DtoForSTT = new S3Dto(multipartFile, 26L, 7L, "txt");
// String textPdfPath = awsS3Uploader.uploadTextPdfFile(s3DtoForSTT);
// System.out.println(textPdfPath);
// try (InputStream inputStream = multipartFile.getInputStream()) {
// // InputStream에서 데이터를 읽어와서 콘솔에 출력
// int byteRead;
// while ((byteRead = inputStream.read()) != -1) {
// System.out.print((char) byteRead);
// }
// }
return new ResponseEntity<>(HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
String refreshToken = jwtService.createRefreshToken(oAuth2User.getUserId());
ResponseCookie cookie = jwtService.setCookieRefreshToken(refreshToken);
response.setHeader("Set-Cookie", cookie.toString());
response.sendRedirect("oauth2/sign-up"); // 추후 수정
response.sendRedirect("https://4988-221-148-248-129.ngrok-free.app"); // 추후 수정
User findUser = userRepository.findByEmail(oAuth2User.getEmail())
.orElseThrow(() -> new IllegalArgumentException("이메일에 해당하는 유저가 없습니다."));
findUser.authorizeUser();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/smart/watchboard/service/STTService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class STTService {

public ResponseEntity<String> getSTT(String path) throws JsonProcessingException {
String url = aiUrl + "/stt";
int startIndex = path.indexOf("audio/mp3/") + "audio/mp3/".length();
int startIndex = path.indexOf("audio/mpeg/") + "audio/mpeg/".length();
String fileName = path.substring(startIndex);

RestTemplate restTemplate = new RestTemplate();
Expand Down

0 comments on commit 0ff1a3e

Please sign in to comment.