Browse a found podcast by season and cancel abandoned previews
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ea3f7b337
commit
12617a6d52
7 files changed
+215
-19
No files matched your search
@@ -3703,6 +3703,8 @@ document.addEventListener('alpine:init', () => {
|
||||
shareDialog: null,
|
||||
found: null,
|
||||
_foundToken: 0,
|
||||
_foundAbort: null,
|
||||
_foundPreviewSeq: 0,
|
||||
busy: {},
|
||||
expanded: {},
|
||||
_searchTimer: null,
|
||||
@@ -4063,15 +4065,18 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
|
||||
foundMore(preview) {
|
||||
const more = Number(preview?.episode_count || 0) - (preview?.episodes?.length || 0);
|
||||
const listed = Number.isInteger(preview?.listed_count) ? preview.listed_count : Number(preview?.episode_count || 0);
|
||||
const more = listed - (preview?.episodes?.length || 0);
|
||||
return more > 0 ? T.podcastFoundMore.replace('{count}', String(more)) : '';
|
||||
},
|
||||
|
||||
openFound(hit) {
|
||||
if (GUEST || !hit?.podcast_id || !hit.feed_url) return;
|
||||
this._abortFoundPreview();
|
||||
this._foundToken += 1;
|
||||
this.found = {
|
||||
hit,
|
||||
season: 'all',
|
||||
preview: null,
|
||||
previewLoading: false,
|
||||
previewError: '',
|
||||
@@ -4085,28 +4090,60 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
|
||||
closeFound() {
|
||||
// An abandoned preview is cancelled: the server stops reading
|
||||
// the feed and frees the account's feed-request slot.
|
||||
this._abortFoundPreview();
|
||||
this._foundToken += 1;
|
||||
this.found = null;
|
||||
},
|
||||
|
||||
_foundBody(hit) {
|
||||
_abortFoundPreview() {
|
||||
if (this._foundAbort) {
|
||||
try { this._foundAbort.abort(); } catch {}
|
||||
}
|
||||
this._foundAbort = null;
|
||||
},
|
||||
|
||||
_foundBody(hit, extra = {}) {
|
||||
// The card's id and origin URL, exactly as found: the server
|
||||
// checks that the id comes from this URL.
|
||||
return {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url }),
|
||||
body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url, ...extra }),
|
||||
};
|
||||
},
|
||||
|
||||
selectFoundSeason(value) {
|
||||
const found = this.found;
|
||||
if (!found || typeof value !== 'string') return;
|
||||
// The same chip again shows every season.
|
||||
const season = found.season === value ? 'all' : value;
|
||||
this.found = { ...found, season };
|
||||
this.loadFoundPreview();
|
||||
},
|
||||
|
||||
async loadFoundPreview() {
|
||||
const found = this.found;
|
||||
if (!found || found.previewLoading) return;
|
||||
if (!found) return;
|
||||
// A newer request (another season, Try again) replaces the
|
||||
// running one.
|
||||
this._abortFoundPreview();
|
||||
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
||||
this._foundAbort = controller;
|
||||
this._foundPreviewSeq += 1;
|
||||
const seq = this._foundPreviewSeq;
|
||||
const token = this._foundToken;
|
||||
const current = () => token === this._foundToken && seq === this._foundPreviewSeq;
|
||||
this.found = { ...found, previewLoading: true, previewError: '' };
|
||||
const season = found.season && found.season !== 'all' ? { season: found.season } : {};
|
||||
try {
|
||||
const preview = await this._json('/api/podcasts/discovery/preview', this._foundBody(found.hit));
|
||||
if (token !== this._foundToken) return;
|
||||
const preview = await this._json('/api/podcasts/discovery/preview', {
|
||||
...this._foundBody(found.hit, season),
|
||||
...(controller ? { signal: controller.signal } : {}),
|
||||
});
|
||||
if (!current()) return;
|
||||
this._foundAbort = null;
|
||||
this.found = {
|
||||
...this.found,
|
||||
preview: {
|
||||
@@ -4121,7 +4158,8 @@ document.addEventListener('alpine:init', () => {
|
||||
localPodcastId: this.found.localPodcastId || preview?.local_podcast_id || null,
|
||||
};
|
||||
} catch (error) {
|
||||
if (token !== this._foundToken) return;
|
||||
if (!current()) return;
|
||||
this._foundAbort = null;
|
||||
this.found = { ...this.found, previewLoading: false, previewError: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user