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

Replace GET_API_KEY with ADMIN_ACTION

This commit is contained in:
QuickMythril 2024-11-07 12:23:26 -05:00
parent 287f582275
commit ae2cc2b3d1
2 changed files with 74 additions and 48 deletions

View File

@ -112,5 +112,5 @@ export const GET_FRIENDS_LIST = 'GET_FRIENDS_LIST'
// OPEN_PROFILE
export const OPEN_PROFILE = 'OPEN_PROFILE'
// GET_API_KEY
export const GET_API_KEY = 'GET_API_KEY'
// ADMIN_ACTION
export const ADMIN_ACTION = 'ADMIN_ACTION'

View File

@ -286,24 +286,50 @@ class WebBrowser extends LitElement {
}
}
case actions.GET_API_KEY: {
case actions.ADMIN_ACTION: {
let type = data.type;
let res1 = await showModalAndWait(
actions.GET_API_KEY,
actions.ADMIN_ACTION,
{
service: this.service,
name: this.name
name: this.name,
type: type
}
);
if (res1 && res1.action === 'accept') {
let apiKey = this.getApiKey();
response = JSON.stringify({ apiKey });
try {
// Determine the API endpoint based on the type
let apiEndpoint = '';
switch (type.toLowerCase()) {
case 'stop':
apiEndpoint = '/admin/stop';
break;
case 'restart':
apiEndpoint = '/admin/restart';
break;
case 'bootstrap':
apiEndpoint = '/admin/bootstrap';
break;
default:
throw new Error(`Unknown admin action type: ${type}`);
}
// Send the API request
let apiResponse = await parentEpml.request('apiCall', {
type: 'api',
url: `${apiEndpoint}?apiKey=${this.getApiKey()}`
});
response = JSON.stringify(apiResponse);
} catch (error) {
const data = {};
data['error'] = `Error performing admin action: ${error.message}`;
response = JSON.stringify(data);
}
} else {
const data = {};
data['error'] = "User declined to share API key";
data['error'] = `User declined admin action: ${type}`;
response = JSON.stringify(data);
break;
}
break;
}
case actions.ENCRYPT_DATA: {
@ -3821,10 +3847,10 @@ async function showModalAndWait(type, data) {
</div>
` : ''}
${type === actions.GET_API_KEY ? `
${type === actions.ADMIN_ACTION ? `
<div class="modal-subcontainer">
<p class="modal-paragraph">${`<span class="capitalize-first">${data.service.toLowerCase()}</span> wants to access your API key.`}</p>
<p class="modal-paragraph">Allow ${data.service.toLowerCase()} to access your API key?</p>
<p class="modal-paragraph">${`<span class="capitalize-first">${data.service.toLowerCase()}</span> wants to perform an admin action.`}</p>
<p class="modal-paragraph">Allow ${data.service.toLowerCase()} to ${data.type} your node?</p>
<p class="modal-paragraph">Please confirm your approval.</p>
</div>
` : ''}