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
@@ -11,7 +11,7 @@ import logging
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import publishing
|
||||
from scrobbler.federation import publishing, sharing
|
||||
from scrobbler.federation.models import FederationSettings
|
||||
from scrobbler.federation.protocol import content, schedule
|
||||
from scrobbler.services import accounts, stats
|
||||
@@ -83,6 +83,22 @@ def check_and_post(settings: FederationSettings, now_utc: datetime) -> str:
|
||||
return "posted" if post is not None else "already_posted" # lost a race with another pass
|
||||
|
||||
|
||||
def preview(user_id: int, now_utc: datetime | None = None) -> tuple[str, str] | None:
|
||||
"""What a weekly summary would say right now, for the week still in progress. Never
|
||||
stored or posted: for the Sharing page's live preview. None if the account is gone."""
|
||||
user = accounts.get_user(user_id)
|
||||
if user is None:
|
||||
return None
|
||||
settings = sharing.settings_for(user_id)
|
||||
tz = schedule.resolve_timezone(settings.timezone)
|
||||
now_utc = now_utc or datetime.now(UTC)
|
||||
start = schedule.current_week_start(now_utc, tz)
|
||||
count = stats.scrobble_count_between(user, start, now_utc)
|
||||
top_artists = stats.top_artists_between(user, start, now_utc, limit=TOP_ARTISTS)
|
||||
top_tracks = stats.top_tracks_between(user, start, now_utc, limit=1)
|
||||
return build_content(count, top_artists, top_tracks)
|
||||
|
||||
|
||||
def check_all(now_utc: datetime | None = None) -> None:
|
||||
"""Worker task (periodic): check every sharing user with weekly summaries on. One
|
||||
user's failure is logged and doesn't stop the rest from being checked."""
|
||||
|
||||
Reference in new issue
Block a user