mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-11 17:55:51 +00:00
Merge pull request #333 from QuickMythril/more-admin-actions
Add ADMIN_ACTION types to manage peers and minting accounts
This commit is contained in:
commit
38d4c38393
@ -287,49 +287,87 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case actions.ADMIN_ACTION: {
|
case actions.ADMIN_ACTION: {
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
|
let value = data.value // Extract value from data
|
||||||
let res1 = await showModalAndWait(
|
let res1 = await showModalAndWait(
|
||||||
actions.ADMIN_ACTION,
|
actions.ADMIN_ACTION,
|
||||||
{
|
{
|
||||||
service: this.service,
|
service: this.service,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
type: type
|
type: type,
|
||||||
|
value: value // Pass value to the modal
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
if (res1 && res1.action === 'accept') {
|
if (res1 && res1.action === 'accept') {
|
||||||
try {
|
try {
|
||||||
// Determine the API endpoint based on the type
|
// Determine the API endpoint based on the type
|
||||||
let apiEndpoint = '';
|
let apiEndpoint = ''
|
||||||
|
let method = 'GET' // Default method
|
||||||
|
let includeValueInBody = false // Flag to include value in body
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
case 'stop':
|
case 'stop':
|
||||||
apiEndpoint = '/admin/stop';
|
apiEndpoint = '/admin/stop'
|
||||||
break;
|
break
|
||||||
case 'restart':
|
case 'restart':
|
||||||
apiEndpoint = '/admin/restart';
|
apiEndpoint = '/admin/restart'
|
||||||
break;
|
break
|
||||||
case 'bootstrap':
|
case 'bootstrap':
|
||||||
apiEndpoint = '/admin/bootstrap';
|
apiEndpoint = '/admin/bootstrap'
|
||||||
break;
|
break
|
||||||
|
case 'addmintingaccount':
|
||||||
|
apiEndpoint = '/admin/mintingaccounts'
|
||||||
|
method = 'POST'
|
||||||
|
includeValueInBody = true
|
||||||
|
break
|
||||||
|
case 'removemintingaccount':
|
||||||
|
apiEndpoint = '/admin/mintingaccounts'
|
||||||
|
method = 'DELETE'
|
||||||
|
includeValueInBody = true
|
||||||
|
break
|
||||||
|
case 'forcesync':
|
||||||
|
apiEndpoint = '/admin/forcesync'
|
||||||
|
method = 'POST'
|
||||||
|
includeValueInBody = true
|
||||||
|
break
|
||||||
|
case 'addpeer':
|
||||||
|
apiEndpoint = '/peers'
|
||||||
|
method = 'POST'
|
||||||
|
includeValueInBody = true
|
||||||
|
break
|
||||||
|
case 'removepeer':
|
||||||
|
apiEndpoint = '/peers'
|
||||||
|
method = 'DELETE'
|
||||||
|
includeValueInBody = true
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown admin action type: ${type}`);
|
throw new Error(`Unknown admin action type: ${type}`)
|
||||||
|
}
|
||||||
|
// Set up options for the API call
|
||||||
|
let options = {
|
||||||
|
url: `${apiEndpoint}?apiKey=${this.getApiKey()}`,
|
||||||
|
method: method
|
||||||
|
}
|
||||||
|
// Include value in body if required
|
||||||
|
if (includeValueInBody) {
|
||||||
|
options.headers = {
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
}
|
||||||
|
options.body = value // Include the peer or minting account value
|
||||||
}
|
}
|
||||||
// Send the API request
|
// Send the API request
|
||||||
let apiResponse = await parentEpml.request('apiCall', {
|
let apiResponse = await parentEpml.request('apiCall', options)
|
||||||
type: 'api',
|
response = JSON.stringify(apiResponse)
|
||||||
url: `${apiEndpoint}?apiKey=${this.getApiKey()}`
|
|
||||||
});
|
|
||||||
response = JSON.stringify(apiResponse);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const data = {};
|
const data = {}
|
||||||
data['error'] = `Error performing admin action: ${error.message}`;
|
data['error'] = `Error performing admin action: ${error.message}`
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const data = {};
|
const data = {}
|
||||||
data['error'] = `User declined admin action: ${type}`;
|
data['error'] = `User declined admin action: ${type}`
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data)
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case actions.ENCRYPT_DATA: {
|
case actions.ENCRYPT_DATA: {
|
||||||
@ -1960,8 +1998,8 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin;
|
let coin = data.coin
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
response = await parentEpml.request('apiCall', {
|
response = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -2000,9 +2038,9 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin;
|
let coin = data.coin
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
let value = data.value;
|
let value = data.value
|
||||||
response = await parentEpml.request('apiCall', {
|
response = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -2042,7 +2080,7 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin.toLowerCase();
|
let coin = data.coin.toLowerCase()
|
||||||
|
|
||||||
response = await parentEpml.request('apiCall', {
|
response = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
@ -2082,10 +2120,10 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin;
|
let coin = data.coin
|
||||||
let host = data.host;
|
let host = data.host
|
||||||
let port = data.port;
|
let port = data.port
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
hostName: host,
|
hostName: host,
|
||||||
@ -2134,10 +2172,10 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin;
|
let coin = data.coin
|
||||||
let host = data.host;
|
let host = data.host
|
||||||
let port = data.port;
|
let port = data.port
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
hostName: host,
|
hostName: host,
|
||||||
@ -2186,10 +2224,10 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let coin = data.coin;
|
let coin = data.coin
|
||||||
let host = data.host;
|
let host = data.host
|
||||||
let port = data.port;
|
let port = data.port
|
||||||
let type = data.type;
|
let type = data.type
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
hostName: host,
|
hostName: host,
|
||||||
@ -3853,7 +3891,13 @@ async function showModalAndWait(type, data) {
|
|||||||
${data.type === 'stop' ? get("nodepage.nchange31") : ''}
|
${data.type === 'stop' ? get("nodepage.nchange31") : ''}
|
||||||
${data.type === 'restart' ? get("nodepage.nchange33") : ''}
|
${data.type === 'restart' ? get("nodepage.nchange33") : ''}
|
||||||
${data.type === 'bootstrap' ? get("tour.tour18") : ''}
|
${data.type === 'bootstrap' ? get("tour.tour18") : ''}
|
||||||
|
${data.type === 'addmintingaccount' ? `${get("nodepage.nchange8")}: ${get("nodepage.nchange9")}` : ''}
|
||||||
|
${data.type === 'removemintingaccount' ? `${get("nodepage.nchange12")}: ${get("nodepage.nchange9")}` : ''}
|
||||||
|
${data.type === 'forcesync' ? get("nodepage.nchange23") : ''}
|
||||||
|
${data.type === 'addpeer' ? `${get("nodepage.nchange8")}: ${get("nodepage.nchange17")}` : ''}
|
||||||
|
${data.type === 'removepeer' ? `${get("nodepage.nchange12")}: ${get("nodepage.nchange17")}` : ''}
|
||||||
</p>
|
</p>
|
||||||
|
${data.value ? `<p class="modal-paragraph">${data.value}</p>` : ''}
|
||||||
<p class="modal-paragraph">${get("browserpage.bchange55")}</p>
|
<p class="modal-paragraph">${get("browserpage.bchange55")}</p>
|
||||||
</div>
|
</div>
|
||||||
` : ''}
|
` : ''}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user