2025-11-07 02:35:51 +00:00
|
|
|
const blogID = document.getElementById("blogpost").dataset.id;
|
|
|
|
|
const titleInput = document.getElementById("title");
|
2025-11-08 12:54:31 +00:00
|
|
|
const publishDateInput = document.getElementById("publish-date");
|
2025-11-08 14:00:29 +00:00
|
|
|
const setCurrentDateBtn = document.getElementById("set-current-date");
|
2025-11-07 02:35:51 +00:00
|
|
|
const descInput = document.getElementById("description");
|
|
|
|
|
const mdInput = document.getElementById("markdown");
|
|
|
|
|
const blueskyActorInput = document.getElementById("bluesky-actor");
|
2025-11-08 12:54:31 +00:00
|
|
|
const blueskyRecordInput = document.getElementById("bluesky-record");
|
|
|
|
|
const fediverseAccountInput = document.getElementById("fediverse-account");
|
|
|
|
|
const fediverseStatusInput = document.getElementById("fediverse-status");
|
2025-11-07 02:35:51 +00:00
|
|
|
const visInput = document.getElementById("visibility");
|
|
|
|
|
const saveBtn = document.getElementById("save");
|
|
|
|
|
const deleteBtn = document.getElementById("delete");
|
|
|
|
|
|
2025-11-08 14:00:29 +00:00
|
|
|
setCurrentDateBtn.addEventListener("click", () => {
|
|
|
|
|
let now = new Date;
|
|
|
|
|
now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
|
|
|
|
|
publishDateInput.value = now.toISOString().slice(0, 16);
|
|
|
|
|
saveBtn.disabled = false;
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-07 02:35:51 +00:00
|
|
|
saveBtn.addEventListener("click", () => {
|
|
|
|
|
fetch("/api/v1/blog/" + blogID, {
|
|
|
|
|
method: "PUT",
|
|
|
|
|
body: JSON.stringify({
|
2025-11-08 12:54:31 +00:00
|
|
|
title: titleInput.innerText,
|
|
|
|
|
publish_date: publishDateInput.value + ":00Z",
|
2025-11-07 02:35:51 +00:00
|
|
|
description: descInput.value,
|
|
|
|
|
markdown: mdInput.value,
|
2025-11-08 12:54:31 +00:00
|
|
|
bluesky: {
|
|
|
|
|
actor: blueskyActorInput.value,
|
|
|
|
|
record: blueskyRecordInput.value,
|
|
|
|
|
},
|
|
|
|
|
fediverse: {
|
|
|
|
|
account: fediverseAccountInput.value,
|
|
|
|
|
status: fediverseStatusInput.value,
|
|
|
|
|
},
|
2025-11-07 02:35:51 +00:00
|
|
|
visible: visInput.value === "true",
|
|
|
|
|
}),
|
|
|
|
|
headers: { "Content-Type": "application/json" }
|
|
|
|
|
}).then(res => {
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
res.text().then(error => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
alert("Failed to update blog post: " + error);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = location;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
deleteBtn.addEventListener("click", () => {
|
|
|
|
|
if (blogID != prompt(
|
|
|
|
|
"You are about to permanently delete " + blogID + ". " +
|
|
|
|
|
"This action is irreversible. " +
|
|
|
|
|
"Please enter \"" + blogID + "\" to continue.")) return;
|
|
|
|
|
fetch("/api/v1/blog/" + blogID, {
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
}).then(res => {
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
res.text().then(error => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
alert("Failed to delete blog post: " + error);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = "/admin";
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-08 12:54:31 +00:00
|
|
|
[titleInput, publishDateInput, descInput, mdInput, visInput,
|
|
|
|
|
blueskyActorInput, blueskyRecordInput,
|
|
|
|
|
fediverseAccountInput, fediverseStatusInput].forEach(input => {
|
|
|
|
|
input.addEventListener("change", () => {
|
|
|
|
|
saveBtn.disabled = false;
|
|
|
|
|
});
|
|
|
|
|
input.addEventListener("keypress", () => {
|
|
|
|
|
saveBtn.disabled = false;
|
|
|
|
|
});
|
2025-11-07 02:35:51 +00:00
|
|
|
});
|