feat: did some stuff

This commit is contained in:
2024-04-05 18:03:23 +02:00
parent 8035b26750
commit b3780fdf96
34 changed files with 355 additions and 54 deletions

View File

@ -17,5 +17,5 @@
{:else if input.type === "boolean"}
<Checkbox bind:value />
{:else if input.type === "select"}
<Select labels={input.labels} bind:value />
<Select bind:value labels={input.labels} />
{/if}

View File

@ -7,3 +7,13 @@
<input type="number" bind:value {min} {max} {step} />
<style>
input {
background: var(--background-color-lighter);
color: var(--text-color);
font-family: var(--font-family);
padding: 0.8em 1em;
border-radius: 5px;
border: none;
}
</style>

View File

@ -1,16 +1,25 @@
export async function getNodeWrapper(id: `${string}/${string}/${string}`) {
let wrapperCode = await (await fetch(`/${id}/wrapper`)).text();
const wrapperReponse = await fetch(`/n/${id}/wrapper`);
if (!wrapperReponse.ok) {
throw new Error(`Failed to load node ${id}`);
}
let wrapperCode = await wrapperReponse.text();
wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return;
wasm = val;`);
const wasmWrapper = await import(/*vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}`);
const wasmWrapper = await import(/*@vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}`);
return wasmWrapper;
}
export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise<WebAssembly.Instance> {
const wasmResponse = await fetch(`/${id}/wasm`);
const wasmResponse = await fetch(`/n/${id}/wasm`);
if (!wasmResponse.ok) {
throw new Error(`Failed to load node ${id}`);
}
const wasmWrapper = await getNodeWrapper(id);

View File

@ -1,19 +0,0 @@
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";
export const GET: RequestHandler = async function GET({ fetch, params }) {
const wasmResponse = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`);
let wrapperCode = await (await fetch(`/${params.user}/${params.collection}/${params.node}/wrapper`)).text();
wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return;
wasm = val;`);
const wasmWrapper = await import(`data:text/javascript;base64,${btoa(wrapperCode)}`);
const module = new WebAssembly.Module(await wasmResponse.arrayBuffer());
const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wasmWrapper });
wasmWrapper.__wbg_set_wasm(instance.exports);
const id = wasmWrapper.get_id();
const outputs = wasmWrapper.get_outputs();
const inputTypes = JSON.parse(wasmWrapper.get_input_types());
return json({ id, outputs, inputs: inputTypes, });
}

View File

@ -0,0 +1,17 @@
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";
import { getNode } from "$lib/registry";
export const GET: RequestHandler = async function GET({ fetch, params }) {
globalThis.fetch = fetch;
const nodeId = `${params.user}/${params.collection}/${params.node}` as const;
try {
const node = await getNode(nodeId);
return json(node);
} catch (err) {
console.log(err)
return new Response("Not found", { status: 404 });
}
}

View File

@ -6,6 +6,12 @@ export const GET: RequestHandler = async function GET({ fetch, params }) {
const filePath = path.resolve(`../../nodes/${params.user}/${params.collection}/${params.node}/pkg/index_bg.wasm`);
try {
await fs.access(filePath);
} catch (e) {
return new Response("Not found", { status: 404 });
}
const file = await fs.readFile(filePath);
const bytes = new Uint8Array(file);

View File

@ -6,6 +6,13 @@ export const GET: RequestHandler = async function GET({ params }) {
const filePath = path.resolve(`../../nodes/${params.user}/${params.collection}/${params.node}/pkg/index_bg.js`);
try {
await fs.access(filePath);
} catch (e) {
console.log("Not Found", filePath);
return new Response("Not found", { status: 404 });
}
const file = await fs.readFile(filePath);
return new Response(file, { status: 200, headers: { "Content-Type": "text/javascript" } });

View File

@ -21,9 +21,6 @@ pub fn unwrap_string(val: JsValue) -> String {
return val.as_string().unwrap();
}
pub fn evaluate_parameter(val: JsValue) -> String {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_string().unwrap();
pub fn evaluate_parameter(_val: String) -> i32 {
return 2;
}

View File

@ -34,7 +34,7 @@ export type NodeType = {
meta?: {
title?: string;
},
execute?: (inputs: Record<string, string | number | boolean>) => unknown;
execute?: (...args: (string | number | boolean)[]) => unknown;
}
export type Socket = {

View File

@ -26,6 +26,7 @@ type NodeInputSelect = {
type DefaultOptions = {
internal?: boolean;
external?: boolean;
title?: string;
}