const c = console; // const ENDPOINT = "https://huggingface.co"; const ENDPOINT = "http://localhost:5564"; async function whoami(token: string): Promise<{ name: string }> { const path = `${ENDPOINT}/api/whoami-v2`; const res = await fetch(path, { headers: { Authorization: `Bearer ${token}`, Origin: `127.0.0.1:8000` } }); return await res.json(); } async function createRepo( token: string, repoId: string, repoType: "model" | "dataset" | "space", ): Promise { const path = `${ENDPOINT}/api/repos/create`; const res = await fetch(path, { method: "POST", headers: { Authorization: `Bearer ${token}`, }, body: JSON.stringify({ name: repoId, type: repoType, }) }); return (await res.json())["url"]; } window.addEventListener("load", function () { const tokenEl = document.querySelector("#token")!; const repoNameEl = document.querySelector("#repo_name")!; const button = document.querySelector("#submit")!; const output = document.querySelector("#logs")!; button.addEventListener("click", async function () { const token = tokenEl.value; const repoName = repoNameEl.value; if (!token || !repoName) { alert("You need a token and a repo name"); return; } button.setAttribute("disabled", "disabled"); try { // c.log(await createRepo(token, repoName, "model")); c.log(await whoami(token)); } catch (err) { output.append(err); } button.removeAttribute("disabled"); }); });