mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
append http protocol if missing
This commit is contained in:
@@ -39,11 +39,13 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
@Path("fetch")
|
@Path("fetch")
|
||||||
public Feed fetchFeed(@QueryParam("url") String url) {
|
public Feed fetchFeed(@QueryParam("url") String url) {
|
||||||
Preconditions.checkNotNull(url);
|
Preconditions.checkNotNull(url);
|
||||||
|
|
||||||
|
url = prependHttp(url);
|
||||||
Feed feed = null;
|
Feed feed = null;
|
||||||
try {
|
try {
|
||||||
feed = feedFetcher.fetch(url);
|
feed = feedFetcher.fetch(url);
|
||||||
} catch (FeedException e) {
|
} catch (FeedException e) {
|
||||||
throw new WebApplicationException(Response
|
throw new WebApplicationException(e, Response
|
||||||
.status(Status.INTERNAL_SERVER_ERROR)
|
.status(Status.INTERNAL_SERVER_ERROR)
|
||||||
.entity(e.getMessage()).build());
|
.entity(e.getMessage()).build());
|
||||||
}
|
}
|
||||||
@@ -57,7 +59,9 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
Preconditions.checkNotNull(req.getTitle());
|
Preconditions.checkNotNull(req.getTitle());
|
||||||
Preconditions.checkNotNull(req.getUrl());
|
Preconditions.checkNotNull(req.getUrl());
|
||||||
|
|
||||||
Feed fetchedFeed = fetchFeed(req.getUrl());
|
String url = prependHttp(req.getUrl());
|
||||||
|
|
||||||
|
Feed fetchedFeed = fetchFeed(url);
|
||||||
Feed feed = feedService.findByUrl(fetchedFeed.getUrl());
|
Feed feed = feedService.findByUrl(fetchedFeed.getUrl());
|
||||||
if (feed == null) {
|
if (feed == null) {
|
||||||
feed = fetchedFeed;
|
feed = fetchedFeed;
|
||||||
@@ -74,6 +78,13 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String prependHttp(String url) {
|
||||||
|
if (!url.startsWith("http")) {
|
||||||
|
url = "http://" + url;
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("unsubscribe")
|
@Path("unsubscribe")
|
||||||
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
|
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user