4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00

Merge pull request #237 from Philreact/feature/return-unpublished-ids-multipublish

multiple publish return ids
This commit is contained in:
AlphaX-Projects 2023-12-16 08:51:41 +01:00 committed by GitHub
commit b17f0f09a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,8 +51,7 @@ class WebBrowser extends LitElement {
dogeFeePerByte: { type: Number },
dgbFeePerByte: { type: Number },
rvnFeePerByte: { type: Number },
arrrWalletAddress: { type: String },
theme: { type: String, reflect: true }
arrrWalletAddress: { type: String }
}
}
@ -1383,7 +1382,10 @@ class WebBrowser extends LitElement {
break
}
const resourcesMap = resources.map(async (resource) => {
let failedPublishesIdentifiers = []
this.loader.show()
for (const resource of resources) {
try {
const requiredFields = ['service', 'name']
const missingFields = []
@ -1396,12 +1398,20 @@ class WebBrowser extends LitElement {
if (missingFields.length > 0) {
const missingFieldsString = missingFields.join(', ')
const errorMsg = `Missing fields: ${missingFieldsString}`
throw new Error(errorMsg)
failedPublishesIdentifiers.push({
reason: errorMsg,
identifier: resource.identifier
})
continue
}
if (!resource.file && !resource.data64) {
throw new Error('No data or file was submitted')
const errorMsg = 'No data or file was submitted'
failedPublishesIdentifiers.push({
reason: errorMsg,
identifier: resource.identifier
})
continue
}
const service = resource.service
@ -1422,7 +1432,12 @@ class WebBrowser extends LitElement {
}
if (!data.encrypt && service.endsWith("_PRIVATE")) {
throw new Error("Only encrypted data can go into private services")
const errorMsg = "Only encrypted data can go into private services"
failedPublishesIdentifiers.push({
reason: errorMsg,
identifier: resource.identifier
})
continue
}
if (data.file) {
data64 = await fileToBase64(data.file)
@ -1441,7 +1456,11 @@ class WebBrowser extends LitElement {
} catch (error) {
const errorMsg = error.message || 'Upload failed due to failed encryption'
throw new Error(errorMsg)
failedPublishesIdentifiers.push({
reason: errorMsg,
identifier: resource.identifier
})
continue
}
}
@ -1452,7 +1471,7 @@ class WebBrowser extends LitElement {
const worker = new WebWorker()
try {
const resPublish = await publishData({
await publishData({
registeredName: encodeURIComponent(name),
file: data64,
service: service,
@ -1477,37 +1496,49 @@ class WebBrowser extends LitElement {
})
worker.terminate()
return resPublish
await new Promise((res)=> {
setTimeout(() => {
res()
}, 1000);
})
} catch (error) {
worker.terminate()
const errorMsg = error.message || 'Upload failed'
throw new Error(errorMsg)
failedPublishesIdentifiers.push({
reason: errorMsg,
identifier: resource.identifier
})
continue
}
} catch (error) {
failedPublishesIdentifiers.push({
reason: "Unknown error",
identifier: resource.identifier
})
continue
}
})
try {
this.loader.show()
const results = await Promise.all(resourcesMap)
response = JSON.stringify(results)
}
this.loader.hide()
break
// handle successful results
} catch (error) {
if(failedPublishesIdentifiers.length > 0){
response = failedPublishesIdentifiers
const obj = {}
const errorMsg = error.message || 'Upload failed'
const errorMsg = {
unsuccessfulPublishes: failedPublishesIdentifiers
}
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)
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
response = true
break
}
case actions.VOTE_ON_POLL: {
@ -2455,7 +2486,7 @@ class WebBrowser extends LitElement {
})
if (isNaN(Number(res))) {
const data = {}
const errorMsg = error.message || get("browserpage.bchange21")
const errorMsg = get("browserpage.bchange21")
data['error'] = errorMsg
response = JSON.stringify(data)
return