feat: use a new ws implementation thats encapsulated
This commit is contained in:
parent
45537620a6
commit
5dd4c41291
13 changed files with 370 additions and 101 deletions
39
app/routes/api/agent.ts
Normal file
39
app/routes/api/agent.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { LoaderFunctionArgs } from 'react-router';
|
||||
import type { AppContext } from '~server/context/app';
|
||||
|
||||
export async function loader({
|
||||
request,
|
||||
context,
|
||||
}: LoaderFunctionArgs<AppContext>) {
|
||||
if (!context?.agentData) {
|
||||
return new Response(JSON.stringify({ error: 'Agent data unavailable' }), {
|
||||
status: 400,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const qp = new URLSearchParams(request.url.split('?')[1]);
|
||||
const nodeIds = qp.get('node_ids')?.split(',');
|
||||
if (!nodeIds) {
|
||||
return new Response(JSON.stringify({ error: 'No node IDs provided' }), {
|
||||
status: 400,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const entries = context.agentData.toJSON();
|
||||
const missing = nodeIds.filter((nodeID) => !entries[nodeID]);
|
||||
if (missing.length > 0) {
|
||||
await context.hp_agentRequest(missing);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(context.agentData), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue