extract image proxying from FeedUtils

This commit is contained in:
Athou
2025-07-21 16:04:51 +02:00
parent 5ee15c6f68
commit fb9d875c31
4 changed files with 97 additions and 30 deletions

View File

@@ -3,7 +3,6 @@ package com.commafeed.backend.feed;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.utils.Base64;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@@ -69,34 +68,8 @@ public class FeedUtils {
if (StringUtils.isBlank(url)) {
return url;
}
return "rest/server/proxy?u=" + imageProxyEncoder(url);
}
public static String rot13(String msg) {
StringBuilder message = new StringBuilder();
for (char c : msg.toCharArray()) {
if (c >= 'a' && c <= 'm') {
c += 13;
} else if (c >= 'n' && c <= 'z') {
c -= 13;
} else if (c >= 'A' && c <= 'M') {
c += 13;
} else if (c >= 'N' && c <= 'Z') {
c -= 13;
}
message.append(c);
}
return message.toString();
}
public static String imageProxyEncoder(String url) {
return Base64.encodeBase64String(rot13(url).getBytes());
}
public static String imageProxyDecoder(String code) {
return rot13(new String(Base64.decodeBase64(code)));
return "rest/server/proxy?u=" + ImageProxyUrl.encode(url);
}
public static void removeUnwantedFromSearch(List<Entry> entries, List<FeedEntryKeyword> keywords) {

View File

@@ -0,0 +1,37 @@
package com.commafeed.backend.feed;
import org.apache.hc.client5.http.utils.Base64;
import lombok.experimental.UtilityClass;
@UtilityClass
public class ImageProxyUrl {
public static String encode(String url) {
return Base64.encodeBase64String(rot13(url).getBytes());
}
public static String decode(String code) {
return rot13(new String(Base64.decodeBase64(code)));
}
private static String rot13(String msg) {
StringBuilder message = new StringBuilder();
for (char c : msg.toCharArray()) {
if (c >= 'a' && c <= 'm') {
c += 13;
} else if (c >= 'n' && c <= 'z') {
c -= 13;
} else if (c >= 'A' && c <= 'M') {
c += 13;
} else if (c >= 'N' && c <= 'Z') {
c -= 13;
}
message.append(c);
}
return message.toString();
}
}

View File

@@ -17,7 +17,7 @@ import com.commafeed.CommaFeedConfiguration;
import com.commafeed.CommaFeedVersion;
import com.commafeed.backend.HttpGetter;
import com.commafeed.backend.HttpGetter.HttpResult;
import com.commafeed.backend.feed.FeedUtils;
import com.commafeed.backend.feed.ImageProxyUrl;
import com.commafeed.frontend.model.ServerInfo;
import com.commafeed.security.Roles;
@@ -77,7 +77,7 @@ public class ServerREST {
return Response.status(Status.FORBIDDEN).build();
}
url = FeedUtils.imageProxyDecoder(url);
url = ImageProxyUrl.decode(url);
try {
HttpResult result = httpGetter.get(url);
return Response.ok(result.getContent()).build();