mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-04 17:16:04 +09:00
feat(requests-board): admin history view + fix community publish transition (#1008)
## Why Andrew asked whether we can see past community-requests-board submissions and whether our first real user got a video. Investigation surfaced: - **First real user was fully served.** `tas041964@gmail.com` requested *Sam Cooke and the Soul Stirrers – Wonderful* (Sep 15); it was auto-picked, generated, published to YouTube (NOMAD-1650), and he got the completion email + emailed thanks. ✅ - **No admin view existed** to see this — you had to query Firestore directly. - **A real bug:** the community publish fan-out (`mark_published` + voter emails) fired **only** on the `youtube_upload_queue` path. Jobs published via the direct video-worker distribution path (like Sam Cooke's) bypassed it, so the request stayed `in_progress`, never lit up the board's public "Recently made" list, and other up-voters would silently miss their "track is live" email. ## What 1. **Fix the publish transition** — extract the fan-out into `backend/services/community_publish.py` and call it from **both** publish paths (`youtube_queue_processor` + `video_worker`). Also fixes a latent `len(int)` crash in the log line. 2. **Backfill / safety net** — `POST /api/internal/community-requests/reconcile`: idempotent, publishes any `in_progress` pick whose job is already live on YouTube. (Will be run in prod post-deploy to fix the Sam Cooke request.) 3. **Admin history view** — `GET /api/admin/community-requests` + a `/admin/community-requests` page: every request, all statuses, with requester, votes, and job + YouTube links. The public board's "Recently made" section already existed in the UI — it was empty only because of bug #1; fixing the transition (+ reconcile backfill) lights it up. ## Testing - `backend/tests/test_community_voter_notify.py` — fan-out from the shared module, both-path idempotency, voter dedupe/retry, YouTube-url resolution, and the reconcile scan. - `backend/tests/test_community_review_admin.py` — the new admin history endpoint maps all statuses. - All 31 requests-board + 158 worker tests pass. The one unrelated failure in `test_audio_processor_local_gpu.py` is pre-existing (confirmed with changes stashed). ## Notes - Admin surface is English-only (no i18n changes); no `en.json` strings added. - Local CodeRabbit review couldn't run (CLI requires life360-org SSO; no seat on this repo) — leaving to the GitHub bot. Plan: `docs/archive/2026-09-17-requests-board-history-and-publish-transition-plan.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an admin Community Requests history page covering all statuses, votes, submitters, review details, linked jobs, and YouTube videos. - Added admin reconciliation for eligible requests with live videos. - Added automatic voter email notifications after community-request publication. - **Bug Fixes** - Improved publication handling across direct and queued video workflows. - Added recovery for incomplete voter notifications and missed publication transitions. - **Documentation** - Documented the community-request history and reconciliation API endpoints. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
083a478aba
commit
36b331f3d7
14 files changed
+705
-70
No files matched your search
@@ -0,0 +1,179 @@
|
||||
"use client"
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
import { adminApi } from "@/lib/api"
|
||||
import type { CommunityRequestItem } from "@/lib/api"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import {
|
||||
Table, TableHeader, TableBody, TableHead, TableRow, TableCell,
|
||||
} from "@/components/ui/table"
|
||||
import { History, Youtube, ExternalLink, RefreshCw } from "lucide-react"
|
||||
|
||||
// Status → badge styling. Mirrors the request lifecycle in backend/models/song_request.py.
|
||||
const STATUS_VARIANT: Record<string, "default" | "secondary" | "outline" | "destructive"> = {
|
||||
open: "secondary",
|
||||
queued: "outline",
|
||||
in_progress: "outline",
|
||||
published: "default",
|
||||
rejected: "destructive",
|
||||
stalled: "destructive",
|
||||
}
|
||||
|
||||
function fmtDate(iso?: string | null): string {
|
||||
if (!iso) return "—"
|
||||
const d = new Date(iso)
|
||||
return isNaN(d.getTime()) ? "—" : d.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" })
|
||||
}
|
||||
|
||||
export default function CommunityRequestsPage() {
|
||||
const [requests, setRequests] = useState<CommunityRequestItem[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const res = await adminApi.listCommunityRequests()
|
||||
setRequests(res.requests)
|
||||
} catch {
|
||||
setError("Failed to load community requests.")
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
}, [load])
|
||||
|
||||
const counts = useMemo(() => {
|
||||
const c: Record<string, number> = {}
|
||||
for (const r of requests) c[r.status] = (c[r.status] ?? 0) + 1
|
||||
return c
|
||||
}, [requests])
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-6xl">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold flex items-center gap-2">
|
||||
<History className="w-6 h-6" /> Community Requests
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Every song requested via the public voting board
|
||||
(<a href="https://requests.nomadkaraoke.com" target="_blank" rel="noopener noreferrer"
|
||||
className="text-blue-500 hover:underline">requests.nomadkaraoke.com</a>) —
|
||||
who asked, how it was voted, which job made it, and where it landed on YouTube.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={load} disabled={loading}>
|
||||
<RefreshCw className={`w-4 h-4 mr-1 ${loading ? "animate-spin" : ""}`} /> Refresh
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="rounded-lg px-3 py-2 text-sm bg-red-500/10 text-red-500 border border-red-500/30">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && requests.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 text-xs">
|
||||
<Badge variant="outline">{requests.length} total</Badge>
|
||||
{Object.entries(counts).map(([status, n]) => (
|
||||
<Badge key={status} variant={STATUS_VARIANT[status] ?? "outline"}>
|
||||
{n} {status.replace("_", " ")}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<div className="space-y-3">
|
||||
{[0, 1, 2].map((i) => <Skeleton key={i} className="h-12 w-full" />)}
|
||||
</div>
|
||||
) : requests.length === 0 ? (
|
||||
<Card>
|
||||
<CardContent className="py-10 text-center text-muted-foreground">
|
||||
No community requests yet.
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Song</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Requester</TableHead>
|
||||
<TableHead className="text-right">Votes</TableHead>
|
||||
<TableHead>Requested</TableHead>
|
||||
<TableHead>Job</TableHead>
|
||||
<TableHead>Video</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{requests.map((r) => (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="font-medium">
|
||||
{r.artist} — {r.title}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={STATUS_VARIANT[r.status] ?? "outline"}>
|
||||
{r.status.replace("_", " ")}
|
||||
</Badge>
|
||||
{r.review_state ? (
|
||||
<Badge variant="outline" className="ml-1">{r.review_state}</Badge>
|
||||
) : null}
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
<span className="truncate">{r.submitted_by}</span>
|
||||
{r.owner_email && r.owner_email !== r.submitted_by ? (
|
||||
<span className="block text-xs text-muted-foreground">owner: {r.owner_email}</span>
|
||||
) : null}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">{r.vote_count}</TableCell>
|
||||
<TableCell className="text-sm text-muted-foreground">{fmtDate(r.created_at)}</TableCell>
|
||||
<TableCell>
|
||||
{r.job_id ? (
|
||||
<a
|
||||
href={`/app/jobs#/${r.job_id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-sm text-blue-500 hover:underline"
|
||||
>
|
||||
{r.job_id.slice(0, 8)} <ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-sm">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{r.youtube_url ? (
|
||||
<a
|
||||
href={r.youtube_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-sm text-blue-500 hover:underline"
|
||||
>
|
||||
<Youtube className="w-4 h-4 text-red-500" /> Watch
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-sm">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
Share2,
|
||||
Building2,
|
||||
ListChecks,
|
||||
History,
|
||||
} from "lucide-react"
|
||||
|
||||
import {
|
||||
@@ -60,6 +61,11 @@ const navItems = [
|
||||
href: "/admin/referrals",
|
||||
icon: Share2,
|
||||
},
|
||||
{
|
||||
title: "Community Requests",
|
||||
href: "/admin/community-requests",
|
||||
icon: History,
|
||||
},
|
||||
{
|
||||
title: "Community Reviews",
|
||||
href: "/admin/community-reviews",
|
||||
|
||||
@@ -2617,7 +2617,32 @@ export interface CommunityReviewItem {
|
||||
community_checked_at?: string | null;
|
||||
}
|
||||
|
||||
export interface CommunityRequestItem {
|
||||
id: string;
|
||||
artist: string;
|
||||
title: string;
|
||||
status: string;
|
||||
submitted_by: string;
|
||||
owner_email?: string | null;
|
||||
vote_count: number;
|
||||
job_id?: string | null;
|
||||
youtube_url?: string | null;
|
||||
review_state?: string | null;
|
||||
created_at?: string | null;
|
||||
picked_at?: string | null;
|
||||
}
|
||||
|
||||
export const adminApi = {
|
||||
/**
|
||||
* Full history of requests-board submissions across every status.
|
||||
*/
|
||||
async listCommunityRequests(): Promise<{ requests: CommunityRequestItem[] }> {
|
||||
const response = await apiFetch(`${API_BASE_URL}/api/admin/community-requests`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* List requests-board picks flagged for existing-community-version review.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user