nodes/store/bin/upload.ts
Max Richter 0c9a9269c4
Some checks failed
Deploy to GitHub Pages / build_site (push) Failing after 6s
feat: some shit
2024-12-18 17:26:24 +01:00

65 lines
1.5 KiB
TypeScript

import * as path from "jsr:@std/path";
const arg = Deno.args[0];
const base = arg.startsWith("/") ? arg : path.join(Deno.cwd(), arg);
const dirs = Deno.readDir(base);
type Node = {
user: string;
system: string;
id: string;
path: string;
};
const nodes: Node[] = [];
for await (const dir of dirs) {
if (dir.isDirectory) {
const userDir = path.join(base, dir.name);
for await (const userName of Deno.readDir(userDir)) {
if (userName.isDirectory) {
const nodeSystemDir = path.join(userDir, userName.name);
for await (const nodeDir of Deno.readDir(nodeSystemDir)) {
if (nodeDir.isDirectory && !nodeDir.name.startsWith(".")) {
const wasmFilePath = path.join(
nodeSystemDir,
nodeDir.name,
"pkg",
"index_bg.wasm",
);
nodes.push({
user: dir.name,
system: userName.name,
id: nodeDir.name,
path: wasmFilePath,
});
}
}
}
}
}
}
async function postNode(node: Node) {
const wasmContent = await Deno.readFile(node.path);
const url = `http://localhost:8000/v1/nodes`;
const res = await fetch(url, {
method: "POST",
body: wasmContent,
});
if (res.ok) {
console.log(`Uploaded ${node.id}`);
} else {
const text = await res.text();
console.log(`Failed to upload ${node.id}: ${text}`);
}
}
for (const node of nodes) {
await postNode(node);
}