From 0d611d2eb80a8254c9f81d2b9e7ba115e513b9cb Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Tue, 18 Jan 2022 10:21:30 +0200 Subject: [PATCH] removed network resurrector server dependency --- .env | 2 +- .env.production | 2 +- src/features/machines/api.js | 21 ++++++++++++------- .../machines/components/MachineContainer.js | 4 +--- .../machines/components/WakeComponent.js | 6 +++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.env b/.env index f5b0bbc..94bd022 100644 --- a/.env +++ b/.env @@ -4,7 +4,7 @@ REACT_APP_IDENTITY_AUTHENTICATION_URL=https://toodle.ddns.net/identity-server-ap REACT_APP_NETWORK_RESURRECTOR_API_URL=http://localhost:5064 #REACT_APP_NETWORK_RESURRECTOR_SERVER_URL=http://localhost:5062 -REACT_APP_NETWORK_RESURRECTOR_SERVER_URL=https://toodle.ddns.net/network-resurrector-api +#REACT_APP_NETWORK_RESURRECTOR_SERVER_URL=https://toodle.ddns.net/network-resurrector-server-api #600000 milliseconds = 10 minutes REACT_APP_MACHINE_PING_INTERVAL=600000 diff --git a/.env.production b/.env.production index c1d4822..5975b53 100644 --- a/.env.production +++ b/.env.production @@ -1,7 +1,7 @@ PUBLIC_URL=/network-resurrector/ REACT_APP_IDENTITY_AUTHENTICATION_URL=https://toodle.ddns.net/identity-server-api/identity/authenticate?UserName={username}&Password={password} REACT_APP_NETWORK_RESURRECTOR_API_URL=https://toodle.ddns.net/network-resurrector-api -REACT_APP_NETWORK_RESURRECTOR_SERVER_URL=https://toodle.ddns.net/network-resurrector-server-api +#REACT_APP_NETWORK_RESURRECTOR_SERVER_URL=https://toodle.ddns.net/network-resurrector-server-api #900000 milliseconds = 15 minutes REACT_APP_MACHINE_PING_INTERVAL=900000 diff --git a/src/features/machines/api.js b/src/features/machines/api.js index be062d7..99ebd12 100644 --- a/src/features/machines/api.js +++ b/src/features/machines/api.js @@ -1,20 +1,25 @@ import { get, post } from "../../utils/axios"; -const apiUrl = `${process.env.REACT_APP_NETWORK_RESURRECTOR_API_URL}/network`; -const serverUrl = `${process.env.REACT_APP_NETWORK_RESURRECTOR_SERVER_URL}/resurrector`; +const networkRoute = `${process.env.REACT_APP_NETWORK_RESURRECTOR_API_URL}/network`; +const powerActionsRoute = `${process.env.REACT_APP_NETWORK_RESURRECTOR_API_URL}/resurrector`; const readMachines = () => { - const machinesPromise = get(`${apiUrl}/machines`); + const machinesPromise = get(`${networkRoute}/machines`); return machinesPromise; }; -const wakeMachine = macAddress => { - const promise = post(`${serverUrl}/wake`, { macAddress }); - return promise; +const wakeMachine = async machineId => { + try { + const promise = await post(`${powerActionsRoute}/wake`, { machineId }); + return promise; + } catch (ex) { + debugger; + console.log(ex); + } }; -const pingMachine = ipAddressOrMachineName => { - const promise = post(`${serverUrl}/ping`, { ipAddressOrMachineName }); +const pingMachine = machineId => { + const promise = post(`${powerActionsRoute}/ping`, { machineId }); return promise; }; diff --git a/src/features/machines/components/MachineContainer.js b/src/features/machines/components/MachineContainer.js index 4a71984..6f76692 100644 --- a/src/features/machines/components/MachineContainer.js +++ b/src/features/machines/components/MachineContainer.js @@ -20,9 +20,7 @@ const MachineContainer = ({ machine }) => { const pingMachine = useCallback( machine => async () => { - const result = await api.pingMachine( - machine.iPv4Address || machine.machineName - ); + const result = await api.pingMachine(machine.machineId); addLog(`Success: ${result.success}. Status: ${result.status}`); if (result.success) { success(result.status); diff --git a/src/features/machines/components/WakeComponent.js b/src/features/machines/components/WakeComponent.js index 97ccb2a..b3832d0 100644 --- a/src/features/machines/components/WakeComponent.js +++ b/src/features/machines/components/WakeComponent.js @@ -37,7 +37,7 @@ const WakeComponent = ({ machine, addLog }) => { ); const wakeMachine = useCallback(async () => { - const result = await api.wakeMachine(machine.macAddress); + const result = await api.wakeMachine(machine.machineId); setState(prev => ({ ...prev, on: result.success })); log(`[Wake]: Success: ${result.success}. Status: ${result.status}`); if (result.success) { @@ -55,10 +55,10 @@ const WakeComponent = ({ machine, addLog }) => { } else { error(result.status); } - }, [log, success, error, startingTime, machine.macAddress]); + }, [log, success, error, startingTime, machine.machineId]); useEffect(() => { - api.pingMachine(machine.iPv4Address || machine.machineName).then(result => { + api.pingMachine(machine.machineId).then(result => { setState(prev => ({ ...prev, on: result.success })); log(`[Ping]: Success: ${result.success}. Status: ${result.status}`);