fetchFeedInternal follows redirects, we don't need to call it twice (#1431)

This commit is contained in:
Athou
2024-06-12 08:21:11 +02:00
parent 941f14dd41
commit 24171faf86
2 changed files with 11 additions and 13 deletions

View File

@@ -399,20 +399,20 @@ public class FeedREST {
Preconditions.checkNotNull(req.getTitle());
Preconditions.checkNotNull(req.getUrl());
String url = prependHttp(req.getUrl());
try {
url = fetchFeedInternal(url).getUrl();
FeedCategory category = null;
if (req.getCategoryId() != null && !CategoryREST.ALL.equals(req.getCategoryId())) {
category = feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
}
FeedInfo info = fetchFeedInternal(url);
FeedInfo info = fetchFeedInternal(prependHttp(req.getUrl()));
long subscriptionId = feedSubscriptionService.subscribe(user, info.getUrl(), req.getTitle(), category);
return Response.ok(subscriptionId).build();
} catch (Exception e) {
log.error("Failed to subscribe to URL {}: {}", url, e.getMessage(), e);
return Response.status(Status.SERVICE_UNAVAILABLE).entity("Failed to subscribe to URL " + url + ": " + e.getMessage()).build();
log.error("Failed to subscribe to URL {}: {}", req.getUrl(), e.getMessage(), e);
return Response.status(Status.SERVICE_UNAVAILABLE)
.entity("Failed to subscribe to URL " + req.getUrl() + ": " + e.getMessage())
.build();
}
}
@@ -423,14 +423,9 @@ public class FeedREST {
@Timed
public Response subscribeFromUrl(@Parameter(hidden = true) @SecurityCheck User user,
@Parameter(description = "feed url", required = true) @QueryParam("url") String url) {
try {
Preconditions.checkNotNull(url);
url = prependHttp(url);
url = fetchFeedInternal(url).getUrl();
FeedInfo info = fetchFeedInternal(url);
FeedInfo info = fetchFeedInternal(prependHttp(url));
feedSubscriptionService.subscribe(user, info.getUrl(), info.getTitle());
} catch (Exception e) {
log.info("Could not subscribe to url {} : {}", url, e.getMessage());