diff --git a/src/main/java/org/qortal/api/resource/RenderResource.java b/src/main/java/org/qortal/api/resource/RenderResource.java index 7294da0c..519e722d 100644 --- a/src/main/java/org/qortal/api/resource/RenderResource.java +++ b/src/main/java/org/qortal/api/resource/RenderResource.java @@ -138,34 +138,38 @@ public class RenderResource { @GET @Path("/signature/{signature}") @SecurityRequirement(name = "apiKey") - public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature) { + public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null); - return this.get(signature, ResourceIdType.SIGNATURE, null, "/", null, "/render/signature", true, true); + return this.get(signature, ResourceIdType.SIGNATURE, null, "/", null, "/render/signature", true, true, theme); } @GET @Path("/signature/{signature}/{path:.*}") @SecurityRequirement(name = "apiKey") - public HttpServletResponse getPathBySignature(@PathParam("signature") String signature, @PathParam("path") String inPath) { + public HttpServletResponse getPathBySignature(@PathParam("signature") String signature, @PathParam("path") String inPath, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null); - return this.get(signature, ResourceIdType.SIGNATURE, null, inPath,null, "/render/signature", true, true); + return this.get(signature, ResourceIdType.SIGNATURE, null, inPath,null, "/render/signature", true, true, theme); } @GET @Path("/hash/{hash}") @SecurityRequirement(name = "apiKey") - public HttpServletResponse getIndexByHash(@PathParam("hash") String hash58, @QueryParam("secret") String secret58) { + public HttpServletResponse getIndexByHash(@PathParam("hash") String hash58, @QueryParam("secret") String secret58, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null); - return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, "/", secret58, "/render/hash", true, false); + return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, "/", secret58, "/render/hash", true, false, theme); } @GET @Path("/hash/{hash}/{path:.*}") @SecurityRequirement(name = "apiKey") public HttpServletResponse getPathByHash(@PathParam("hash") String hash58, @PathParam("path") String inPath, - @QueryParam("secret") String secret58) { + @QueryParam("secret") String secret58, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null); - return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, inPath, secret58, "/render/hash", true, false); + return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, inPath, secret58, "/render/hash", true, false, theme); } @GET @@ -173,29 +177,35 @@ public class RenderResource { @SecurityRequirement(name = "apiKey") public HttpServletResponse getPathByName(@PathParam("service") Service service, @PathParam("name") String name, - @PathParam("path") String inPath) { + @PathParam("path") String inPath, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, name, service, null); String prefix = String.format("/render/%s", service); - return this.get(name, ResourceIdType.NAME, service, inPath, null, prefix, true, true); + return this.get(name, ResourceIdType.NAME, service, inPath, null, prefix, true, true, theme); } @GET @Path("{service}/{name}") @SecurityRequirement(name = "apiKey") public HttpServletResponse getIndexByName(@PathParam("service") Service service, - @PathParam("name") String name) { + @PathParam("name") String name, + @QueryParam("theme") String theme) { Security.requirePriorAuthorization(request, name, service, null); String prefix = String.format("/render/%s", service); - return this.get(name, ResourceIdType.NAME, service, "/", null, prefix, true, true); + return this.get(name, ResourceIdType.NAME, service, "/", null, prefix, true, true, theme); } private HttpServletResponse get(String resourceId, ResourceIdType resourceIdType, Service service, String inPath, - String secret58, String prefix, boolean usePrefix, boolean async) { + String secret58, String prefix, boolean usePrefix, boolean async, String theme) { ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath, secret58, prefix, usePrefix, async, request, response, context); + + if (theme != null) { + renderer.setTheme(theme); + } return renderer.render(); } diff --git a/src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java b/src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java index 2e11cb48..ab94a80d 100644 --- a/src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java +++ b/src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java @@ -34,6 +34,7 @@ public class ArbitraryDataRenderer { private final String resourceId; private final ResourceIdType resourceIdType; private final Service service; + private String theme = "light"; private String inPath; private final String secret58; private final String prefix; @@ -77,7 +78,7 @@ public class ArbitraryDataRenderer { // If async is requested, show a loading screen whilst build is in progress if (async) { arbitraryDataReader.loadAsynchronously(false, 10); - return this.getLoadingResponse(service, resourceId); + return this.getLoadingResponse(service, resourceId, theme); } // Otherwise, loop until we have data @@ -171,7 +172,7 @@ public class ArbitraryDataRenderer { return userPath; } - private HttpServletResponse getLoadingResponse(Service service, String name) { + private HttpServletResponse getLoadingResponse(Service service, String name, String theme) { String responseString = ""; URL url = Resources.getResource("loading/index.html"); try { @@ -180,6 +181,7 @@ public class ArbitraryDataRenderer { // Replace vars responseString = responseString.replace("%%SERVICE%%", service.toString()); responseString = responseString.replace("%%NAME%%", name); + responseString = responseString.replace("%%THEME%%", theme); } catch (IOException e) { LOGGER.info("Unable to show loading screen: {}", e.getMessage()); @@ -210,4 +212,8 @@ public class ArbitraryDataRenderer { return indexFiles; } + public void setTheme(String theme) { + this.theme = theme; + } + } diff --git a/src/main/resources/loading/index.html b/src/main/resources/loading/index.html index fc50c72d..a828e04e 100644 --- a/src/main/resources/loading/index.html +++ b/src/main/resources/loading/index.html @@ -128,6 +128,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI