Return "Resource does not exist" error if requesting a non-existent resource via GET_QDN_RESOURCE_URL.

This commit is contained in:
CalDescent 2023-04-21 19:50:01 +01:00
parent b1ebe1864b
commit db4a9ee880
2 changed files with 19 additions and 3 deletions

View File

@ -653,6 +653,7 @@ let res = await qortalRequest({
``` ```
### Get URL to load a QDN resource ### Get URL to load a QDN resource
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
``` ```
let url = await qortalRequest({ let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL", action: "GET_QDN_RESOURCE_URL",
@ -664,6 +665,7 @@ let url = await qortalRequest({
``` ```
### Get URL to load a QDN website ### Get URL to load a QDN website
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
``` ```
let url = await qortalRequest({ let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL", action: "GET_QDN_RESOURCE_URL",
@ -673,6 +675,7 @@ let url = await qortalRequest({
``` ```
### Get URL to load a specific file from a QDN website ### Get URL to load a specific file from a QDN website
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
``` ```
let url = await qortalRequest({ let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL", action: "GET_QDN_RESOURCE_URL",

View File

@ -46,6 +46,18 @@ function handleResponse(event, response) {
responseObj = response; responseObj = response;
} }
// GET_QDN_RESOURCE_URL has custom handling
const data = event.data;
if (data.action == "GET_QDN_RESOURCE_URL") {
if (responseObj == null || responseObj.status == null || responseObj.status == "NOT_PUBLISHED") {
responseObj = {};
responseObj.error = "Resource does not exist";
}
else {
responseObj = buildResourceUrl(data.service, data.name, data.identifier, data.path, false);
}
}
// Respond to app // Respond to app
if (responseObj.error != null) { if (responseObj.error != null) {
event.ports[0].postMessage({ event.ports[0].postMessage({
@ -173,9 +185,10 @@ window.addEventListener("message", (event) => {
return httpGetAsyncWithEvent(event, "/names/" + data.name); return httpGetAsyncWithEvent(event, "/names/" + data.name);
case "GET_QDN_RESOURCE_URL": case "GET_QDN_RESOURCE_URL":
const response = buildResourceUrl(data.service, data.name, data.identifier, data.path, false); // Check status first; URL is built ant returned automatically after status check
handleResponse(event, response); url = "/arbitrary/resource/status/" + data.service + "/" + data.name;
return; if (data.identifier != null) url = url.concat("/" + data.identifier);
return httpGetAsyncWithEvent(event, url);
case "LINK_TO_QDN_RESOURCE": case "LINK_TO_QDN_RESOURCE":
if (data.service == null) data.service = "WEBSITE"; // Default to WEBSITE if (data.service == null) data.service = "WEBSITE"; // Default to WEBSITE