feat(episodes): let owners remove episodes from the RSS feed
Adds an "unlisted" flag on episodes rather than reusing the existing hard-delete route, since a hard delete cascades to purchases/earnings (ON DELETE CASCADE) and would wipe a producer's sales history and any unwithdrawn earnings for that episode. Unlisting only affects feed.xml output — the episode, its purchases, and reseller listings all stay intact and it can be relisted at any time. Wires up the missing frontend for it too: the podcast settings page had no episode list or management controls at all before this, despite the backend already exposing full episode CRUD. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,18 +4,30 @@ import { useRoute, useRouter } from 'vue-router';
|
|||||||
import { api } from '../lib/api';
|
import { api } from '../lib/api';
|
||||||
import PodcastForm, { type PodcastPayload } from '../components/PodcastForm.vue';
|
import PodcastForm, { type PodcastPayload } from '../components/PodcastForm.vue';
|
||||||
|
|
||||||
|
interface Episode {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
pub_date: number;
|
||||||
|
unlisted: number;
|
||||||
|
}
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const podcastId = route.params.id as string;
|
const podcastId = route.params.id as string;
|
||||||
|
|
||||||
const podcast = ref<(PodcastPayload & { id: string }) | null>(null);
|
const podcast = ref<(PodcastPayload & { id: string }) | null>(null);
|
||||||
|
const episodes = ref<Episode[]>([]);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const error = ref('');
|
const error = ref('');
|
||||||
const saved = ref(false);
|
const saved = ref(false);
|
||||||
|
const episodeError = ref('');
|
||||||
|
const busyEpisodeId = ref('');
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
podcast.value = await api.get<PodcastPayload & { id: string }>(`/api/podcasts/${podcastId}`);
|
const data = await api.get<PodcastPayload & { id: string; episodes: Episode[] }>(`/api/podcasts/${podcastId}`);
|
||||||
|
podcast.value = data;
|
||||||
|
episodes.value = data.episodes;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = (err as Error).message;
|
error.value = (err as Error).message;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -27,6 +39,23 @@ function onSaved(): void {
|
|||||||
saved.value = true;
|
saved.value = true;
|
||||||
setTimeout(() => router.push('/'), 800);
|
setTimeout(() => router.push('/'), 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function toggleListed(ep: Episode): Promise<void> {
|
||||||
|
const nextUnlisted = !ep.unlisted;
|
||||||
|
if (nextUnlisted && !confirm(`Remove "${ep.title}" from the RSS feed? It stays in your library and can be added back later.`)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
episodeError.value = '';
|
||||||
|
busyEpisodeId.value = ep.id;
|
||||||
|
try {
|
||||||
|
const updated = await api.put<Episode>(`/api/podcasts/${podcastId}/episodes/${ep.id}`, { unlisted: nextUnlisted });
|
||||||
|
ep.unlisted = updated.unlisted;
|
||||||
|
} catch (err) {
|
||||||
|
episodeError.value = (err as Error).message;
|
||||||
|
} finally {
|
||||||
|
busyEpisodeId.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -40,5 +69,38 @@ function onSaved(): void {
|
|||||||
Saved.
|
Saved.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!loading && !error" class="card">
|
||||||
|
<h2 class="mb-1 text-lg font-semibold">Episodes</h2>
|
||||||
|
<p class="mb-4 text-xs text-white/30">
|
||||||
|
Removing an episode from the feed hides it from RSS/podcast apps but keeps it in your
|
||||||
|
library — sales history, reseller listings, and the uploaded file are untouched, and you
|
||||||
|
can add it back any time.
|
||||||
|
</p>
|
||||||
|
<p v-if="episodeError" class="mb-3 rounded-lg bg-red-500/20 border border-red-500/40 p-3 text-sm text-red-200">
|
||||||
|
{{ episodeError }}
|
||||||
|
</p>
|
||||||
|
<p v-if="!episodes.length" class="text-sm text-white/50">No episodes yet.</p>
|
||||||
|
<ul v-else class="space-y-2">
|
||||||
|
<li v-for="ep in episodes" :key="ep.id" class="flex items-center justify-between gap-4 rounded-lg bg-white/5 p-3">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<p class="truncate font-medium" :class="{ 'text-white/40': ep.unlisted }">{{ ep.title }}</p>
|
||||||
|
<p class="text-xs text-white/30">
|
||||||
|
{{ new Date(ep.pub_date * 1000).toLocaleDateString() }}
|
||||||
|
<span v-if="ep.unlisted" class="ml-2 rounded-full bg-amber-500/20 px-2 py-0.5 text-amber-300">
|
||||||
|
Removed from feed
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
class="btn-secondary shrink-0 whitespace-nowrap !py-1.5 !px-3 text-sm"
|
||||||
|
:disabled="busyEpisodeId === ep.id"
|
||||||
|
@click="toggleListed(ep)"
|
||||||
|
>
|
||||||
|
{{ busyEpisodeId === ep.id ? 'Working…' : ep.unlisted ? 'Add back to feed' : 'Remove from feed' }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ describe('login allowlist', () => {
|
|||||||
|
|
||||||
describe('podcasts, episodes, feed', () => {
|
describe('podcasts, episodes, feed', () => {
|
||||||
let podcastId: string;
|
let podcastId: string;
|
||||||
|
let episodeId: string;
|
||||||
const sha = 'c'.repeat(64);
|
const sha = 'c'.repeat(64);
|
||||||
|
|
||||||
it('creates a podcast', async () => {
|
it('creates a podcast', async () => {
|
||||||
@@ -188,6 +189,7 @@ describe('podcasts, episodes, feed', () => {
|
|||||||
});
|
});
|
||||||
expect(res.statusCode).toBe(201);
|
expect(res.statusCode).toBe(201);
|
||||||
expect(res.json().enclosure_url).toContain(`${sha}.mp4`);
|
expect(res.json().enclosure_url).toContain(`${sha}.mp4`);
|
||||||
|
episodeId = res.json().id;
|
||||||
} finally {
|
} finally {
|
||||||
vi.unstubAllGlobals();
|
vi.unstubAllGlobals();
|
||||||
}
|
}
|
||||||
@@ -229,6 +231,35 @@ describe('podcasts, episodes, feed', () => {
|
|||||||
});
|
});
|
||||||
expect(cached.statusCode).toBe(304);
|
expect(cached.statusCode).toBe(304);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('removing an episode from the feed hides it from feed.xml but keeps it in the owner list', async () => {
|
||||||
|
const unlist = await app.inject({
|
||||||
|
method: 'PUT',
|
||||||
|
url: `/api/podcasts/${podcastId}/episodes/${episodeId}`,
|
||||||
|
headers: { cookie },
|
||||||
|
payload: { unlisted: true },
|
||||||
|
});
|
||||||
|
expect(unlist.statusCode).toBe(200);
|
||||||
|
expect(unlist.json().unlisted).toBe(1);
|
||||||
|
|
||||||
|
const feed = await app.inject({ method: 'GET', url: `/feeds/${podcastId}/feed.xml` });
|
||||||
|
expect(feed.body).not.toContain(`${sha}.mp4`);
|
||||||
|
|
||||||
|
const owned = await app.inject({ method: 'GET', url: `/api/podcasts/${podcastId}`, headers: { cookie } });
|
||||||
|
expect(owned.json().episodes.some((e: { id: string }) => e.id === episodeId)).toBe(true);
|
||||||
|
|
||||||
|
const relist = await app.inject({
|
||||||
|
method: 'PUT',
|
||||||
|
url: `/api/podcasts/${podcastId}/episodes/${episodeId}`,
|
||||||
|
headers: { cookie },
|
||||||
|
payload: { unlisted: false },
|
||||||
|
});
|
||||||
|
expect(relist.statusCode).toBe(200);
|
||||||
|
expect(relist.json().unlisted).toBe(0);
|
||||||
|
|
||||||
|
const feedAgain = await app.inject({ method: 'GET', url: `/feeds/${podcastId}/feed.xml` });
|
||||||
|
expect(feedAgain.body).toContain(`${sha}.mp4`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('streams + mediamtx auth webhook', () => {
|
describe('streams + mediamtx auth webhook', () => {
|
||||||
|
|||||||
@@ -148,6 +148,17 @@ CREATE TABLE cashu_proofs (
|
|||||||
created_at INTEGER NOT NULL
|
created_at INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX idx_cashu_proofs_unspent ON cashu_proofs(spent_at);
|
CREATE INDEX idx_cashu_proofs_unspent ON cashu_proofs(spent_at);
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
sql: `
|
||||||
|
-- Removing an episode from the RSS feed doesn't have to mean deleting it outright:
|
||||||
|
-- a hard DELETE cascades to purchases/earnings (ON DELETE CASCADE), which would wipe
|
||||||
|
-- a producer's sales history and any unwithdrawn earnings for that episode. "unlisted"
|
||||||
|
-- lets the feed simply omit the episode while everything else (purchases, reseller
|
||||||
|
-- listings, the blob itself) stays intact and reversible.
|
||||||
|
ALTER TABLE episodes ADD COLUMN unlisted INTEGER NOT NULL DEFAULT 0;
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default async function feedRoutes(app: FastifyInstance) {
|
|||||||
const { db, settings } = app.ctx;
|
const { db, settings } = app.ctx;
|
||||||
|
|
||||||
const getPodcast = db.prepare('SELECT * FROM podcasts WHERE id = ?');
|
const getPodcast = db.prepare('SELECT * FROM podcasts WHERE id = ?');
|
||||||
const listEpisodes = db.prepare('SELECT * FROM episodes WHERE podcast_id = ? ORDER BY pub_date DESC');
|
const listEpisodes = db.prepare('SELECT * FROM episodes WHERE podcast_id = ? AND unlisted = 0 ORDER BY pub_date DESC');
|
||||||
const listAllPodcasts = db.prepare('SELECT * FROM podcasts ORDER BY created_at');
|
const listAllPodcasts = db.prepare('SELECT * FROM podcasts ORDER BY created_at');
|
||||||
|
|
||||||
app.get('/feeds/:id/feed.xml', async (req, reply) => {
|
app.get('/feeds/:id/feed.xml', async (req, reply) => {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ const episodeSchema = z.object({
|
|||||||
episode_no: z.number().int().positive().nullish(),
|
episode_no: z.number().int().positive().nullish(),
|
||||||
pub_date: z.number().int().positive().optional(),
|
pub_date: z.number().int().positive().optional(),
|
||||||
price_sats: z.number().int().positive().nullish(),
|
price_sats: z.number().int().positive().nullish(),
|
||||||
|
unlisted: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default async function podcastRoutes(app: FastifyInstance) {
|
export default async function podcastRoutes(app: FastifyInstance) {
|
||||||
@@ -168,10 +169,10 @@ export default async function podcastRoutes(app: FastifyInstance) {
|
|||||||
const d = { ...episode, ...parsed.data };
|
const d = { ...episode, ...parsed.data };
|
||||||
db.prepare(`
|
db.prepare(`
|
||||||
UPDATE episodes SET title=?, description=?, duration_secs=?, season=?, episode_no=?,
|
UPDATE episodes SET title=?, description=?, duration_secs=?, season=?, episode_no=?,
|
||||||
pub_date=?, price_sats=?
|
pub_date=?, price_sats=?, unlisted=?
|
||||||
WHERE id=?
|
WHERE id=?
|
||||||
`).run(d.title, d.description, d.duration_secs ?? null, d.season ?? null,
|
`).run(d.title, d.description, d.duration_secs ?? null, d.season ?? null,
|
||||||
d.episode_no ?? null, d.pub_date, d.price_sats ?? null, eid);
|
d.episode_no ?? null, d.pub_date, d.price_sats ?? null, d.unlisted ? 1 : 0, eid);
|
||||||
return getEpisode.get(eid, id) as Episode;
|
return getEpisode.get(eid, id) as Episode;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export interface Episode {
|
|||||||
price_sats: number | null;
|
price_sats: number | null;
|
||||||
pub_date: number;
|
pub_date: number;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
|
unlisted: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Purchase {
|
export interface Purchase {
|
||||||
|
|||||||
Reference in New Issue
Block a user