feat: did some stuff
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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, });
|
||||
}
|
@ -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 });
|
||||
}
|
||||
}
|
@ -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);
|
@ -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" } });
|
Reference in New Issue
Block a user