feat: some stuff
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m0s

This commit is contained in:
max_richter 2024-12-20 15:55:45 +01:00
parent 15ff1cc52d
commit dc46c4b64c
Signed by: max
GPG Key ID: 51973802EF3F77C5
2 changed files with 16 additions and 25 deletions

View File

@ -45,6 +45,7 @@ async function postNode(node: Node) {
const wasmContent = await Deno.readFile(node.path); const wasmContent = await Deno.readFile(node.path);
const url = `http://localhost:8000/nodes`; const url = `http://localhost:8000/nodes`;
// const url = "https://node-store.app.max-richter.dev/nodes";
const res = await fetch(url, { const res = await fetch(url, {
method: "POST", method: "POST",

View File

@ -58,34 +58,16 @@ async function getNodeByVersion(
const [id, version] = nodeId.replace(/\.wasm$/, "").split("@"); const [id, version] = nodeId.replace(/\.wasm$/, "").split("@");
console.log({ user, system, id, version }); console.log({ user, system, id, version });
if (version) { if (version) {
return service.getNodeVersionWasm( return service.getNodeVersionWasm(user, system, id, version);
user,
system,
id,
version,
);
} else { } else {
return service.getNodeWasmById( return service.getNodeWasmById(user, system, id);
user,
system,
id,
);
} }
} else { } else {
const [id, version] = nodeId.replace(/\.json$/, "").split("@"); const [id, version] = nodeId.replace(/\.json$/, "").split("@");
if (!version) { if (!version) {
return service.getNodeDefinitionById( return service.getNodeDefinitionById(user, system, id);
user,
system,
id,
);
} else { } else {
return await service.getNodeVersion( return await service.getNodeVersion(user, system, id, version);
user,
system,
id,
version,
);
} }
} }
} }
@ -170,7 +152,10 @@ nodeRouter.openapi(
console.log("Get Nodes by System", { user, system }); console.log("Get Nodes by System", { user, system });
try { try {
const nodes = await service.getNodesBySystem(user, system); const nodes = await service.getNodesBySystem(user, system);
return c.json(nodes); return c.json({
id: `${user}/${system}`,
nodes: nodes.map((n) => ({ id: n.id.split("@")[0] })),
});
} catch (error) { } catch (error) {
if (error instanceof CustomError) { if (error instanceof CustomError) {
throw new HTTPException(error.status, { message: error.message }); throw new HTTPException(error.status, { message: error.message });
@ -201,8 +186,13 @@ nodeRouter.openapi(
const nodeId = c.req.param("nodeId.json").replace(/\.json$/, ""); const nodeId = c.req.param("nodeId.json").replace(/\.json$/, "");
console.log("Get Node by Id", { user, system, nodeId }); console.log("Get Node by Id", { user, system, nodeId });
try { try {
const node = await service.getNodeDefinitionById(user, system, nodeId); const res = await getNodeByVersion(user, system, nodeId);
return c.json(node); if (res instanceof ArrayBuffer) {
c.header("Content-Type", "application/wasm");
return c.body(res);
} else {
return c.json(res);
}
} catch (error) { } catch (error) {
if (error instanceof CustomError) { if (error instanceof CustomError) {
throw new HTTPException(error.status, { message: error.message }); throw new HTTPException(error.status, { message: error.message });