API and web UI for posts, previews and post settings (phase 3, step 8)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m0s
CI / test (push) Successful in 2m53s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m0s
CI / test (push) Successful in 2m53s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
/api/v1/federation gains:
- GET /posts, DELETE /posts/{id}: manage your own posts from the UI.
- GET /preview/weekly: what the weekly summary would say right now, for
the week still in progress - never posted or stored. Backed by a new
weekly.preview() and schedule.current_week_start().
- GET /profiles/{username}/posts/{post_uuid} (public, unauthenticated):
backs the UI's post page, which can't itself speak ActivityPub.
Settings gain timezone/post_weekly_summary/post_milestones, already
present in sharing.EDITABLE since phase 3 step 2 but never added to
SharingSettingsSchema, so the API was silently dropping them from
responses. timezone validates against the same is_valid_timezone() the
service layer uses, with a dedicated marshmallow validator.
Fixed a real gap found while wiring the post page: ids.post_page_url()
took a username but never put it in the URL, so post.html would have
had no way to know whose post to look up. It's now ?u=<username>&id=<uuid>.
Sharing page gets a "What to post" section (weekly summary and
milestones toggles, a timezone field with a browser-supplied IANA
datalist where Intl.supportedValuesOf exists, and a live preview).
New posts.html lists a user's posts with delete (mirroring followers.js's
confirm-before-destructive-action pattern); new post.html is the public
landing page for a post's `url`, reached by browsers redirected from the
raw ActivityPub endpoint.
Verified by hand against a local dev server and a real browser: sign in,
enable sharing, preview and publish, list and delete a post, and follow
the ActivityPub redirect through to the public post page and its 404
after deletion - fixed one bug found this way (the preview box was
collapsing the summary's line breaks).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
d4f3607eef
commit
0acce9b948
16 files changed
+865
-8
No files matched your search
@@ -919,6 +919,22 @@ input {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.preview-box {
|
||||
padding: 1rem 1.25rem;
|
||||
border-radius: var(--radius-control);
|
||||
background: var(--paper-raised);
|
||||
border: 1px solid var(--rule);
|
||||
margin: 0.75rem 0 1.25rem;
|
||||
}
|
||||
|
||||
.preview-box p {
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
|
||||
.preview-box p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.field textarea {
|
||||
min-height: 5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { api } from "./api.js";
|
||||
import { errorBox, formatDate, h, replace } from "./dom.js";
|
||||
import { publicPage } from "./layout.js";
|
||||
|
||||
const root = document.getElementById("post");
|
||||
const params = new URLSearchParams(location.search);
|
||||
const username = params.get("u") ?? "";
|
||||
const postId = params.get("id") ?? "";
|
||||
|
||||
// A public page: never sends visitors to sign in.
|
||||
publicPage();
|
||||
|
||||
try {
|
||||
const post = await api(
|
||||
`/federation/profiles/${encodeURIComponent(username)}/posts/${encodeURIComponent(postId)}`,
|
||||
{ auth: false },
|
||||
);
|
||||
document.title = `${post.display_name} · Scrobbler`;
|
||||
replace(
|
||||
root,
|
||||
h(
|
||||
"p",
|
||||
{ class: "muted" },
|
||||
h("a", { href: post.profile_url }, post.display_name),
|
||||
` · ${post.handle}`,
|
||||
),
|
||||
h("p", { style: "white-space: pre-line" }, post.text),
|
||||
h("p", { class: "muted", title: formatDate(post.created_at) }, `Posted ${formatDate(post.created_at)}`),
|
||||
);
|
||||
} catch (error) {
|
||||
replace(
|
||||
root,
|
||||
error.status === 404
|
||||
? [
|
||||
h("h1", {}, "No post here"),
|
||||
h("p", { class: "lede" }, "This post doesn't exist, isn't public, or has been deleted."),
|
||||
]
|
||||
: errorBox(error.message),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { api } from "./api.js";
|
||||
import { errorBox, formatDate, h, replace, timeAgo } from "./dom.js";
|
||||
import { signedInPage } from "./layout.js";
|
||||
|
||||
const messages = document.getElementById("messages");
|
||||
const KIND_LABEL = { weekly: "Weekly summary", milestone: "Milestone" };
|
||||
const VISIBILITY_LABEL = { followers: "Followers only", unlisted: "Unlisted", public: "Public" };
|
||||
|
||||
await signedInPage("sharing.html");
|
||||
await refresh();
|
||||
|
||||
async function refresh() {
|
||||
let posts;
|
||||
try {
|
||||
posts = await api("/federation/posts");
|
||||
} catch (error) {
|
||||
replace(
|
||||
messages,
|
||||
error.status === 404
|
||||
? h("p", { class: "notice" }, "This server doesn't share to the fediverse.")
|
||||
: errorBox(error.message),
|
||||
);
|
||||
return;
|
||||
}
|
||||
replace(
|
||||
document.getElementById("posts"),
|
||||
posts.length
|
||||
? posts.map(postRow)
|
||||
: h(
|
||||
"li",
|
||||
{ class: "empty" },
|
||||
"Nothing posted yet. Weekly summaries and milestones appear here once you're sharing.",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function postRow(post) {
|
||||
const actions = h("div", { class: "confirm" });
|
||||
const reset = () =>
|
||||
replace(
|
||||
actions,
|
||||
post.deleted_at
|
||||
? null
|
||||
: h("button", { type: "button", class: "button button-quiet", onclick: askDelete }, "Delete"),
|
||||
);
|
||||
const askDelete = () =>
|
||||
replace(
|
||||
actions,
|
||||
h("span", { class: "muted" }, "Delivered followers keep a copy; this only removes it from their timeline."),
|
||||
h("button", { type: "button", class: "button button-danger", onclick: doDelete }, "Delete post"),
|
||||
h("button", { type: "button", class: "button button-quiet", onclick: reset }, "Cancel"),
|
||||
);
|
||||
const doDelete = async () => {
|
||||
try {
|
||||
await api(`/federation/posts/${post.id}`, { method: "DELETE" });
|
||||
replace(messages, h("p", { class: "notice notice-ok", role: "status" }, "Post deleted."));
|
||||
} catch (error) {
|
||||
replace(messages, errorBox(error.message));
|
||||
}
|
||||
await refresh();
|
||||
};
|
||||
reset();
|
||||
return h(
|
||||
"li",
|
||||
{},
|
||||
h(
|
||||
"div",
|
||||
{ class: "row-head" },
|
||||
h("span", { class: "row-title" }, KIND_LABEL[post.kind] ?? post.kind),
|
||||
actions,
|
||||
),
|
||||
h("p", { style: "white-space: pre-line" }, post.text),
|
||||
h(
|
||||
"p",
|
||||
{ class: "muted", title: formatDate(post.created_at) },
|
||||
`${VISIBILITY_LABEL[post.visibility] ?? post.visibility} · Posted ${timeAgo(post.created_at)}`,
|
||||
post.deleted_at ? ` · Deleted ${timeAgo(post.deleted_at)}` : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
+44
-1
@@ -5,8 +5,20 @@ import { signedInPage } from "./layout.js";
|
||||
const form = document.getElementById("sharing");
|
||||
const messages = document.getElementById("messages");
|
||||
const handlePanel = document.getElementById("handle-panel");
|
||||
const FIELDS = ["enabled", "visibility", "manually_approves_followers", "discoverable", "indexable", "display_name", "bio"];
|
||||
const FIELDS = [
|
||||
"enabled",
|
||||
"visibility",
|
||||
"manually_approves_followers",
|
||||
"discoverable",
|
||||
"indexable",
|
||||
"post_weekly_summary",
|
||||
"post_milestones",
|
||||
"timezone",
|
||||
"display_name",
|
||||
"bio",
|
||||
];
|
||||
|
||||
fillTimezoneChoices();
|
||||
await signedInPage("sharing.html");
|
||||
|
||||
let settings;
|
||||
@@ -26,6 +38,34 @@ if (settings) {
|
||||
form.hidden = false;
|
||||
form.elements.enabled.addEventListener("change", () => showHandle(form.elements.enabled.checked));
|
||||
form.addEventListener("submit", save);
|
||||
document.getElementById("preview-weekly").addEventListener("click", previewWeekly);
|
||||
}
|
||||
|
||||
// Free text (validated server-side), with autocomplete from the browser's own IANA list
|
||||
// when it can supply one; a picker where that's available, a plain field otherwise.
|
||||
function fillTimezoneChoices() {
|
||||
if (typeof Intl.supportedValuesOf !== "function") return;
|
||||
const datalist = document.getElementById("timezones");
|
||||
replace(datalist, Intl.supportedValuesOf("timeZone").map((zone) => h("option", { value: zone })));
|
||||
}
|
||||
|
||||
async function previewWeekly() {
|
||||
const box = document.getElementById("weekly-preview");
|
||||
const button = document.getElementById("preview-weekly");
|
||||
button.disabled = true;
|
||||
try {
|
||||
const preview = await api("/federation/preview/weekly");
|
||||
replace(
|
||||
box,
|
||||
h("p", { class: "muted" }, "What this week's summary would say so far:"),
|
||||
h("p", { style: "white-space: pre-line" }, preview.text),
|
||||
);
|
||||
box.hidden = false;
|
||||
} catch (error) {
|
||||
replace(messages, errorBox(error.message));
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function fill(values) {
|
||||
@@ -107,6 +147,9 @@ async function save(event) {
|
||||
manually_approves_followers: form.elements.manually_approves_followers.checked,
|
||||
discoverable: form.elements.discoverable.checked,
|
||||
indexable: form.elements.indexable.checked,
|
||||
post_weekly_summary: form.elements.post_weekly_summary.checked,
|
||||
post_milestones: form.elements.post_milestones.checked,
|
||||
timezone: form.elements.timezone.value.trim() || "UTC",
|
||||
display_name: form.elements.display_name.value.trim() || null,
|
||||
bio: form.elements.bio.value.trim() || null,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Post · Scrobbler</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='%231c2330'/%3E%3Ccircle cx='8' cy='8' r='3.5' fill='%23f2a541'/%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="config.js"></script>
|
||||
<script type="module" src="js/post.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="site-header" id="site-header"></header>
|
||||
<main id="main">
|
||||
<div class="auth" id="post" aria-live="polite"></div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,21 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Posts · Scrobbler</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='%231c2330'/%3E%3Ccircle cx='8' cy='8' r='3.5' fill='%23f2a541'/%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="config.js"></script>
|
||||
<script type="module" src="js/posts.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="site-header" id="site-header"></header>
|
||||
<main id="main">
|
||||
<h1 class="page-title">Posts</h1>
|
||||
<p class="lede">Weekly summaries and milestones sent to the fediverse. <a href="sharing.html">Sharing settings</a></p>
|
||||
<div id="messages"></div>
|
||||
<ul class="rows" id="posts"></ul>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -60,6 +60,29 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="choices">
|
||||
<legend>What to post</legend>
|
||||
<div class="choice">
|
||||
<input type="checkbox" id="post_weekly_summary" name="post_weekly_summary">
|
||||
<label for="post_weekly_summary"><strong>Weekly summary</strong><span class="muted">Your play count and top artist, once a week.</span></label>
|
||||
</div>
|
||||
<div class="choice">
|
||||
<input type="checkbox" id="post_milestones" name="post_milestones">
|
||||
<label for="post_milestones"><strong>Milestones</strong><span class="muted">Scrobble-count, artist-plays and top-10 milestones as you reach them.</span></label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="timezone">Time zone</label>
|
||||
<input id="timezone" name="timezone" list="timezones" autocomplete="off">
|
||||
<datalist id="timezones"></datalist>
|
||||
<span class="hint">Decides when your week ends for the weekly summary.</span>
|
||||
</div>
|
||||
<div class="button-row">
|
||||
<button class="button button-quiet" type="button" id="preview-weekly">Preview this week's summary</button>
|
||||
</div>
|
||||
<div class="preview-box" id="weekly-preview" hidden></div>
|
||||
<p class="muted"><a href="posts.html">See your posts</a></p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="choices">
|
||||
<legend>Profile</legend>
|
||||
<div class="field">
|
||||
|
||||
Reference in new issue
Block a user