diff options
author | Vika <vika@fireburn.ru> | 2021-05-09 16:22:50 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2021-05-09 16:22:50 +0300 |
commit | 31b01d56f0f7812ea0fbb45e5924ce4eb0de7383 (patch) | |
tree | 31eb8f3aa58872f2df3fdeebad23a9ce2f646d4f | |
parent | a5a1e44022019995c2646e30be6fc055a61714fc (diff) | |
download | kittybox-31b01d56f0f7812ea0fbb45e5924ce4eb0de7383.tar.zst |
Fixed Micropub client channels and sending payload
-rw-r--r-- | src/index.html | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/index.html b/src/index.html index 15ccfc0..1fc2a96 100644 --- a/src/index.html +++ b/src/index.html @@ -66,7 +66,6 @@ } async function query_channels() { - return ["main", "likes", "bookmarks"] const response = await fetch(form.action + "?q=config", { headers: { "Authorization": `Bearer ${form.elements.access_token.value}` @@ -86,10 +85,10 @@ const template = document.getElementById("channel_selector").content.cloneNode(true) const input = template.querySelector("input") const label = template.querySelector("label") - input.id = `channel_selector_option_${channel}` - input.value = channel + input.id = `channel_selector_option_${channel.uid}` + input.value = channel.uid label.for = input.id - label.innerHTML = `<code>${channel}</code>` + label.innerHTML = `<a href="${channel.uid}">${channel.name}</a>` channel_list.appendChild(template) }) @@ -98,13 +97,24 @@ form.onsubmit = async (event) => { event.preventDefault() console.log(JSON.stringify(construct_body(form))) - return - const response = await fetch(form.action, { - headers: { - "Authorization": `Bearer ${form.elements.access_token.value}` - }, - body: construct_body(form) - }) + try { + const response = await fetch(form.action, { + method: form.method, + headers: { + "Authorization": `Bearer ${form.elements.access_token.value}`, + "Content-Type": "application/json" + }, + body: JSON.stringify(construct_body(form)) + }) + if (response.status != 201 || response.status != 202) { + console.error(await response.json()); + } + if (response.headers.get("Location")) { + window.location.href = response.headers.get("Location"); + } + } catch (e) { + console.error(e) + } } </script> </head> |