From dde1af071cb22ac896c902055f08fcdf72b2e93e Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Fri, 21 Jul 2023 16:09:22 -0700 Subject: [PATCH] refactor: WebguiUnraidApiCommand --- composables/services/webgui.ts | 39 ++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/composables/services/webgui.ts b/composables/services/webgui.ts index 4810b6efa..0f6191b73 100644 --- a/composables/services/webgui.ts +++ b/composables/services/webgui.ts @@ -29,15 +29,40 @@ export const WebguiUpdate = request.url('/update.php'); * @type POST */ export const WebguiUpdateDns = request.url('/webGui/include/UpdateDNS.php'); -/** - * @name WebguiUpdateDns - * @description used after Sign In to ensure URLs will work correctly - * @type POST - */ -export const WebguiUnraidApiCommand = request.url('/plugins/dynamix.my.servers/include/unraid-api.php'); /** * @name WebguiState * @description used to get current state of server via PHP rather than unraid-api * @type GET - */ +*/ export const WebguiState = request.url('/plugins/dynamix.my.servers/data/server-state.php'); +/** + * Run unraid-api command's via php requests + */ +export interface WebguiUnraidApiCommandPayload { + csrf_token: string; + command: 'report' | 'start'; + param1?: '-v'|'-vv'; +} +export const WebguiUnraidApiCommand = async (payload: WebguiUnraidApiCommandPayload) => { + console.debug('[WebguiUnraidApiCommand]', payload); + // eslint-disable-next-line camelcase + const { csrf_token, command, param1 } = payload; + // // Trigger front-end interactivty based on command + // if (command === 'start') { commit('SET_MY_SERVERS_LOADING', true); } + const response = await request + .url('/plugins/dynamix.my.servers/include/unraid-api.php') + .formUrl({ + // eslint-disable-next-line camelcase + csrf_token, + command, + param1, + }) + .post() + .json((json) => { + log.debug('👼 [WebguiUnraidApiCommand] json %o', json); + }) + .catch((error) => { + log.error(`[WebguiUnraidApiCommand] catch failed to execute unraid-api ${command} 😢 %o`, error); + }); + return response; +};