upload.mjs
850 Bytes
// spike, one-off: upload a local file to H3 Console's /v1/assets endpoint.
// This is the undocumented endpoint found by reading the console's own
// front-end JS (its own upload widgets use it) -- see H3-CONSOLE.md update.
process.loadEnvFile(new URL("../../.env", import.meta.url));
const BASE = process.env.H3_CONSOLE_BASE;
const TOKEN = process.env.H3_CONSOLE_TOKEN;
const filePath = process.argv[2];
if (!filePath) { console.error("usage: node upload.mjs <path>"); process.exit(1); }
const fs = await import("node:fs");
const buf = fs.readFileSync(filePath);
const fd = new FormData();
fd.append("file", new Blob([buf]), filePath.split("/").pop());
const res = await fetch(`${BASE}/v1/assets`, {
method: "POST",
headers: { Authorization: `Bearer ${TOKEN}` },
body: fd,
});
const text = await res.text();
console.log(res.status, text);