Подкасты в веб-плеере: хранилище PostgreSQL, обновление RSS, прокси, UI и воспроизведение (MR-W2) #11

Open
sanapach wants to merge 46 commits from sanapach/furumi-web:podcasts/web into master
pull from: sanapach/furumi-web:podcasts/web
46 Commits
Author SHA1 Message Date
sanapachandClaude Opus 5.5 4fef5c2bd4 Format the refresh runner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 7aa2253e00 Document the proxy head check and the playback handoff details
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 7214c57624 Save the failed session's position before preparing the episode again
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 056c53a808 Record the listening after a handoff that did not go through
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 f87d70c593 Bound the episodes the browser can add outside the account's feeds
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 0aead73135 Let one account use the whole refresh run when others have nothing due
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 62141c0840 Answer blocked host names like unreachable ones
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 402ad0a03a Accept a bare MPEG frame only when its whole header is valid
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 2549e9e50d Sniff the file head separately when the browser probes a short range
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 404d9cc175 Note the podcast review fixes in the changelog
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 9b43a25d8f Resume episodes from the progress register and keep saving after a takeover
A reload or a Play after a pause continues from the register instead of
this page's saved position, a seek during preparation is kept, a player
that keeps listening after being superseded writes again as a new
session, a player that loses the playback role records its listening,
marking the loaded episode closes its session, and Prev no longer
resets an episode to 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 4050214912 Report the progress register in podcast playback answers
The player checks it before continuing a paused session and resumes
from it after a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 fc0befc4a3 Pass generic proxy responses through only when they start like audio
The enclosure type of a feed or of a client-sent episode reference no
longer makes an application/octet-stream response acceptable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 cfebe1898f Bound user-started feed and audio requests per account
Feed downloads and proxy streams have per-account and server-wide
limits, new subscriptions stop at 1000 per account, and scheduled
refreshes take accounts in turns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 2eb27cfe77 Accept only application/json bodies on podcast endpoints
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 c51a9af9e5 Keep network details and URLs out of podcast fetch errors
Users see the kind of failure only; resolved addresses and transport
details go to the logs, without URLs. Feed and audio requests are
limited to the web ports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 99b2935b35 Compare podcast alias sets in byte order on any collation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 047fc9e887 Keep the podcast API's 401 path out of a large Result
Clippy flagged the helper that returned the 401 response as its error
variant (result_large_err); it now returns the account id as an Option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 bf6981948a Refresh podcast counters when an episode changes status
Playing, completing or restarting an episode from the player updated
its row but left the unplayed and in-progress counters of the podcast
page as they were loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 592d61dd58 Release 0.14.0 with podcasts in the web player
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 ff10f4354d Document podcasts in the web player
README and the administration guide describe the Podcasts section,
resume and completion, handoffs, unsubscribing, what stays private and
what the publisher sees, and the security model of the optional audio
proxy. The development guide lists the endpoints, how the player
writes progress and the node tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 9d1a46c9fe Add a podcasts section to the web player
The sidebar gets Podcasts: add an RSS feed (fetched by the server; a
refused or broken feed shows why), the subscriptions with unplayed
counts and the last fetch error, and a podcast page with seasons, an
episode search, played/sort filters, paging, manual refresh and
unsubscribe (the confirmation says progress and history are kept), or
subscribe again. Episodes show the saved position, the time left and a
played mark, with Play/Resume, Start over, Mark played, Mark unplayed
and Add to queue; Jam guests cannot add episodes. The podcast page also
lists the recent listening history.

The queue labels episodes, the podcast name of the current episode
opens its page, like and share are hidden for episodes, and the player
bar shows when an episode is loading or cannot be played or resumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 3ebfc45abb Play podcast episodes in the web player
Episodes in the queue are no longer skipped. The player asks the
podcast API for the audio source and the resume position, plays the
publisher URL (or the same-origin proxy when the administrator enabled
it and the direct URL fails or is http:// on an https:// page) and
seeks before it starts, so it never reports a resumed episode that
plays from elsewhere: a server that cannot seek to the saved position
shows that and keeps the position until the user plays from the start.

Progress follows the contract: Play starts a listening session as an
explicit action above the handed-off generation, checkpoints go out
every 20 s and on pause, a seek is an explicit action, the end of the
stream completes the episode, and a stop, a page hide (beacon) or a
handoff saves the final position. Writes of a session run one after
another in the background; a superseded session stops writing, and a
device that loses the playback role ends its session without a report.
Reports always carry the position of their own episode.

Jam placeholders stay unplayable and episodes stay private for Jam
rules. A podcasts store holds the list, the podcast page and the
explicit episode actions for the UI of the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 2c551c5b71 Carry the newest progress generation in outgoing playback states
A browser queue item keeps the handoff hint it arrived with, which is
older than the checkpoints this account has written since. Every
podcast episode in a playback state the web sends to a trusted device
now carries max(hint, register generation), so the device taking over
writes its explicit action above everything the web has seen. Which
state reads the resume position from the register is decided on the
converted queue, so the bridge itself stays testable without a
database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 1778942714 Add the podcast HTTP API for the UI and the web player
/api/podcasts now lists subscriptions with counters and fetch state,
subscribes by feed URL (fetched first; nothing is stored for a URL that
is not a public feed), shows a podcast with its seasons and history,
pages and searches episodes, and runs the explicit progress actions
(start over, played, unplayed) and unsubscribe/subscribe again.

The web player gets two endpoints: playback returns the audio source
and the resume position and, when the browser starts playing, writes a
new listening session as an explicit action above the carried handoff
generation; progress stores checkpoints, pause, stop and handoff at the
session generation, a seek as an explicit action, completes the episode
once at the end or within the completion tail, and records the
listening session. Handlers delegate to podcasts::api, which the new
Postgres test drives directly.

Podcast queue items are no longer marked unavailable in browser JSON
and carry the episode artwork. The temporary dead-code allowance of the
podcast module is gone; helpers used only by tests are cfg(test) and
complete_session gave way to complete_if_current.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 5aaea8a8eb Document podcast feed refresh and the audio proxy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 2c0c3d21aa Proxy podcast audio from publishers on request
Browsers stream episode audio from the publisher by default. For
publishers they cannot play directly (CORS, mixed content), the
administrator can enable podcast_audio_proxy_enabled (admin Settings,
FURU_PODCAST_AUDIO_PROXY_ENABLED). The endpoints live in a new app at
/api/podcasts:

- GET /episodes/{episode_id}/audio streams an episode of the signed-in
  account. The URL comes from the account's catalog, never from the
  request. Requests go through SafeHttp with one sanitized byte Range and
  no client headers; 200/206/416 pass through, only audio content types
  are served, with nosniff and a sandbox CSP, and responses stop at 1 GiB
  or 4 hours.
- GET /episodes/{episode_id}/source returns the publisher URL and, when
  enabled, the proxy URL.
- POST /{podcast_id}/refresh refreshes one subscribed feed now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 bf9a6abc3f Refresh subscribed podcast feeds in a background job
The podcast_refresh job runs every five minutes and refreshes the podcasts
whose next check is due: conditional requests (ETag, Last-Modified), 32 MiB
and 60 s limits, the shared music-dht parser and PodcastStore::apply_feed.
A chain of permanent redirects moves the feed and becomes an alias.
Healthy feeds are checked hourly with a stable spread; failures back off
from 15 minutes up to a day, honouring Retry-After. Accounts subscribed to
the same feed URL share one request, at most four run at once, and one
run at a time holds an advisory lock. runner::refresh_now is the manual
refresh for one subscribed podcast, at most every 30 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 04ae7d5bd1 Guard podcast HTTP requests against SSRF
Feed and enclosure URLs come from users and third-party feeds. SafeHttp
accepts only http(s) URLs without credentials, resolves names with a
resolver that refuses the whole answer unless every address is public
(loopback, private, CGNAT, link-local, cloud metadata, unique local,
multicast, reserved; IPv4-mapped, NAT64 and 6to4 judged by their IPv4
part), and connects to exactly the checked addresses, so DNS rebinding
cannot swap them. IP literals and every redirect hop are checked; system
proxies, cookies and Referer are off. Loopback is reachable only through a
#[cfg(test)] policy used by the local test server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 c2627444c5 Document the podcast store and the relay import
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 681ff7af89 Sync podcast state through the store instead of the relay
Received podcast operations and snapshot sections are applied to the
podcast store, this device's snapshots are filled from it, and an
unknown episode position resumes from its progress register. The
relay module is removed; operations, gating and snapshot bounds on the
wire are unchanged. The device-sync Postgres tests now migrate their
database themselves and cover locally emitted podcast operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 7f07cb206a Add a PostgreSQL podcast store with relay import
PodcastStore implements the music_dht::podcast contract per account:
catalog, feed aliases, episodes with a derived season view, the
subscription, share and progress registers, listening sessions and the
local-only fetch state. Received operations, snapshot records and local
actions share one apply path (materializers plus merge functions) under
a per-account advisory lock. Local actions append their operation to the
device-sync log with the next stamp of the web device and apply exactly
that operation in the same transaction.

Migration m_0056 creates the tables; m_0057 imports the registers that
0.13 kept in furumusic__fed_podcast_relay and the catalog rows of the
episode references in the operation log. The relay table is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00
sanapachandClaude Opus 5.5 cc1705457e Enable the shared podcast feed parser
The podcast store resolves episode ids from parsed feeds with the
identity hints of music_dht::podcast::feed, which are part of the id
contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:37 +02:00
sanapachandClaude Opus 5.5 4f17feef71 Point frid deps at the fork branch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:29 +02:00
sanapachandClaude Opus 5.5 c1cd689ea0 Test episode resume positions and rollback cleanup on PostgreSQL
The ignored device-sync PostgreSQL test now also covers a handoff and a
remote Next onto an episode with an unknown position (the relayed
progress register supplies 1200 s and its generation), and checks that
0.12's operation types fail on a relayed podcast operation and read the
log again after the documented cleanup statement, which the m_0055
backwards operation now shares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:26:40 +02:00
sanapachandClaude Opus 5.5 a04a7460e6 Note the review fixes in the changelog and docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:22:26 +02:00
sanapachandClaude Opus 5.5 3af0e8ccc9 Keep a rollback to 0.12 safe for sync and the typed queue
Release 0.12 fails a whole sync batch on a podcast operation kind, so
rolling back is only safe after the relayed podcast operations are
removed: document the step in docs/administration.md and run it in the
m_0055 backwards operation.

The typed queue now records the current track id and queue position
written with it, next to the legacy ids. A 0.12 release that only moved
to another track in the same queue no longer leaves a stale typed
position that the next upgrade would restore. Jam placeholders are never
stored in a user's own typed queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:22:19 +02:00
sanapachandClaude Opus 5.5 6f3ed4b7ee Check Jam participant commands against the host queue
The server checked a participant's queue_remove/queue_clear against the
host state of the last report, but the host browser runs its pending
commands in one batch: after a move, a checked index can name a private
item. Participant commands are now stamped `jam_participant`, and the
host browser refuses to remove, clear, add or bring back its private
items for them, judged on the queue it is about to change.

A guest that stops controlling a Jam drops the host's private
placeholders from its own queue, so they are not saved or relayed as
the guest's queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:21:51 +02:00
sanapachandClaude Opus 5.5 d1be583d1e Resume unknown episode positions from progress, not 0
The web player only knows a podcast episode's position from a handoff or
a seek. When Next, auto-advance, a click or a play command makes an
episode current, it now reports `position_unknown` instead of 0, and the
server takes the resume position (and the register generation) from the
relayed progress register before it hands the state to another device.
Remote Next/Prev/play commands to a device do the same.

Next with repeat all or shuffle wraps past a trailing unplayable item
instead of stopping on it. Prev leaves an unplayable item instead of
"restarting" it, and seeking such an item moves its kept position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 19:21:25 +02:00
sanapachandClaude Opus 5.5 ab7202fc73 Note the podcast queue fixes in the changelog
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 18:35:49 +02:00
sanapachandClaude Opus 5.5 19139ea830 Undo metadata deletions archived before the typed queue column
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 18:35:49 +02:00
sanapachandClaude Opus 5.5 a9736e5914 Keep Jam guests from removing or timing the host's private items
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 18:35:49 +02:00
sanapachandClaude Opus 5.5 4d0b352258 Keep the episode position and skip unplayable items safely in the player
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 18:35:49 +02:00
sanapachandClaude Opus 5.5 c14ab8dfea Document podcast queue support and release 0.13.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 16:58:32 +02:00
sanapachandClaude Opus 5.5 b558cf381e Relay device-sync v4 and keep podcast queue items
Use the shared music_dht::device_sync types instead of private copies
(byte-identical for v3 content, checked against the 0.12.x types and a
golden fixture) and announce protocol 4, because every v4 element is
kept:

- podcast operations stay in the operation log and are relayed only to
  peers that reported v4; their registers and the podcast snapshot
  sections are merged with the shared rules into an opaque relay table
  and returned in this server's snapshots (m_0055);
- the browser bridge carries PlaybackTrack.source: items that are not
  library tracks keep the verbatim wire item, so podcast episodes and
  Jam placeholders survive the round trip; the player labels and skips
  them instead of dropping them;
- the typed queue is persisted in queue_items_json next to queue_json,
  which is still written for rollback (m_0054).

Peer versions come from self-reports (profile_protocol_version); relayed
profiles only raise them and DeviceProfileSet no longer stores this
server's constant. Invites carry the inviter's version and a
DeviceProfileSet announces v4 once. Handoffs of a podcast queue to a
device below v4 are refused with an update message, and its playback
commands are ignored while the queue has podcast items. Jam guests see
podcast items as private placeholders, which are mapped back on their
commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 16:58:29 +02:00
sanapachandClaude Opus 5.5 75c67026ac Update music-dht to 0.6.0
The podcast contract and device-sync protocol v4 live in music-dht 0.6.
Cargo.lock currently resolves it from a local patch of the frid branch
podcasts/contract and must be regenerated against the published crate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 16:58:21 +02:00