diff --git a/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkBilibiliParser.java b/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkBilibiliParser.java index 294fe7f..3ca6ea1 100644 --- a/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkBilibiliParser.java +++ b/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkBilibiliParser.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; @@ -11,6 +13,7 @@ import run.halo.editor.hyperlink.HttpClientFactory; import run.halo.editor.hyperlink.dto.HyperLinkBaseDTO; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,7 +54,15 @@ public Mono getHyperLinkDetail(URI linkURI) { httpHeaders.set(HttpHeaders.CONTENT_TYPE, "application/json"); }) .retrieve() - .bodyToMono(String.class)); + .bodyToFlux(DataBuffer.class) + .flatMap(dataBuffer -> { + String content = dataBuffer.toString(StandardCharsets.UTF_8); + DataBufferUtils.release(dataBuffer); + return Mono.just(content); + }) + .reduce(new StringBuilder(), StringBuilder::append) + .filter(stringBuilder -> !stringBuilder.isEmpty()) + .map(StringBuilder::toString)); } public String getQueryParam(URI linkURI) { @@ -61,7 +72,6 @@ public String getQueryParam(URI linkURI) { throw new RuntimeException("id not found"); } String id = matcher.group(1); - System.out.println(id); if (id.chars().allMatch(Character::isDigit)) { return "aid=" + id; } else { diff --git a/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkQQMusicParser.java b/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkQQMusicParser.java index 1926135..7761d6e 100644 --- a/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkQQMusicParser.java +++ b/src/main/java/run/halo/editor/hyperlink/handler/HyperLinkQQMusicParser.java @@ -73,7 +73,6 @@ public String getQueryParam(URI linkURI) { throw new RuntimeException("id not found"); } String id = matcher.group(1); - System.out.println(id); if (id.chars().allMatch(Character::isDigit)) { return "songid=" + id; } else { diff --git a/src/main/java/run/halo/editor/hyperlink/handler/ParserType.java b/src/main/java/run/halo/editor/hyperlink/handler/ParserType.java index 73db297..16f70f4 100644 --- a/src/main/java/run/halo/editor/hyperlink/handler/ParserType.java +++ b/src/main/java/run/halo/editor/hyperlink/handler/ParserType.java @@ -10,7 +10,7 @@ public enum ParserType { DEFAULT("default", HyperLinkDefaultParser.class), QQMUSIC("(i.)?y.qq.com", HyperLinkQQMusicParser.class), - BILIBILI("www.bilibili.com", HyperLinkBilibiliParser.class); + BILIBILI("(www|m).bilibili.com", HyperLinkBilibiliParser.class); private final String host; private final Class> type;