File size: 1,580 Bytes
431b4de
081a4b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431b4de
081a4b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431b4de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const c = console;
// const ENDPOINT = "https://huggingface.co";
const ENDPOINT = "http://localhost:5564";
async function whoami(token) {
    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, repoId, repoType) {
    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");
    });
});