Phase 1, part 1: fetch, write and publish posts from the web app
Brings back posting, which Phase 0 removed with the terminal interface. - Content page: per inventory entry, fetch its X account, X hashtag search, YouTube channel and RSS/Atom feeds (new), then select, dismiss or restore the fetched items, which are kept in the database. - Writing: one AI call returns a draft per channel (X and LinkedIn), prompted from the company profile, the entry's relationship, talking points and mention policy, and each channel's rules. Fetched text is quoted as untrusted. An over-long X draft gets one request to shorten. - Drafts page: edit with a live length counter that counts like X, then publish each draft on its own. A draft is claimed before posting so it can't go out twice; failures are kept on the draft for a retry; X tokens are refreshed and saved. - Migration 2 adds content_items and drafts, and turns queued posts into drafts for the platforms they hadn't reached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,10 +41,65 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Ask before submitting a form with data-confirm.
|
||||
// Ask before submitting a form with data-confirm. A form with data-busy
|
||||
// shows that text on the button that submitted it, and can't be sent twice,
|
||||
// while a slow request (fetching, writing, publishing) runs. With
|
||||
// data-busy-on, only that button's value counts as slow.
|
||||
document.addEventListener("submit", function (e) {
|
||||
var msg = e.target.getAttribute("data-confirm");
|
||||
if (msg && !window.confirm(msg)) e.preventDefault();
|
||||
var form = e.target;
|
||||
var msg = form.getAttribute("data-confirm");
|
||||
if (msg && !window.confirm(msg)) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
var busy = form.getAttribute("data-busy");
|
||||
if (!busy) return;
|
||||
var btn = e.submitter;
|
||||
var only = form.getAttribute("data-busy-on");
|
||||
if (only && (!btn || btn.value !== only)) return;
|
||||
if (form.dataset.sending) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
form.dataset.sending = "1";
|
||||
if (btn) {
|
||||
// A disabled button isn't submitted, so carry its value in a hidden field.
|
||||
if (btn.name) {
|
||||
var keep = document.createElement("input");
|
||||
keep.type = "hidden";
|
||||
keep.name = btn.name;
|
||||
keep.value = btn.value;
|
||||
form.appendChild(keep);
|
||||
}
|
||||
btn.textContent = busy;
|
||||
setTimeout(function () { btn.disabled = true; }, 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Live length of a post: <textarea data-count="x|linkedin" data-limit
|
||||
// data-reserve> followed by its <p class="count">. X counts most characters
|
||||
// outside Latin, punctuation and symbols as 2, like the server does.
|
||||
function weighted(s) {
|
||||
var n = 0;
|
||||
for (var ch of s) {
|
||||
var c = ch.codePointAt(0);
|
||||
if (c <= 0x10ff || (c >= 0x2000 && c <= 0x200d) || (c >= 0x2010 && c <= 0x201f) || (c >= 0x2032 && c <= 0x2037)) n += 1;
|
||||
else n += 2;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
function count(area) {
|
||||
var out = document.getElementById(area.getAttribute("aria-describedby"));
|
||||
if (!out) return;
|
||||
var limit = parseInt(area.getAttribute("data-limit"), 10);
|
||||
var reserve = parseInt(area.getAttribute("data-reserve") || "0", 10);
|
||||
var text = area.value.trim();
|
||||
var n = area.getAttribute("data-count") === "x" ? weighted(text) + reserve : Array.from(text).length;
|
||||
out.textContent = n + " / " + limit + (reserve ? " including the link" : "");
|
||||
out.classList.toggle("over", n > limit);
|
||||
}
|
||||
document.addEventListener("input", function (e) {
|
||||
if (e.target.matches("textarea[data-count]")) count(e.target);
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", syncProvider);
|
||||
|
||||
Reference in New Issue
Block a user