about summary refs log tree commit diff
path: root/kittybox-rs/companion-lite/micropub_api.js
blob: 402c075cadf514bc70f4ddeb55d71e07017f3bc2 (plain) (blame)
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
export async function query_channels(endpoint, token) {
    const response = await fetch(endpoint + "?q=config", {
        headers: {
            "Authorization": `Bearer ${get_token()}`
        }
    })

    const config = await response.json();

    return config["channels"]
}

export async function submit(endpoint, token, mf2) {
    try {
        const response = await fetch(endpoint, {
            method: "POST",
            headers: {
                "Authorization": `Bearer ${token}`,
                "Content-Type": "application/json"
            },
            body: JSON.stringify(mf2)
        })


        if (response.status != 201 || response.status != 202) {
            let err = await response.json();
            console.error("Micropub error!", err);
            
            return err;
        } else {
            return {
                "location": response.headers.get("Location")
            }
        }
    } catch (e) {
        console.error("Network error!", e)
        throw e
    }
}

// Local Variables:
// js-indent-level: 4
// End: