feat: improve hash functions
This commit is contained in:
@ -1,19 +1,8 @@
|
||||
export async function getNodeWrapper(id: `${string}/${string}/${string}`) {
|
||||
import { createWasmWrapper } from "@nodes/utils"
|
||||
|
||||
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)}#${id}${Math.random().toString().slice(2)}`);
|
||||
|
||||
return wasmWrapper;
|
||||
}
|
||||
|
||||
export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise<WebAssembly.Instance> {
|
||||
export async function getNodeWasm(id: `${string}/${string}/${string}`) {
|
||||
|
||||
const wasmResponse = await fetch(`/n/${id}/wasm`);
|
||||
|
||||
@ -21,13 +10,12 @@ export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise<
|
||||
throw new Error(`Failed to load node ${id}`);
|
||||
}
|
||||
|
||||
const wasmWrapper = await getNodeWrapper(id);
|
||||
|
||||
const wrapper = createWasmWrapper();
|
||||
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 instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wrapper });
|
||||
wrapper.setInstance(instance)
|
||||
|
||||
return wasmWrapper;
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +23,8 @@ export async function getNode(id: `${string}/${string}/${string}`) {
|
||||
|
||||
const wrapper = await getNodeWasm(id);
|
||||
|
||||
const outputs = wrapper.get_outputs();
|
||||
const rawInputs = wrapper.get_input_types();
|
||||
const outputs = wrapper?.get_outputs?.() || [];
|
||||
const rawInputs = wrapper.get_inputs();
|
||||
try {
|
||||
const inputTypes = JSON.parse(rawInputs);
|
||||
return { id, outputs, inputs: inputTypes }
|
||||
|
@ -1,19 +0,0 @@
|
||||
import type { RequestHandler } from "./$types";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
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" } });
|
||||
}
|
Reference in New Issue
Block a user