mirror of
https://github.com/Qortal/qortal.git
synced 2025-06-01 05:56:59 +00:00
Added "qdnContext" variable, with possible values of "render", "gateway", or "domainMap".
This is used internally to allow Q-Apps to determine how to handle certain requests.
This commit is contained in:
parent
5a1cc7a0de
commit
3b6e1ea27f
@ -12,11 +12,13 @@ public class HTMLParser {
|
|||||||
|
|
||||||
private String linkPrefix;
|
private String linkPrefix;
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
private String qdnContext;
|
||||||
|
|
||||||
public HTMLParser(String resourceId, String inPath, String prefix, boolean usePrefix, byte[] data) {
|
public HTMLParser(String resourceId, String inPath, String prefix, boolean usePrefix, byte[] data, String qdnContext) {
|
||||||
String inPathWithoutFilename = inPath.substring(0, inPath.lastIndexOf('/'));
|
String inPathWithoutFilename = inPath.substring(0, inPath.lastIndexOf('/'));
|
||||||
this.linkPrefix = usePrefix ? String.format("%s/%s%s", prefix, resourceId, inPathWithoutFilename) : "";
|
this.linkPrefix = usePrefix ? String.format("%s/%s%s", prefix, resourceId, inPathWithoutFilename) : "";
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.qdnContext = qdnContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAdditionalHeaderTags() {
|
public void addAdditionalHeaderTags() {
|
||||||
@ -29,6 +31,10 @@ public class HTMLParser {
|
|||||||
String qAppsScriptElement = String.format("<script src=\"/apps/q-apps.js?time=%d\">", System.currentTimeMillis());
|
String qAppsScriptElement = String.format("<script src=\"/apps/q-apps.js?time=%d\">", System.currentTimeMillis());
|
||||||
head.get(0).prepend(qAppsScriptElement);
|
head.get(0).prepend(qAppsScriptElement);
|
||||||
|
|
||||||
|
// Add QDN context var
|
||||||
|
String qdnContextVar = String.format("<script>var qdnContext=\"%s\";</script>", this.qdnContext);
|
||||||
|
head.get(0).prepend(qdnContextVar);
|
||||||
|
|
||||||
// Add base href tag
|
// Add base href tag
|
||||||
String baseElement = String.format("<base href=\"%s\">", baseUrl);
|
String baseElement = String.format("<base href=\"%s\">", baseUrl);
|
||||||
head.get(0).prepend(baseElement);
|
head.get(0).prepend(baseElement);
|
||||||
|
@ -51,7 +51,7 @@ public class DomainMapResource {
|
|||||||
String secret58, String prefix, boolean usePrefix, boolean async) {
|
String secret58, String prefix, boolean usePrefix, boolean async) {
|
||||||
|
|
||||||
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
||||||
secret58, prefix, usePrefix, async, request, response, context);
|
secret58, prefix, usePrefix, async, "domainMap", request, response, context);
|
||||||
return renderer.render();
|
return renderer.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ public class GatewayResource {
|
|||||||
String secret58, String prefix, boolean usePrefix, boolean async) {
|
String secret58, String prefix, boolean usePrefix, boolean async) {
|
||||||
|
|
||||||
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
||||||
secret58, prefix, usePrefix, async, request, response, context);
|
secret58, prefix, usePrefix, async, "gateway", request, response, context);
|
||||||
return renderer.render();
|
return renderer.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ public class RenderResource {
|
|||||||
String secret58, String prefix, boolean usePrefix, boolean async, String theme) {
|
String secret58, String prefix, boolean usePrefix, boolean async, String theme) {
|
||||||
|
|
||||||
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
||||||
secret58, prefix, usePrefix, async, request, response, context);
|
secret58, prefix, usePrefix, async, "render", request, response, context);
|
||||||
|
|
||||||
if (theme != null) {
|
if (theme != null) {
|
||||||
renderer.setTheme(theme);
|
renderer.setTheme(theme);
|
||||||
|
@ -40,12 +40,13 @@ public class ArbitraryDataRenderer {
|
|||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final boolean usePrefix;
|
private final boolean usePrefix;
|
||||||
private final boolean async;
|
private final boolean async;
|
||||||
|
private final String qdnContext;
|
||||||
private final HttpServletRequest request;
|
private final HttpServletRequest request;
|
||||||
private final HttpServletResponse response;
|
private final HttpServletResponse response;
|
||||||
private final ServletContext context;
|
private final ServletContext context;
|
||||||
|
|
||||||
public ArbitraryDataRenderer(String resourceId, ResourceIdType resourceIdType, Service service, String inPath,
|
public ArbitraryDataRenderer(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 qdnContext,
|
||||||
HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
||||||
|
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId;
|
||||||
@ -56,6 +57,7 @@ public class ArbitraryDataRenderer {
|
|||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.usePrefix = usePrefix;
|
this.usePrefix = usePrefix;
|
||||||
this.async = async;
|
this.async = async;
|
||||||
|
this.qdnContext = qdnContext;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -118,7 +120,7 @@ public class ArbitraryDataRenderer {
|
|||||||
if (HTMLParser.isHtmlFile(filename)) {
|
if (HTMLParser.isHtmlFile(filename)) {
|
||||||
// HTML file - needs to be parsed
|
// HTML file - needs to be parsed
|
||||||
byte[] data = Files.readAllBytes(Paths.get(filePath)); // TODO: limit file size that can be read into memory
|
byte[] data = Files.readAllBytes(Paths.get(filePath)); // TODO: limit file size that can be read into memory
|
||||||
HTMLParser htmlParser = new HTMLParser(resourceId, inPath, prefix, usePrefix, data);
|
HTMLParser htmlParser = new HTMLParser(resourceId, inPath, prefix, usePrefix, data, qdnContext);
|
||||||
htmlParser.addAdditionalHeaderTags();
|
htmlParser.addAdditionalHeaderTags();
|
||||||
response.addHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src 'self' blob:; img-src 'self' data: blob:;");
|
response.addHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src 'self' blob:; img-src 'self' data: blob:;");
|
||||||
response.setContentType(context.getMimeType(filename));
|
response.setContentType(context.getMimeType(filename));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user