mirror of
https://github.com/Athou/commafeed.git
synced 2026-10-27 15:38:47 +00:00
resolve public url dynamically, remove publicUrl config element
This commit is contained in:
@@ -66,6 +66,7 @@ import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -89,6 +90,7 @@ public class CategoryREST {
|
||||
private final FeedEntryService feedEntryService;
|
||||
private final FeedSubscriptionService feedSubscriptionService;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UriInfo uri;
|
||||
|
||||
@Path("/entries")
|
||||
@GET
|
||||
@@ -215,7 +217,7 @@ public class CategoryREST {
|
||||
feed.setFeedType("rss_2.0");
|
||||
feed.setTitle("CommaFeed - " + entries.getName());
|
||||
feed.setDescription("CommaFeed - " + entries.getName());
|
||||
feed.setLink(config.publicUrl());
|
||||
feed.setLink(uri.getBaseUri().toString());
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).toList());
|
||||
|
||||
SyndFeedOutput output = new SyndFeedOutput();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.commafeed.frontend.resource;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.Calendar;
|
||||
@@ -86,6 +85,7 @@ import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.ResponseBuilder;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -114,6 +114,7 @@ public class FeedREST {
|
||||
private final OPMLImporter opmlImporter;
|
||||
private final OPMLExporter opmlExporter;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UriInfo uri;
|
||||
|
||||
private static FeedEntry initTestEntry() {
|
||||
FeedEntry entry = new FeedEntry();
|
||||
@@ -217,7 +218,7 @@ public class FeedREST {
|
||||
feed.setFeedType("rss_2.0");
|
||||
feed.setTitle("CommaFeed - " + entries.getName());
|
||||
feed.setDescription("CommaFeed - " + entries.getName());
|
||||
feed.setLink(config.publicUrl());
|
||||
feed.setLink(uri.getBaseUri().toString());
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).toList());
|
||||
|
||||
SyndFeedOutput output = new SyndFeedOutput();
|
||||
@@ -413,7 +414,7 @@ public class FeedREST {
|
||||
} catch (Exception e) {
|
||||
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
|
||||
}
|
||||
return Response.temporaryRedirect(URI.create(config.publicUrl())).build();
|
||||
return Response.temporaryRedirect(uri.getBaseUri()).build();
|
||||
}
|
||||
|
||||
private String prependHttp(String url) {
|
||||
|
||||
@@ -58,6 +58,7 @@ import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -79,6 +80,7 @@ public class UserREST {
|
||||
private final PasswordEncryptionService encryptionService;
|
||||
private final MailService mailService;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UriInfo uri;
|
||||
|
||||
@Path("/settings")
|
||||
@GET
|
||||
@@ -289,7 +291,7 @@ public class UserREST {
|
||||
}
|
||||
|
||||
private String buildEmailContent(User user) throws Exception {
|
||||
String publicUrl = FeedUtils.removeTrailingSlash(config.publicUrl());
|
||||
String publicUrl = FeedUtils.removeTrailingSlash(uri.getBaseUri().toString());
|
||||
publicUrl += "/rest/user/passwordResetCallback";
|
||||
return String.format(
|
||||
"You asked for password recovery for account '%s', <a href='%s'>follow this link</a> to change your password. Ignore this if you didn't request a password recovery.",
|
||||
@@ -337,7 +339,7 @@ public class UserREST {
|
||||
|
||||
String message = "Your new password is: " + passwd;
|
||||
message += "<br />";
|
||||
message += String.format("<a href=\"%s\">Back to Homepage</a>", config.publicUrl());
|
||||
message += String.format("<a href=\"%s\">Back to Homepage</a>", uri.getBaseUri());
|
||||
return Response.ok(message).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.commafeed.frontend.servlet;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -14,6 +13,7 @@ import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.core.NewCookie;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
@Path("/logout")
|
||||
@PermitAll
|
||||
@@ -21,16 +21,19 @@ import jakarta.ws.rs.core.Response;
|
||||
public class LogoutServlet {
|
||||
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UriInfo uri;
|
||||
private final String cookieName;
|
||||
|
||||
public LogoutServlet(CommaFeedConfiguration config, @ConfigProperty(name = "quarkus.http.auth.form.cookie-name") String cookieName) {
|
||||
public LogoutServlet(CommaFeedConfiguration config, UriInfo uri,
|
||||
@ConfigProperty(name = "quarkus.http.auth.form.cookie-name") String cookieName) {
|
||||
this.config = config;
|
||||
this.uri = uri;
|
||||
this.cookieName = cookieName;
|
||||
}
|
||||
|
||||
@GET
|
||||
public Response get() {
|
||||
NewCookie removeCookie = new NewCookie.Builder(cookieName).maxAge(0).expiry(Date.from(Instant.EPOCH)).path("/").build();
|
||||
return Response.temporaryRedirect(URI.create(config.publicUrl())).cookie(removeCookie).build();
|
||||
return Response.temporaryRedirect(uri.getBaseUri()).cookie(removeCookie).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Path("/next")
|
||||
@@ -40,12 +41,13 @@ public class NextUnreadServlet {
|
||||
private final FeedEntryService feedEntryService;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final AuthenticationContext authenticationContext;
|
||||
private final UriInfo uri;
|
||||
|
||||
@GET
|
||||
public Response get(@QueryParam("category") String categoryId, @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||
User user = authenticationContext.getCurrentUser();
|
||||
if (user == null) {
|
||||
return Response.temporaryRedirect(URI.create(config.publicUrl())).build();
|
||||
return Response.temporaryRedirect(uri.getBaseUri()).build();
|
||||
}
|
||||
|
||||
FeedEntryStatus status = unitOfWork.call(() -> {
|
||||
@@ -71,7 +73,7 @@ public class NextUnreadServlet {
|
||||
return s;
|
||||
});
|
||||
|
||||
String url = status == null ? config.publicUrl() : status.getEntry().getUrl();
|
||||
String url = status == null ? uri.getBaseUri().toString() : status.getEntry().getUrl();
|
||||
return Response.temporaryRedirect(URI.create(url)).build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user