11package run .halo .feed ;
22
3+ import static run .halo .feed .RssUtils .genRelativeThumbUri ;
4+
35import com .google .common .base .Throwables ;
6+ import java .net .URI ;
47import lombok .extern .slf4j .Slf4j ;
58import org .apache .commons .lang3 .StringUtils ;
69import org .jsoup .Jsoup ;
710import org .jsoup .nodes .Element ;
811import org .jsoup .select .Elements ;
912import org .springframework .util .Assert ;
1013import org .springframework .web .util .UriComponentsBuilder ;
11- import org .springframework .web .util .UriUtils ;
1214import run .halo .app .core .attachment .ThumbnailSize ;
1315import run .halo .app .infra .utils .PathUtils ;
1416import run .halo .feed .telemetry .TelemetryEndpoint ;
1517
16- import java .net .URI ;
17- import java .nio .charset .StandardCharsets ;
18-
1918@ Slf4j
2019public class RelativeLinkProcessor {
2120 private final URI externalUri ;
@@ -66,8 +65,6 @@ private String doProcessForHtml(String html) {
6665 processElementAttr (embeds , "src" , false );
6766
6867 return document .body ().html ();
69- // var outputHtml = document.body().html();
70- // return StringEscapeUtils.unescapeHtml4(outputHtml);
7168 }
7269
7370 private void processElementAttr (Elements elements , String attrKey , boolean canThumb ) {
@@ -89,10 +86,7 @@ boolean isNotTelemetryLink(String uri) {
8986 }
9087
9188 private String genThumbUrl (String url , ThumbnailSize size ) {
92- return processLink ("/apis/api.storage.halo.run/v1alpha1/thumbnails/-/via-uri?uri="
93- + UriUtils .encode (url , StandardCharsets .UTF_8 )
94- + "&size=" + size .name ().toLowerCase ()
95- );
89+ return processLink (genRelativeThumbUri (url , size ));
9690 }
9791
9892 private String processLink (String link ) {
@@ -101,18 +95,18 @@ private String processLink(String link) {
10195 }
10296 var contextPath = StringUtils .defaultIfBlank (externalUri .getPath (), "/" );
10397 var linkUri = UriComponentsBuilder .fromUriString (URI .create (link ).toASCIIString ())
104- .build (true );
98+ .build (true );
10599 var builder = UriComponentsBuilder .fromUriString (externalUri .toString ());
106100 if (shouldAppendPath (contextPath , link )) {
107101 builder .pathSegment (linkUri .getPathSegments ().toArray (new String [0 ]));
108102 } else {
109103 builder .replacePath (linkUri .getPath ());
110104 }
111105 return builder .query (linkUri .getQuery ())
112- .fragment (linkUri .getFragment ())
113- .build (true )
114- .toUri ()
115- .toString ();
106+ .fragment (linkUri .getFragment ())
107+ .build (true )
108+ .toUri ()
109+ .toString ();
116110 }
117111
118112 private static boolean shouldAppendPath (String contextPath , String link ) {
0 commit comments