mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-15 03:35:49 +00:00
/site API endpoints replaced with more generic /render APIs so that they can be used for apps, blogs, etc
This involves passing a service along with the name, such as `GET /render/WEBSITE/Test`
This commit is contained in:
parent
3a05a0bcaa
commit
08b79e45cf
@ -150,7 +150,7 @@ public class DomainMapService {
|
|||||||
context.addServlet(apiServlet, "/*");
|
context.addServlet(apiServlet, "/*");
|
||||||
|
|
||||||
// Rewrite URLs
|
// Rewrite URLs
|
||||||
rewriteHandler.addRule(new RewritePatternRule("/*", "/site/domainmap/")); // rewrite / as /site/domainmap/
|
rewriteHandler.addRule(new RewritePatternRule("/*", "/render/domainmap/")); // rewrite / as /site/domainmap/
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -32,20 +32,20 @@ import org.qortal.arbitrary.ArbitraryDataFile.*;
|
|||||||
import org.qortal.utils.Base58;
|
import org.qortal.utils.Base58;
|
||||||
|
|
||||||
|
|
||||||
@Path("/site")
|
@Path("/render")
|
||||||
@Tag(name = "Website")
|
@Tag(name = "Render")
|
||||||
public class WebsiteResource {
|
public class RenderResource {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(WebsiteResource.class);
|
private static final Logger LOGGER = LogManager.getLogger(RenderResource.class);
|
||||||
|
|
||||||
@Context HttpServletRequest request;
|
@Context HttpServletRequest request;
|
||||||
@Context HttpServletResponse response;
|
@Context HttpServletResponse response;
|
||||||
@Context ServletContext context;
|
@Context ServletContext context;
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/preview")
|
@Path("/preview/{service}")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Generate preview URL based on a user-supplied path to a static website",
|
summary = "Generate preview URL based on a user-supplied path and service",
|
||||||
requestBody = @RequestBody(
|
requestBody = @RequestBody(
|
||||||
required = true,
|
required = true,
|
||||||
content = @Content(
|
content = @Content(
|
||||||
@ -68,7 +68,7 @@ public class WebsiteResource {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public String previewWebsite(String directoryPath) {
|
public String preview(@PathParam("service") Service service, String directoryPath) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
|
|
||||||
// It's too dangerous to allow user-supplied filenames in weaker security contexts
|
// It's too dangerous to allow user-supplied filenames in weaker security contexts
|
||||||
@ -77,7 +77,6 @@ public class WebsiteResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
Service service = Service.WEBSITE;
|
|
||||||
Method method = Method.PUT;
|
Method method = Method.PUT;
|
||||||
Compression compression = Compression.ZIP;
|
Compression compression = Compression.ZIP;
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ public class WebsiteResource {
|
|||||||
if (arbitraryDataFile != null) {
|
if (arbitraryDataFile != null) {
|
||||||
String digest58 = arbitraryDataFile.digest58();
|
String digest58 = arbitraryDataFile.digest58();
|
||||||
if (digest58 != null) {
|
if (digest58 != null) {
|
||||||
return "http://localhost:12393/site/hash/" + digest58 + "?secret=" + Base58.encode(arbitraryDataFile.getSecret());
|
return "http://localhost:12393/render/WEBSITE/hash/" + digest58 + "?secret=" + Base58.encode(arbitraryDataFile.getSecret());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "Unable to generate preview URL";
|
return "Unable to generate preview URL";
|
||||||
@ -107,7 +106,7 @@ public class WebsiteResource {
|
|||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature) {
|
public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(signature, ResourceIdType.SIGNATURE, "/", null, "/site/signature", true, true);
|
return this.get(signature, ResourceIdType.SIGNATURE, null, "/", null, "/render/signature", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ -115,7 +114,7 @@ public class WebsiteResource {
|
|||||||
@SecurityRequirement(name = "apiKey")
|
@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) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(signature, ResourceIdType.SIGNATURE, inPath,null, "/site/signature", true, true);
|
return this.get(signature, ResourceIdType.SIGNATURE, null, inPath,null, "/render/signature", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ -123,7 +122,7 @@ public class WebsiteResource {
|
|||||||
@SecurityRequirement(name = "apiKey")
|
@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) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(hash58, ResourceIdType.FILE_HASH, "/", secret58, "/site/hash", true, false);
|
return this.get(hash58, ResourceIdType.FILE_HASH, null, "/", secret58, "/render/hash", true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ -132,23 +131,28 @@ public class WebsiteResource {
|
|||||||
public HttpServletResponse getPathByHash(@PathParam("hash") String hash58, @PathParam("path") String inPath,
|
public HttpServletResponse getPathByHash(@PathParam("hash") String hash58, @PathParam("path") String inPath,
|
||||||
@QueryParam("secret") String secret58) {
|
@QueryParam("secret") String secret58) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(hash58, ResourceIdType.FILE_HASH, inPath, secret58, "/site/hash", true, false);
|
return this.get(hash58, ResourceIdType.FILE_HASH, null, inPath, secret58, "/render/hash", true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{name}/{path:.*}")
|
@Path("{service}/{name}/{path:.*}")
|
||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public HttpServletResponse getPathByName(@PathParam("name") String name, @PathParam("path") String inPath) {
|
public HttpServletResponse getPathByName(@PathParam("service") Service service,
|
||||||
|
@PathParam("name") String name,
|
||||||
|
@PathParam("path") String inPath) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(name, ResourceIdType.NAME, inPath, null, "/site", true, true);
|
String prefix = String.format("/render/%s", service);
|
||||||
|
return this.get(name, ResourceIdType.NAME, service, inPath, null, prefix, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{name}")
|
@Path("{service}/{name}")
|
||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public HttpServletResponse getIndexByName(@PathParam("name") String name) {
|
public HttpServletResponse getIndexByName(@PathParam("service") Service service,
|
||||||
|
@PathParam("name") String name) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
return this.get(name, ResourceIdType.NAME, "/", null, "/site", true, true);
|
String prefix = String.format("/render/%s", service);
|
||||||
|
return this.get(name, ResourceIdType.NAME, service, "/", null, prefix, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ -166,16 +170,16 @@ public class WebsiteResource {
|
|||||||
private HttpServletResponse getDomainMap(String inPath) {
|
private HttpServletResponse getDomainMap(String inPath) {
|
||||||
Map<String, String> domainMap = Settings.getInstance().getSimpleDomainMap();
|
Map<String, String> domainMap = Settings.getInstance().getSimpleDomainMap();
|
||||||
if (domainMap != null && domainMap.containsKey(request.getServerName())) {
|
if (domainMap != null && domainMap.containsKey(request.getServerName())) {
|
||||||
return this.get(domainMap.get(request.getServerName()), ResourceIdType.NAME, inPath, null, "", false, true);
|
return this.get(domainMap.get(request.getServerName()), ResourceIdType.NAME, Service.WEBSITE, inPath, null, "", false, true);
|
||||||
}
|
}
|
||||||
return ArbitraryDataRenderer.getResponse(response, 404, "Error 404: File Not Found");
|
return ArbitraryDataRenderer.getResponse(response, 404, "Error 404: File Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpServletResponse get(String resourceId, ResourceIdType resourceIdType, String inPath, String secret58,
|
private HttpServletResponse get(String resourceId, ResourceIdType resourceIdType, Service service, String inPath,
|
||||||
String prefix, boolean usePrefix, boolean async) {
|
String secret58, String prefix, boolean usePrefix, boolean async) {
|
||||||
|
|
||||||
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, inPath, secret58,
|
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
|
||||||
prefix, usePrefix, async, request, response, context);
|
secret58, prefix, usePrefix, async, request, response, context);
|
||||||
return renderer.render();
|
return renderer.render();
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ public class ArbitraryDataRenderer {
|
|||||||
|
|
||||||
private String resourceId;
|
private String resourceId;
|
||||||
private ResourceIdType resourceIdType;
|
private ResourceIdType resourceIdType;
|
||||||
|
private Service service;
|
||||||
private String inPath;
|
private String inPath;
|
||||||
private String secret58;
|
private String secret58;
|
||||||
private String prefix;
|
private String prefix;
|
||||||
@ -38,12 +39,13 @@ public class ArbitraryDataRenderer {
|
|||||||
private HttpServletResponse response;
|
private HttpServletResponse response;
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
|
||||||
public ArbitraryDataRenderer(String resourceId, ResourceIdType resourceIdType, String inPath, String secret58,
|
public ArbitraryDataRenderer(String resourceId, ResourceIdType resourceIdType, Service service, String inPath,
|
||||||
String prefix, boolean usePrefix, boolean async,
|
String secret58, String prefix, boolean usePrefix, boolean async,
|
||||||
HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
||||||
|
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId;
|
||||||
this.resourceIdType = resourceIdType;
|
this.resourceIdType = resourceIdType;
|
||||||
|
this.service = service;
|
||||||
this.inPath = inPath;
|
this.inPath = inPath;
|
||||||
this.secret58 = secret58;
|
this.secret58 = secret58;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
@ -59,7 +61,6 @@ public class ArbitraryDataRenderer {
|
|||||||
inPath = File.separator + inPath;
|
inPath = File.separator + inPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service service = Service.WEBSITE;
|
|
||||||
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(resourceId, resourceIdType, service, null);
|
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(resourceId, resourceIdType, service, null);
|
||||||
arbitraryDataReader.setSecret58(secret58); // Optional, used for loading encrypted file hashes only
|
arbitraryDataReader.setSecret58(secret58); // Optional, used for loading encrypted file hashes only
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user