From ae2cc2b3d1ad35323e24dd1b939b812dd8429425 Mon Sep 17 00:00:00 2001 From: QuickMythril Date: Thu, 7 Nov 2024 12:23:26 -0500 Subject: [PATCH] Replace GET_API_KEY with ADMIN_ACTION --- .../core/components/qdn-action-types.js | 4 +- .../plugins/core/qdn/browser/browser.src.js | 118 +++++++++++------- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/plugins/plugins/core/components/qdn-action-types.js b/plugins/plugins/core/components/qdn-action-types.js index 1c359e06..cd795600 100644 --- a/plugins/plugins/core/components/qdn-action-types.js +++ b/plugins/plugins/core/components/qdn-action-types.js @@ -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' diff --git a/plugins/plugins/core/qdn/browser/browser.src.js b/plugins/plugins/core/qdn/browser/browser.src.js index f794fdb1..acce1221 100644 --- a/plugins/plugins/core/qdn/browser/browser.src.js +++ b/plugins/plugins/core/qdn/browser/browser.src.js @@ -180,36 +180,36 @@ class WebBrowser extends LitElement { render() { return html` -
-
-
- this.goBack()} title="${translate('general.back')}" class="address-bar-button"> +
+
+
+ this.goBack()} title="${translate('general.back')}" class="address-bar-button"> arrow_back_ios - this.goForward()} title="${translate('browserpage.bchange1')}" class="address-bar-button"> + this.goForward()} title="${translate('browserpage.bchange1')}" class="address-bar-button"> arrow_forward_ios - this.refresh()} title="${translate('browserpage.bchange2')}" class="address-bar-button"> + this.refresh()} title="${translate('browserpage.bchange2')}" class="address-bar-button"> refresh - this.goBackToList()} title="${translate('browserpage.bchange3')}" class="address-bar-button"> + this.goBackToList()} title="${translate('browserpage.bchange3')}" class="address-bar-button"> home - - ${this.renderFullScreen()} - this.delete()} title="${translate('browserpage.bchange4')} ${this.service} ${this.name} ${translate('browserpage.bchange5')}" class="address-bar-button float-right"> + + ${this.renderFullScreen()} + this.delete()} title="${translate('browserpage.bchange4')} ${this.service} ${this.name} ${translate('browserpage.bchange5')}" class="address-bar-button float-right"> delete - ${this.renderBlockUnblockButton()} - ${this.renderFollowUnfollowButton()} -
-
- -
-
-
+ ${this.renderBlockUnblockButton()} + ${this.renderFollowUnfollowButton()} +
+
+ +
+
+
` } @@ -286,24 +286,50 @@ class WebBrowser extends LitElement { } } - case actions.GET_API_KEY: { - let res1 = await showModalAndWait( - actions.GET_API_KEY, - { - service: this.service, - name: this.name - } - ); - if (res1 && res1.action === 'accept') { - let apiKey = this.getApiKey(); - response = JSON.stringify({ apiKey }); - break; - } else { - const data = {}; - data['error'] = "User declined to share API key"; - response = JSON.stringify(data); - break; - } + case actions.ADMIN_ACTION: { + let type = data.type; + let res1 = await showModalAndWait( + actions.ADMIN_ACTION, + { + service: this.service, + name: this.name, + type: type + } + ); + if (res1 && res1.action === 'accept') { + 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 admin action: ${type}`; + response = JSON.stringify(data); + } + break; } case actions.ENCRYPT_DATA: { @@ -1918,13 +1944,13 @@ class WebBrowser extends LitElement { const requiredFields = ['coin','type'] const missingFields = [] - requiredFields.forEach((field) => { + requiredFields.forEach((field) => { if (!data[field]) { missingFields.push(field) } }) - if (missingFields.length > 0) { + if (missingFields.length > 0) { const missingFieldsString = missingFields.join(', ') const errorMsg = `Missing fields: ${missingFieldsString}` let data = {} @@ -3821,12 +3847,12 @@ async function showModalAndWait(type, data) { ` : ''} - ${type === actions.GET_API_KEY ? ` - + ${type === actions.ADMIN_ACTION ? ` + ` : ''} ${type === actions.PUBLISH_MULTIPLE_QDN_RESOURCES ? `