Add the share toggle and privacy dialog to the podcast page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
588ea4e99e
commit
74ad88d06e
6 files changed
+318
-2
No files matched your search
@@ -75,6 +75,17 @@ const T = {
|
||||
podcastFetchError: "{{ t.player_podcast_fetch_error }}",
|
||||
podcastNextCheck: "{{ t.player_podcast_next_check }}",
|
||||
podcastUnsubscribeConfirm: "{{ t.player_podcast_unsubscribe_confirm }}",
|
||||
podcastSharePrivate: "{{ t.player_podcast_share_private }}",
|
||||
podcastSharePublished: "{{ t.player_podcast_share_published }}",
|
||||
podcastSharePublishing: "{{ t.player_podcast_share_publishing }}",
|
||||
podcastShareDiscoveryOff: "{{ t.player_podcast_share_discovery_off }}",
|
||||
podcastSharePending: "{{ t.player_podcast_share_pending }}",
|
||||
podcastShareUnavailable: "{{ t.player_podcast_share_unavailable }}",
|
||||
podcastWarningSecretQuery: "{{ t.player_podcast_warning_secret_query }}",
|
||||
podcastWarningPrivateHost: "{{ t.player_podcast_warning_private_host }}",
|
||||
podcastWarningEntropyQuery: "{{ t.player_podcast_warning_entropy_query }}",
|
||||
podcastWarningEntropyPath: "{{ t.player_podcast_warning_entropy_path }}",
|
||||
podcastWarningOther: "{{ t.player_podcast_warning_other }}",
|
||||
podcastSeason: "{{ t.player_podcast_season }}",
|
||||
podcastNoSeason: "{{ t.player_podcast_no_season }}",
|
||||
podcastLeft: "{{ t.player_podcast_left }}",
|
||||
@@ -3677,6 +3688,10 @@ document.addEventListener('alpine:init', () => {
|
||||
refreshing: false,
|
||||
refreshMessage: '',
|
||||
actionError: '',
|
||||
share: null,
|
||||
sharing: false,
|
||||
shareError: '',
|
||||
shareDialog: null,
|
||||
busy: {},
|
||||
expanded: {},
|
||||
_searchTimer: null,
|
||||
@@ -3761,9 +3776,12 @@ document.addEventListener('alpine:init', () => {
|
||||
this.sort = 'newest';
|
||||
this.query = '';
|
||||
this.expanded = {};
|
||||
this.share = null;
|
||||
this.shareDialog = null;
|
||||
}
|
||||
this.refreshMessage = '';
|
||||
this.actionError = '';
|
||||
this.shareError = '';
|
||||
this.detailError = '';
|
||||
this._enterView('podcast_detail', '#podcast?id=' + encodeURIComponent(podcastId), options);
|
||||
this.loadDetail(podcastId);
|
||||
@@ -3777,6 +3795,7 @@ document.addEventListener('alpine:init', () => {
|
||||
const data = await this._json(`/api/podcasts/feeds/${podcastId}`);
|
||||
if (token !== this._detailToken) return;
|
||||
this.current = data.podcast;
|
||||
this.share = data.share || null;
|
||||
this.seasons = Array.isArray(data.seasons) ? data.seasons : [];
|
||||
this.history = Array.isArray(data.history) ? data.history : [];
|
||||
this.detailError = '';
|
||||
@@ -3849,6 +3868,8 @@ document.addEventListener('alpine:init', () => {
|
||||
try {
|
||||
this.current = await this._json(`/api/podcasts/feeds/${podcast.podcast_id}/unsubscribe`, { method: 'POST' });
|
||||
this.loadList();
|
||||
// Unsubscribing also revokes sharing.
|
||||
this.loadDetail(podcast.podcast_id);
|
||||
} catch (error) {
|
||||
this.actionError = error.message;
|
||||
}
|
||||
@@ -3861,11 +3882,103 @@ document.addEventListener('alpine:init', () => {
|
||||
try {
|
||||
this.current = await this._json(`/api/podcasts/feeds/${podcast.podcast_id}/subscribe`, { method: 'POST' });
|
||||
this.loadList();
|
||||
// A new subscription is private until shared again.
|
||||
this.loadDetail(podcast.podcast_id);
|
||||
} catch (error) {
|
||||
this.actionError = error.message;
|
||||
}
|
||||
},
|
||||
|
||||
// Sharing in the federation: the account's synced decision; the
|
||||
// server's node publishes the card. A feed URL that looks private
|
||||
// (token in the query, member-feed host...) is published only after
|
||||
// the user confirms exactly the URLs shown in the dialog.
|
||||
toggleShare() {
|
||||
const share = this.share;
|
||||
if (!this.current || !share || this.sharing) return;
|
||||
if (share.shared) return this._setShare(false);
|
||||
if (Array.isArray(share.warnings) && share.warnings.length) return this.reviewShare();
|
||||
return this._setShare(true);
|
||||
},
|
||||
|
||||
reviewShare(share = this.share) {
|
||||
const podcast = this.current;
|
||||
if (!podcast || !share || !share.feed_url) return;
|
||||
this.shareDialog = {
|
||||
podcastId: podcast.podcast_id,
|
||||
title: podcast.title,
|
||||
warnings: Array.isArray(share.warnings) ? share.warnings : [],
|
||||
feed_url: share.feed_url,
|
||||
id_feed_url: share.id_feed_url || null,
|
||||
};
|
||||
},
|
||||
|
||||
cancelShare() {
|
||||
this.shareDialog = null;
|
||||
},
|
||||
|
||||
confirmShare() {
|
||||
const dialog = this.shareDialog;
|
||||
this.shareDialog = null;
|
||||
if (!dialog || this.current?.podcast_id !== dialog.podcastId) return;
|
||||
return this._setShare(true, { feed_url: dialog.feed_url, id_feed_url: dialog.id_feed_url });
|
||||
},
|
||||
|
||||
async _setShare(shared, confirm = null) {
|
||||
const podcastId = this.current?.podcast_id;
|
||||
if (!podcastId || this.sharing) return;
|
||||
this.sharing = true;
|
||||
this.shareError = '';
|
||||
try {
|
||||
const body = { shared };
|
||||
if (confirm) body.confirm = confirm;
|
||||
const res = await fetch(`/api/podcasts/feeds/${podcastId}/share`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
let data = null;
|
||||
try { data = await res.json(); } catch {}
|
||||
if (this.current?.podcast_id !== podcastId) return;
|
||||
if (res.status === 409 && data?.needs_confirmation && data.share) {
|
||||
// The URLs changed (or were never confirmed): ask about
|
||||
// what the server would publish now.
|
||||
this.share = data.share;
|
||||
this.reviewShare(data.share);
|
||||
} else if (!res.ok) {
|
||||
throw new Error(data?.error || T.podcastRequestFailed);
|
||||
} else {
|
||||
if (data?.podcast) this.current = data.podcast;
|
||||
this.share = data?.share || this.share;
|
||||
this.loadList();
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.current?.podcast_id === podcastId) this.shareError = error.message;
|
||||
} finally {
|
||||
this.sharing = false;
|
||||
}
|
||||
},
|
||||
|
||||
shareStatus() {
|
||||
const share = this.share;
|
||||
if (!share) return '';
|
||||
if (!share.shared) return share.card_error ? T.podcastShareUnavailable : T.podcastSharePrivate;
|
||||
if (share.pending_confirmation) return T.podcastSharePending;
|
||||
if (share.discovery !== 'running') return T.podcastShareDiscoveryOff;
|
||||
return share.published ? T.podcastSharePublished : T.podcastSharePublishing;
|
||||
},
|
||||
|
||||
warningText(warning) {
|
||||
const name = warning?.name || '';
|
||||
switch (warning?.reason) {
|
||||
case 'secret_query_parameter': return T.podcastWarningSecretQuery.replace('{name}', name);
|
||||
case 'private_feed_host': return T.podcastWarningPrivateHost.replace('{host}', warning.host || '');
|
||||
case 'high_entropy_query_value': return T.podcastWarningEntropyQuery.replace('{name}', name);
|
||||
case 'high_entropy_path_segment': return T.podcastWarningEntropyPath;
|
||||
default: return T.podcastWarningOther;
|
||||
}
|
||||
},
|
||||
|
||||
jamBlocked() {
|
||||
// A Jam guest controls the host's queue: episodes are private.
|
||||
return !!Alpine.store('devices')?.isControllingRemoteJam?.();
|
||||
|
||||
Reference in new issue
Block a user