Skip to content

Commit

Permalink
Allow any html endpoint to be refreshed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lPrimemaster committed Feb 10, 2025
1 parent 01c6aa4 commit c410257
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 83 deletions.
71 changes: 36 additions & 35 deletions frontend/src/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, createSignal, createEffect, on } from 'solid-js';
import { Component, createSignal, createEffect, on, onMount } from 'solid-js';
import Sidebar from './components/Sidebar'
import Card from './components/Card';
import BackendStatusTable from './components/BackendStatusTable';
Expand All @@ -14,7 +14,7 @@ import { ResourcePanel } from './components/ResourcePanel';
import { ClientsTable } from './components/ClientsTable';
import { Hello } from 'mulex-api';

const [socketStatus, setSocketStatus] = createSignal<boolean>(false);
const [socketStatus, setSocketStatus] = createSignal<boolean>(true);
const [runStatus, setRunStatus] = createSignal<string>('Stopped');
const [runNumber, setRunNumber] = createSignal<number>(0);
const [runTimestamp, setRunTimestamp] = createSignal<number>(0);
Expand Down Expand Up @@ -54,46 +54,47 @@ const Home: Component = () => {

MxWebsocket.instance.on_connection_change((conn: boolean) => {
setSocketStatus(conn);
});

if(conn) {
// if(conn) {
// MxWebsocket.instance.rpc_call('mulex::RdbListKeys', [], 'generic').then((res) => {
// const keys = res.astype('stringarray');
// const tree = new MxRdbTree(keys);
// tree.print_tree();
// });

MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/status')],
'generic').then((res: MxGenericType) => {
const rstatus = res.astype('uint8');
// Status MEMO:
// 0 - Stopped
// 1 - Running
// 2 - Starting
// 3 - Stopping
setRunStatusFromCode(rstatus);
});

MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/number')],
'generic').then((res: MxGenericType) => {
const rnumber = res.astype('uint64');
setRunNumber(Number(rnumber));
});

MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/timestamp')],
'generic').then((res: MxGenericType) => {
const rts = res.astype('int64');
setRunTimestamp(Number(rts));
});

watchRunInfo();
}
});
// onMount(() => {
MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/status')],
'generic').then((res: MxGenericType) => {
const rstatus = res.astype('uint8');
// Status MEMO:
// 0 - Stopped
// 1 - Running
// 2 - Starting
// 3 - Stopping
setRunStatusFromCode(rstatus);
});

MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/number')],
'generic').then((res: MxGenericType) => {
const rnumber = res.astype('uint64');
setRunNumber(Number(rnumber));
});

MxWebsocket.instance.rpc_call(
'mulex::RdbReadValueDirect',
[MxGenericType.str512('/system/run/timestamp')],
'generic').then((res: MxGenericType) => {
const rts = res.astype('int64');
setRunTimestamp(Number(rts));
});

watchRunInfo();
// });

// If the socket status changes, emit a message on the toaster
let skipToastInit = true;
Expand Down
36 changes: 19 additions & 17 deletions frontend/src/components/BackendStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, For, Show, createSignal } from 'solid-js';
import { Component, For, Show, createSignal, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
import { MxWebsocket } from '../lib/websocket';
import { MxRdb } from '../lib/rdb';
Expand Down Expand Up @@ -55,24 +55,26 @@ const BackendStatusTable: Component = () => {
return key.replace('/system/backends/', '').split('/').shift() as string;
}

MxWebsocket.instance.on_connection_change((conn: boolean) => {
if(conn) {
MxWebsocket.instance.rpc_call('mulex::RdbListSubkeys', [MxGenericType.str512('/system/backends/*/name')], 'generic').then((data) => {
const client_status: Array<string> = data.astype('stringarray');

client_status
.map((x) => {
// Return the client id
return extract_backend_name(x);
})
.forEach((x) => {
create_client_status(x).then((status: BackendStatus) => {
setBackends(x, () => status);
});
// MxWebsocket.instance.on_connection_change((conn: boolean) => {
// if(conn) {
onMount(() => {
MxWebsocket.instance.rpc_call('mulex::RdbListSubkeys', [MxGenericType.str512('/system/backends/*/name')], 'generic').then((data) => {
const client_status: Array<string> = data.astype('stringarray');

client_status
.map((x) => {
// Return the client id
return extract_backend_name(x);
})
.forEach((x) => {
create_client_status(x).then((status: BackendStatus) => {
setBackends(x, () => status);
});
});
}
});
});
});
// }
// });

const rdb = new MxRdb();

Expand Down
26 changes: 14 additions & 12 deletions frontend/src/components/ClientsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, For } from 'solid-js';
import { Component, For, onMount } from 'solid-js';
import { MxWebsocket } from '~/lib/websocket';
import { MxGenericType } from '~/lib/convert';
import { createMapStore } from '~/lib/rmap';
Expand Down Expand Up @@ -60,20 +60,22 @@ export const ClientsTable : Component = () => {

watchClients();

MxWebsocket.instance.on_connection_change((conn: boolean) => {
if(conn) {
MxWebsocket.instance.rpc_call('mulex::HttpGetClients', [], 'generic').then((data: MxGenericType) => {
const client_list = data.unpack(['str32', 'int64', 'uint64']);
// MxWebsocket.instance.on_connection_change((conn: boolean) => {
// if(conn) {
onMount(() => {
MxWebsocket.instance.rpc_call('mulex::HttpGetClients', [], 'generic').then((data: MxGenericType) => {
const client_list = data.unpack(['str32', 'int64', 'uint64']);

clientsActions.set(new Map<string, ClientInfo>());
for(const client of client_list) {
addClient(client);
}
});
clientsActions.set(new Map<string, ClientInfo>());
for(const client of client_list) {
addClient(client);
}
});

watchClients();
}
watchClients();
});
// }
// });

return (
<div>
Expand Down
34 changes: 18 additions & 16 deletions frontend/src/components/ResourcePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, createSignal } from 'solid-js';
import { Component, createSignal, onMount } from 'solid-js';
import { MxGaugeVertical } from '../api/GaugeVertical';
import { MxWebsocket } from '../lib/websocket';
import { MxGenericType } from '../lib/convert';
Expand All @@ -24,25 +24,27 @@ export const ResourcePanel : Component = () => {

watchKeys();

MxWebsocket.instance.on_connection_change((conn: boolean) => {
if(conn) {
MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/mem_total')], 'generic').then((res) => {
// To GB
setMemTotal(Number(res.astype('uint64')) / (1024 * 1024 * 1024));
});
// MxWebsocket.instance.on_connection_change((conn: boolean) => {
// if(conn) {
onMount(() => {
MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/mem_total')], 'generic').then((res) => {
// To GB
setMemTotal(Number(res.astype('uint64')) / (1024 * 1024 * 1024));
});

MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/mem_used')], 'generic').then((res) => {
// To GB
setMemUsed(Number(res.astype('uint64')) / (1024 * 1024 * 1024));
});
MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/mem_used')], 'generic').then((res) => {
// To GB
setMemUsed(Number(res.astype('uint64')) / (1024 * 1024 * 1024));
});

MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/cpu_usage')], 'generic').then((res) => {
setCpuUsage(res.astype('float64'));
});
MxWebsocket.instance.rpc_call('mulex::RdbReadValueDirect', [MxGenericType.str512('/system/metrics/cpu_usage')], 'generic').then((res) => {
setCpuUsage(res.astype('float64'));
});

watchKeys();
}
watchKeys();
});
// }
// });

return (
<div class="flex gap-5 place-content-center">
Expand Down
8 changes: 5 additions & 3 deletions network/mxhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ namespace mulex
std::string respath = serveDir + urlPath;
if(!std::filesystem::is_regular_file(respath))
{
LogError("[mxhttp] Failed to serve files. Resource <%s> not found.", respath.c_str());
res->writeStatus("404 Not Found")->end("<h1>404 - File Not Found<h1>");
return false;
urlPath = "/index.html";
respath = serveDir + urlPath;
// LogError("[mxhttp] Failed to serve files. Resource <%s> not found.", respath.c_str());
// res->writeStatus("404 Not Found")->end("<h1>404 - File Not Found<h1>");
// return false;
}

std::string data = HttpReadFileFromDisk(respath);
Expand Down

0 comments on commit c410257

Please sign in to comment.