보드서비스수정
This commit is contained in:
parent
b72ce018d5
commit
e9a4cf1276
@ -191,14 +191,15 @@ public class localbordService {
|
|||||||
|
|
||||||
private String extractFirstImageUrl(String jsonContent) {
|
private String extractFirstImageUrl(String jsonContent) {
|
||||||
try {
|
try {
|
||||||
|
// JSON 유효성 검사
|
||||||
|
if (!isValidJson(jsonContent)) {
|
||||||
|
throw new IllegalArgumentException("Invalid JSON content: " + jsonContent);
|
||||||
|
}
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode rootNode = objectMapper.readTree(jsonContent);
|
JsonNode rootNode = objectMapper.readTree(jsonContent);
|
||||||
|
|
||||||
if (!rootNode.isArray()) {
|
// JSON 배열 순회
|
||||||
System.err.println("JSON content is not an array");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (JsonNode node : rootNode) {
|
for (JsonNode node : rootNode) {
|
||||||
JsonNode insertNode = node.get("insert");
|
JsonNode insertNode = node.get("insert");
|
||||||
if (insertNode != null && insertNode.has("image")) {
|
if (insertNode != null && insertNode.has("image")) {
|
||||||
@ -212,6 +213,16 @@ public class localbordService {
|
|||||||
return null; // 이미지가 없는 경우
|
return null; // 이미지가 없는 경우
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidJson(String json) {
|
||||||
|
try {
|
||||||
|
final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.readTree(json); // JSON 파싱 시도
|
||||||
|
return true; // JSON이 유효하면 true 반환
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false; // 유효하지 않은 경우 false 반환
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String extractPlainTextFromJson(String jsonContent) {
|
private String extractPlainTextFromJson(String jsonContent) {
|
||||||
StringBuilder plainTextBuilder = new StringBuilder();
|
StringBuilder plainTextBuilder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
@ -257,20 +268,15 @@ public class localbordService {
|
|||||||
post.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0));
|
post.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0));
|
||||||
|
|
||||||
Object content = post.get("content");
|
Object content = post.get("content");
|
||||||
if (content != null) {
|
String contentString = convertBlobToString(content);
|
||||||
String contentString = convertBlobToString(content);
|
post.put("content", contentString);
|
||||||
post.put("content", contentString);
|
|
||||||
|
|
||||||
// 첫 번째 이미지 URL 및 순수 텍스트 추출
|
String firstImageUrl = extractFirstImageUrl(contentString);
|
||||||
String firstImageUrl = extractFirstImageUrl(contentString);
|
post.put("firstImageUrl", firstImageUrl);
|
||||||
post.put("firstImageUrl", firstImageUrl);
|
|
||||||
|
|
||||||
String plainContent = extractPlainTextFromJson(contentString);
|
String plainContent = extractPlainTextFromJson(contentString);
|
||||||
post.put("plainContent", plainContent);
|
post.put("plainContent", plainContent);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
post.put("commentCount", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user