forked from Qortal/qortal
Fixed issues preventing the loading screen from working when using the gateway.
This commit is contained in:
parent
8525fb89f8
commit
13bcfbe3c5
@ -3,8 +3,12 @@ package org.qortal.api.gateway.resource;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.qortal.api.Security;
|
||||
import org.qortal.api.model.ArbitraryResourceSummary;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.ArbitraryDataReader;
|
||||
import org.qortal.arbitrary.ArbitraryDataRenderer;
|
||||
import org.qortal.arbitrary.ArbitraryDataResource;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@ -22,6 +26,48 @@ public class GatewayResource {
|
||||
@Context HttpServletResponse response;
|
||||
@Context ServletContext context;
|
||||
|
||||
/**
|
||||
* We need to allow resource status checking (and building) via the gateway, as the node's API port
|
||||
* may not be forwarded and will almost certainly not be authenticated. Since gateways allow for
|
||||
* all resources to be loaded except those that are blacklisted, there is no need for authentication.
|
||||
*/
|
||||
@GET
|
||||
@Path("/arbitrary/resource/status/{service}/{name}")
|
||||
public ArbitraryResourceSummary getDefaultResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
return this.getSummary(service, name, null, build);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/arbitrary/resource/status/{service}/{name}/{identifier}")
|
||||
public ArbitraryResourceSummary getResourceStatus(@PathParam("service") Service service,
|
||||
@PathParam("name") String name,
|
||||
@PathParam("identifier") String identifier,
|
||||
@QueryParam("build") Boolean build) {
|
||||
|
||||
return this.getSummary(service, name, identifier, build);
|
||||
}
|
||||
|
||||
private ArbitraryResourceSummary getSummary(Service service, String name, String identifier, Boolean build) {
|
||||
|
||||
// If "build=true" has been specified in the query string, build the resource before returning its status
|
||||
if (build != null && build == true) {
|
||||
ArbitraryDataReader reader = new ArbitraryDataReader(name, ArbitraryDataFile.ResourceIdType.NAME, service, null);
|
||||
try {
|
||||
reader.loadSynchronously(false);
|
||||
} catch (Exception e) {
|
||||
// No need to handle exception, as it will be reflected in the status
|
||||
}
|
||||
}
|
||||
|
||||
ArbitraryDataResource resource = new ArbitraryDataResource(name, ResourceIdType.NAME, service, identifier);
|
||||
return resource.getSummary();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{name}/{path:.*}")
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
|
@ -68,7 +68,7 @@ public class ArbitraryDataRenderer {
|
||||
// If async is requested, show a loading screen whilst build is in progress
|
||||
if (async) {
|
||||
arbitraryDataReader.loadAsynchronously();
|
||||
return this.getLoadingResponse();
|
||||
return this.getLoadingResponse(service, resourceId);
|
||||
}
|
||||
|
||||
// Otherwise, hang the request until the build completes
|
||||
@ -145,11 +145,16 @@ public class ArbitraryDataRenderer {
|
||||
return userPath;
|
||||
}
|
||||
|
||||
private HttpServletResponse getLoadingResponse() {
|
||||
private HttpServletResponse getLoadingResponse(Service service, String name) {
|
||||
String responseString = "";
|
||||
URL url = Resources.getResource("loading/index.html");
|
||||
try {
|
||||
responseString = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
|
||||
// Replace vars
|
||||
responseString = responseString.replace("%%SERVICE%%", service.toString());
|
||||
responseString = responseString.replace("%%NAME%%", name);
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.info("Unable to show loading screen: {}", e.getMessage());
|
||||
}
|
||||
|
@ -41,9 +41,9 @@
|
||||
<script>
|
||||
const checkStatus = async () => {
|
||||
var host = location.protocol + '//' + location.host;
|
||||
var pathArray = window.location.pathname.split('/');
|
||||
var service = pathArray[2];
|
||||
var name = pathArray[3];
|
||||
var service = "%%SERVICE%%"
|
||||
var name = "%%NAME%%"
|
||||
|
||||
var url = host + '/arbitrary/resource/status/' + service + '/' + name + '?build=true';
|
||||
var textStatus = "Loading...";
|
||||
var retryInterval = 2500;
|
||||
|
Loading…
x
Reference in New Issue
Block a user