Skip to content

Commit

Permalink
fix: fix the issue that some video links cannot be parsed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Aziteee committed Nov 11, 2024
1 parent 1016dcd commit f77aaa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
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;
import reactor.core.publisher.Mono;
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;

Expand Down Expand Up @@ -51,7 +54,15 @@ public Mono<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum ParserType {

DEFAULT("default", HyperLinkDefaultParser.class),
QQMUSIC("(i.)?y.qq.com", HyperLinkQQMusicParser.class),
BILIBILI("[www|m].bilibili.com", HyperLinkBilibiliParser.class);
BILIBILI("(www|m).bilibili.com", HyperLinkBilibiliParser.class);

private final String host;
private final Class<? extends HyperLinkParser<? extends HyperLinkBaseDTO>> type;
Expand Down

0 comments on commit f77aaa7

Please sign in to comment.