diff --git a/qortal-ui-core/language/us.json b/qortal-ui-core/language/us.json index 26614884..0068305a 100644 --- a/qortal-ui-core/language/us.json +++ b/qortal-ui-core/language/us.json @@ -630,7 +630,9 @@ "bchange29": "Instant publish (requires 0.001 QORT fee)", "bchange30": "Service", "bchange31": "Name", - "bchange32": "Identifier" + "bchange32": "Identifier", + "bchange33": "Instant publish", + "bchange34": "Filename" }, "datapage": { "dchange1": "Data Management", diff --git a/qortal-ui-plugins/plugins/core/components/qdn-action-types.js b/qortal-ui-plugins/plugins/core/components/qdn-action-types.js index dd9df85c..b51caa6f 100644 --- a/qortal-ui-plugins/plugins/core/components/qdn-action-types.js +++ b/qortal-ui-plugins/plugins/core/components/qdn-action-types.js @@ -23,4 +23,7 @@ export const DEPLOY_AT = 'DEPLOY_AT'; export const GET_WALLET_BALANCE = 'GET_WALLET_BALANCE'; // SEND_COIN action -export const SEND_COIN = 'SEND_COIN'; \ No newline at end of file +export const SEND_COIN = 'SEND_COIN'; + +// PUBLISH_MULTIPLE_QDN_RESOURCES +export const PUBLISH_MULTIPLE_QDN_RESOURCES = 'PUBLISH_MULTIPLE_QDN_RESOURCES' \ No newline at end of file diff --git a/qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js b/qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js index 2717101b..b85ca695 100644 --- a/qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js +++ b/qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js @@ -607,6 +607,145 @@ class WebBrowser extends LitElement { } else if (res2.action === 'reject') { response = '{"error": "User declined request"}'; } + // Params: data.service, data.name, data.identifier, data.data64, + // TODO: prompt user for publish. If they confirm, call `POST /arbitrary/{service}/{name}/{identifier}/base64` and sign+process transaction + // then set the response string from the core to the `response` variable (defined above) + // If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}` + break; + } + case actions.PUBLISH_MULTIPLE_QDN_RESOURCES: { + const requiredFields = ['resources']; + const missingFields = []; + + requiredFields.forEach((field) => { + if (!data[field]) { + missingFields.push(field); + } + }); + + if (missingFields.length > 0) { + const missingFieldsString = missingFields.join(', '); + const errorMsg = `Missing fields: ${missingFieldsString}` + let data = {}; + data['error'] = errorMsg; + response = JSON.stringify(data); + break + } + const resources = data.resources + if (!Array.isArray(resources)) { + let data = {}; + data['error'] = "Invalid data" + response = JSON.stringify(data); + break + } + if (resources.length === 0) { + let data = {}; + data['error'] = "No resources to publish" + response = JSON.stringify(data); + break + } + const res2 = await showModalAndWait( + actions.PUBLISH_MULTIPLE_QDN_RESOURCES, + { + resources, + + } + ); + + if (res2.action === 'reject') { + response = '{"error": "User declined request"}'; + break + + } + const resourcesMap = resources.map(async (resource) => { + const requiredFields = ['service', 'name', 'data64']; + const missingFields = []; + + requiredFields.forEach((field) => { + if (!resource[field]) { + missingFields.push(field); + } + }); + + if (missingFields.length > 0) { + const missingFieldsString = missingFields.join(', '); + const errorMsg = `Missing fields: ${missingFieldsString}` + throw new Error(errorMsg) + } + + const service = resource.service; + const name = resource.name; + let identifier = resource.identifier; + const data64 = resource.data64; + const filename = resource.filename; + const title = resource.title; + const description = resource.description; + const category = resource.category; + const tag1 = resource.tag1; + const tag2 = resource.tag2; + const tag3 = resource.tag3; + const tag4 = resource.tag4; + const tag5 = resource.tag5; + if (resource.identifier == null) { + identifier = 'default'; + } + + const worker = new WebWorker(); + try { + + const resPublish = await publishData({ + registeredName: encodeURIComponent(name), + file: data64, + service: service, + identifier: encodeURIComponent(identifier), + parentEpml, + uploadType: 'file', + selectedAddress: this.selectedAddress, + worker: worker, + isBase64: true, + filename: filename, + title, + description, + category, + tag1, + tag2, + tag3, + tag4, + tag5, + apiVersion: 2, + withFee: res2.userData.isWithFee === true ? true : false + }); + + worker.terminate(); + return resPublish + } catch (error) { + worker.terminate(); + const errorMsg = error.message || 'Upload failed'; + throw new Error(errorMsg) + } + + + }) + + try { + this.loader.show(); + const results = await Promise.all(resourcesMap); + response = JSON.stringify(results); + this.loader.hide(); + break + // handle successful results + } catch (error) { + const obj = {}; + const errorMsg = error.message || 'Upload failed'; + obj['error'] = errorMsg; + response = JSON.stringify(obj); + this.loader.hide(); + break; + } + + + + // Params: data.service, data.name, data.identifier, data.data64, // TODO: prompt user for publish. If they confirm, call `POST /arbitrary/{service}/{name}/{identifier}/base64` and sign+process transaction // then set the response string from the core to the `response` variable (defined above) @@ -1580,7 +1719,36 @@ async function showModalAndWait(type, data) { ` : ''} - ${type === actions.PUBLISH_QDN_RESOURCE ? ` + + + + ` : ''} + ${type === actions.PUBLISH_QDN_RESOURCE ? ` ` : ''} + ${type === actions.GET_WALLET_BALANCE ? `` : ''} ${type === actions.SEND_CHAT_MESSAGE ? `` : ''} @@ -1609,7 +1778,7 @@ async function showModalAndWait(type, data) { const okButton = modal.querySelector('#ok-button'); okButton.addEventListener('click', () => { const userData = {}; - if (type === actions.PUBLISH_QDN_RESOURCE) { + if (type === actions.PUBLISH_QDN_RESOURCE || type === actions.PUBLISH_MULTIPLE_QDN_RESOURCES) { const isWithFeeCheckbox = modal.querySelector('#isWithFee'); userData.isWithFee = isWithFeeCheckbox.checked; }