스팸단어 체크 드레그 기능 추가

This commit is contained in:
hylee 2024-09-03 18:09:42 +09:00
parent 40df003057
commit 220b3ef2d4
2 changed files with 45 additions and 19 deletions

View File

@ -8,14 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64;
@Slf4j @Slf4j
@RestController @RestController
@ -35,22 +33,41 @@ public class RestSpamController {
} }
// 키워드 -> 핵심키워드 :: keywords -> chc_keywords // 키워드 -> 핵심키워드 :: keywords -> chc_keywords
@PutMapping("/mjon/spam/chcKeyword/{spamId}/{word}") @PutMapping("/mjon/spam/chcKeyword/{spamId}/{encodedWord}")
public ResponseEntity<RestResponse> updateChcKeyword(@PathVariable String spamId, @PathVariable String word) { public ResponseEntity<RestResponse> updateChcKeyword(@PathVariable String spamId, @PathVariable String encodedWord) {
/* try { try {
String decodedWord = URLDecoder.decode(word, StandardCharsets.UTF_8.toString()); System.out.println("Encoded Word from URL: " + encodedWord); // 인코딩된 단어 출력
return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, decodedWord)); byte[] decodedBytes = Base64.getDecoder().decode(encodedWord);
} catch (UnsupportedEncodingException e) { String word = new String(decodedBytes, StandardCharsets.UTF_8);
// 디코딩에 실패할 경우, 적절한 오류 응답을 보냅니다. System.out.println("Decoded Word: " + word); // 디코딩된 단어 출력
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid encoding"));
}*/ return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word));
return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word)); } catch (IllegalArgumentException e) {
System.err.println("Base64 decoding error: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid Base64 encoding"));
} catch (Exception e) {
System.err.println("General error: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RestResponse("Server error"));
}
// return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word));
} }
// 핵심키워드 -> 키워드 :: chc_keywords -> keywords // 핵심키워드 -> 키워드 :: chc_keywords -> keywords
@PutMapping("/mjon/spam/keyword/{spamId}/{word}") @PutMapping("/mjon/spam/keyword/{spamId}/{encodedWord}")
public ResponseEntity<RestResponse> updateKeyword(@PathVariable String spamId, @PathVariable String word) { public ResponseEntity<RestResponse> updateKeyword(@PathVariable String spamId, @PathVariable String encodedWord) {
return ResponseEntity.ok().body(spamService.updateKeyword(spamId, word)); try {
System.out.println("Encoded Word from URL: " + encodedWord); // 인코딩된 단어 출력
byte[] decodedBytes = Base64.getDecoder().decode(encodedWord);
String word = new String(decodedBytes, StandardCharsets.UTF_8);
System.out.println("Decoded Word: " + word); // 디코딩된 단어 출력
return ResponseEntity.ok().body(spamService.updateKeyword(spamId, word));
} catch (IllegalArgumentException e) {
System.err.println("Base64 decoding error: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid Base64 encoding"));
} catch (Exception e) {
System.err.println("General error: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RestResponse("Server error"));
}
} }

View File

@ -253,6 +253,10 @@
// 선택된 텍스트가 있는 경우에만 실행 // 선택된 텍스트가 있는 경우에만 실행
if (selectedText) { if (selectedText) {
if(!confirm("\'" +selectedText+ "\' 단어를 등록 하시겠습니까?")){
return false;
}
console.log(selectedText); // 선택된 텍스트를 콘솔에 출력 console.log(selectedText); // 선택된 텍스트를 콘솔에 출력
// 핵심 단어 칼럼에 새로운 단어 버튼 추가 // 핵심 단어 칼럼에 새로운 단어 버튼 추가
var spamId = $(this).closest('tr').find('button').first().data('spamid'); var spamId = $(this).closest('tr').find('button').first().data('spamid');
@ -380,7 +384,9 @@
function fn_keywordUpdate(spamId, word){ function fn_keywordUpdate(spamId, word){
// 한글이 포함된 word를 URL 인코딩합니다. // 한글이 포함된 word를 URL 인코딩합니다.
var encodedWord = encodeURIComponent(word); var base64Word = btoa(unescape(encodeURIComponent(word))); // Base64 인코딩
var encodedWord = encodeURIComponent(base64Word); // URL 인코딩
$.ajax({ $.ajax({
url: '/mjon/spam/keyword/' + spamId + '/' + encodedWord, url: '/mjon/spam/keyword/' + spamId + '/' + encodedWord,
type: 'PUT', type: 'PUT',
@ -397,7 +403,10 @@
function fn_chcKeywordUpdate(spamId, word){ function fn_chcKeywordUpdate(spamId, word){
// 한글이 포함된 word를 URL 인코딩합니다. // 한글이 포함된 word를 URL 인코딩합니다.
var encodedWord = encodeURIComponent(word); // var encodedWord = encodeURIComponent(word);
var base64Word = btoa(unescape(encodeURIComponent(word))); // Base64 인코딩
var encodedWord = encodeURIComponent(base64Word); // URL 인코딩
console.log("Encoded Word:", encodedWord); // 인코딩된 단어 출력
$.ajax({ $.ajax({
url: '/mjon/spam/chcKeyword/' + spamId + '/' + encodedWord, url: '/mjon/spam/chcKeyword/' + spamId + '/' + encodedWord,
type: 'PUT', type: 'PUT',