return relative urls to rely less on publicUrl where possible (#1016)

This commit is contained in:
Athou
2022-08-20 11:35:37 +02:00
parent c6439fe020
commit fbfe16e784
5 changed files with 19 additions and 35 deletions

View File

@@ -474,11 +474,11 @@ public class FeedUtils {
return url.startsWith("/") || url.startsWith("#") || !url.matches("^\\w+\\:\\/\\/.*");
}
public static String getFaviconUrl(FeedSubscription subscription, String publicUrl) {
return removeTrailingSlash(publicUrl) + "/rest/feed/favicon/" + subscription.getId();
public static String getFaviconUrl(FeedSubscription subscription) {
return "rest/feed/favicon/" + subscription.getId();
}
public static String proxyImages(String content, String publicUrl) {
public static String proxyImages(String content) {
if (StringUtils.isBlank(content)) {
return content;
}
@@ -488,7 +488,7 @@ public class FeedUtils {
for (Element element : elements) {
String href = element.attr("src");
if (href != null) {
String proxy = proxyImage(href, publicUrl);
String proxy = proxyImage(href);
element.attr("src", proxy);
}
}
@@ -496,11 +496,11 @@ public class FeedUtils {
return doc.body().html();
}
public static String proxyImage(String url, String publicUrl) {
public static String proxyImage(String url) {
if (StringUtils.isBlank(url)) {
return url;
}
return removeTrailingSlash(publicUrl) + "/rest/server/proxy?u=" + imageProxyEncoder(url);
return "rest/server/proxy?u=" + imageProxyEncoder(url);
}
public static String rot13(String msg) {

View File

@@ -105,7 +105,7 @@ public class Entry implements Serializable {
@ApiModelProperty(value = "tags", required = true)
private List<String> tags;
public static Entry build(FeedEntryStatus status, String publicUrl, boolean proxyImages) {
public static Entry build(FeedEntryStatus status, boolean proxyImages) {
Entry entry = new Entry();
FeedEntry feedEntry = status.getEntry();
@@ -124,23 +124,22 @@ public class Entry implements Serializable {
entry.setFeedId(String.valueOf(sub.getId()));
entry.setFeedUrl(sub.getFeed().getUrl());
entry.setFeedLink(sub.getFeed().getLink());
entry.setIconUrl(FeedUtils.getFaviconUrl(sub, publicUrl));
entry.setIconUrl(FeedUtils.getFaviconUrl(sub));
entry.setTags(status.getTags().stream().map(FeedEntryTag::getName).collect(Collectors.toList()));
if (content != null) {
entry.setRtl(FeedUtils.isRTL(feedEntry));
entry.setTitle(content.getTitle());
entry.setContent(proxyImages ? FeedUtils.proxyImages(content.getContent(), publicUrl) : content.getContent());
entry.setContent(proxyImages ? FeedUtils.proxyImages(content.getContent()) : content.getContent());
entry.setAuthor(content.getAuthor());
entry.setEnclosureType(content.getEnclosureType());
entry.setEnclosureUrl(proxyImages && StringUtils.contains(content.getEnclosureType(), "image")
? FeedUtils.proxyImage(content.getEnclosureUrl(), publicUrl)
? FeedUtils.proxyImage(content.getEnclosureUrl())
: content.getEnclosureUrl());
entry.setMediaDescription(content.getMediaDescription());
entry.setMediaThumbnailUrl(
proxyImages ? FeedUtils.proxyImage(content.getMediaThumbnailUrl(), publicUrl) : content.getMediaThumbnailUrl());
entry.setMediaThumbnailUrl(proxyImages ? FeedUtils.proxyImage(content.getMediaThumbnailUrl()) : content.getMediaThumbnailUrl());
entry.setMediaThumbnailWidth(content.getMediaThumbnailWidth());
entry.setMediaThumbnailHeight(content.getMediaThumbnailHeight());

View File

@@ -62,7 +62,7 @@ public class Subscription implements Serializable {
@ApiModelProperty(value = "JEXL string evaluated on new entries to mark them as read if they do not match")
private String filter;
public static Subscription build(FeedSubscription subscription, String publicUrl, UnreadCount unreadCount) {
public static Subscription build(FeedSubscription subscription, UnreadCount unreadCount) {
Date now = new Date();
FeedCategory category = subscription.getCategory();
Feed feed = subscription.getFeed();
@@ -74,7 +74,7 @@ public class Subscription implements Serializable {
sub.setErrorCount(feed.getErrorCount());
sub.setFeedUrl(feed.getUrl());
sub.setFeedLink(feed.getLink());
sub.setIconUrl(FeedUtils.getFaviconUrl(subscription, publicUrl));
sub.setIconUrl(FeedUtils.getFaviconUrl(subscription));
sub.setLastRefresh(feed.getLastUpdated());
sub.setNextRefresh((feed.getDisabledUntil() != null && feed.getDisabledUntil().before(now)) ? null : feed.getDisabledUntil());
sub.setUnread(unreadCount.getUnreadCount());

View File

@@ -146,18 +146,14 @@ public class CategoryREST {
offset, limit + 1, order, true, onlyIds, tag);
for (FeedEntryStatus status : list) {
entries.getEntries()
.add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getImageProxyEnabled()));
}
} else if (STARRED.equals(id)) {
entries.setName("Starred");
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(user, newerThanDate, offset, limit + 1, order, !onlyIds);
for (FeedEntryStatus status : starred) {
entries.getEntries()
.add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getImageProxyEnabled()));
}
} else {
FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(id));
@@ -169,9 +165,7 @@ public class CategoryREST {
offset, limit + 1, order, true, onlyIds, tag);
for (FeedEntryStatus status : list) {
entries.getEntries()
.add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getImageProxyEnabled()));
}
entries.setName(parent.getName());
} else {
@@ -476,7 +470,7 @@ public class CategoryREST {
if (id == null && subscription.getCategory() == null
|| subscription.getCategory() != null && Objects.equals(subscription.getCategory().getId(), id)) {
UnreadCount uc = unreadCount.get(subscription.getId());
Subscription sub = Subscription.build(subscription, config.getApplicationSettings().getPublicUrl(), uc);
Subscription sub = Subscription.build(subscription, uc);
category.getFeeds().add(sub);
}
}

View File

@@ -177,9 +177,7 @@ public class FeedREST {
entryKeywords, newerThanDate, offset, limit + 1, order, true, onlyIds, null);
for (FeedEntryStatus status : list) {
entries.getEntries()
.add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getImageProxyEnabled()));
}
boolean hasMore = entries.getEntries().size() > limit;
@@ -346,7 +344,7 @@ public class FeedREST {
return Response.status(Status.NOT_FOUND).build();
}
UnreadCount unreadCount = feedSubscriptionService.getUnreadCount(user).get(id);
return Response.ok(Subscription.build(sub, config.getApplicationSettings().getPublicUrl(), unreadCount)).build();
return Response.ok(Subscription.build(sub, unreadCount)).build();
}
@GET
@@ -522,13 +520,6 @@ public class FeedREST {
@Timed
public Response importOpml(@ApiParam(hidden = true) @SecurityCheck User user,
@ApiParam(value = "ompl file", required = true) @FormDataParam("file") InputStream input) {
String publicUrl = config.getApplicationSettings().getPublicUrl();
if (StringUtils.isBlank(publicUrl)) {
throw new WebApplicationException(
Response.status(Status.INTERNAL_SERVER_ERROR).entity("Set the public URL in the admin section.").build());
}
if (CommaFeedApplication.USERNAME_DEMO.equals(user.getName())) {
return Response.status(Status.FORBIDDEN).entity("Import is disabled for the demo account").build();
}