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 // OPEN_PROFILE
export const OPEN_PROFILE = 'OPEN_PROFILE' export const OPEN_PROFILE = 'OPEN_PROFILE'
// GET_API_KEY // ADMIN_ACTION
export const GET_API_KEY = 'GET_API_KEY' export const ADMIN_ACTION = 'ADMIN_ACTION'

View File

@ -180,36 +180,36 @@ class WebBrowser extends LitElement {
render() { render() {
return html` return html`
<div id="websitesWrapper" style="width:auto; padding:10px; background: var(--white);"> <div id="websitesWrapper" style="width:auto; padding:10px; background: var(--white);">
<div class="layout horizontal center"> <div class="layout horizontal center">
<div class="address-bar"> <div class="address-bar">
<mwc-button @click=${() => this.goBack()} title="${translate('general.back')}" class="address-bar-button"> <mwc-button @click=${() => this.goBack()} title="${translate('general.back')}" class="address-bar-button">
<mwc-icon>arrow_back_ios</mwc-icon> <mwc-icon>arrow_back_ios</mwc-icon>
</mwc-button> </mwc-button>
<mwc-button @click=${() => this.goForward()} title="${translate('browserpage.bchange1')}" class="address-bar-button"> <mwc-button @click=${() => this.goForward()} title="${translate('browserpage.bchange1')}" class="address-bar-button">
<mwc-icon>arrow_forward_ios</mwc-icon> <mwc-icon>arrow_forward_ios</mwc-icon>
</mwc-button> </mwc-button>
<mwc-button @click=${() => this.refresh()} title="${translate('browserpage.bchange2')}" class="address-bar-button"> <mwc-button @click=${() => this.refresh()} title="${translate('browserpage.bchange2')}" class="address-bar-button">
<mwc-icon>refresh</mwc-icon> <mwc-icon>refresh</mwc-icon>
</mwc-button> </mwc-button>
<mwc-button @click=${() => this.goBackToList()} title="${translate('browserpage.bchange3')}" class="address-bar-button"> <mwc-button @click=${() => this.goBackToList()} title="${translate('browserpage.bchange3')}" class="address-bar-button">
<mwc-icon>home</mwc-icon> <mwc-icon>home</mwc-icon>
</mwc-button> </mwc-button>
<input @keydown=${this._handleKeyDown} style="width: 550px; color: var(--black);" id="address" type="text" value="${this.displayUrl}"></input> <input @keydown=${this._handleKeyDown} style="width: 550px; color: var(--black);" id="address" type="text" value="${this.displayUrl}"></input>
${this.renderFullScreen()} ${this.renderFullScreen()}
<mwc-button @click=${() => this.delete()} title="${translate('browserpage.bchange4')} ${this.service} ${this.name} ${translate('browserpage.bchange5')}" class="address-bar-button float-right"> <mwc-button @click=${() => this.delete()} title="${translate('browserpage.bchange4')} ${this.service} ${this.name} ${translate('browserpage.bchange5')}" class="address-bar-button float-right">
<mwc-icon>delete</mwc-icon> <mwc-icon>delete</mwc-icon>
</mwc-button> </mwc-button>
${this.renderBlockUnblockButton()} ${this.renderBlockUnblockButton()}
${this.renderFollowUnfollowButton()} ${this.renderFollowUnfollowButton()}
</div> </div>
<div class="iframe-container"> <div class="iframe-container">
<iframe id="browser-iframe" src="${this.url}" sandbox="allow-scripts allow-same-origin allow-forms allow-downloads allow-modals" allow="fullscreen"> <iframe id="browser-iframe" src="${this.url}" sandbox="allow-scripts allow-same-origin allow-forms allow-downloads allow-modals" allow="fullscreen">
<span style="color: var(--black);">${translate('browserpage.bchange6')}</span> <span style="color: var(--black);">${translate('browserpage.bchange6')}</span>
</iframe> </iframe>
</div> </div>
</div> </div>
</div> </div>
` `
} }
@ -286,24 +286,50 @@ class WebBrowser extends LitElement {
} }
} }
case actions.GET_API_KEY: { case actions.ADMIN_ACTION: {
let res1 = await showModalAndWait( let type = data.type;
actions.GET_API_KEY, let res1 = await showModalAndWait(
{ actions.ADMIN_ACTION,
service: this.service, {
name: this.name service: this.service,
} name: this.name,
); type: type
if (res1 && res1.action === 'accept') { }
let apiKey = this.getApiKey(); );
response = JSON.stringify({ apiKey }); if (res1 && res1.action === 'accept') {
break; try {
} else { // Determine the API endpoint based on the type
const data = {}; let apiEndpoint = '';
data['error'] = "User declined to share API key"; switch (type.toLowerCase()) {
response = JSON.stringify(data); case 'stop':
break; 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 admin action: ${type}`;
response = JSON.stringify(data);
}
break;
} }
case actions.ENCRYPT_DATA: { case actions.ENCRYPT_DATA: {
@ -1918,13 +1944,13 @@ class WebBrowser extends LitElement {
const requiredFields = ['coin','type'] const requiredFields = ['coin','type']
const missingFields = [] const missingFields = []
requiredFields.forEach((field) => { requiredFields.forEach((field) => {
if (!data[field]) { if (!data[field]) {
missingFields.push(field) missingFields.push(field)
} }
}) })
if (missingFields.length > 0) { if (missingFields.length > 0) {
const missingFieldsString = missingFields.join(', ') const missingFieldsString = missingFields.join(', ')
const errorMsg = `Missing fields: ${missingFieldsString}` const errorMsg = `Missing fields: ${missingFieldsString}`
let data = {} let data = {}
@ -3821,12 +3847,12 @@ async function showModalAndWait(type, data) {
</div> </div>
` : ''} ` : ''}
${type === actions.GET_API_KEY ? ` ${type === actions.ADMIN_ACTION ? `
<div class="modal-subcontainer"> <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">${`<span class="capitalize-first">${data.service.toLowerCase()}</span> wants to perform an admin action.`}</p>
<p class="modal-paragraph">Allow ${data.service.toLowerCase()} to access your API key?</p> <p class="modal-paragraph">Allow ${data.service.toLowerCase()} to ${data.type} your node?</p>
<p class="modal-paragraph">Please confirm your approval.</p> <p class="modal-paragraph">Please confirm your approval.</p>
</div> </div>
` : ''} ` : ''}
${type === actions.PUBLISH_MULTIPLE_QDN_RESOURCES ? ` ${type === actions.PUBLISH_MULTIPLE_QDN_RESOURCES ? `