import Link from 'next/link'; export const dynamic = 'force-dynamic'; export const revalidate = 0; interface VideoData { id: string; title: string; uploader: string; thumbnail: string; view_count: number; duration: string; } interface Subscription { id: number; channel_id: string; channel_name: string; channel_avatar: string; } async function getHistory() { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080'}/api/history?limit=20`, { cache: 'no-store' }); if (!res.ok) return []; const data = await res.json(); return Array.isArray(data) ? data : []; } catch { return []; } } async function getSubscriptions() { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080'}/api/subscriptions`, { cache: 'no-store' }); if (!res.ok) return []; const data = await res.json(); return Array.isArray(data) ? data : []; } catch { return []; } } function formatViews(views: number): string { if (views >= 1000000) return (views / 1000000).toFixed(1) + 'M'; if (views >= 1000) return (views / 1000).toFixed(1) + 'K'; return views.toString(); } export default async function LibraryPage() { const [history, subscriptions] = await Promise.all([getHistory(), getSubscriptions()]); return (
No videos watched yet
Videos you watch will appear here
{video.uploader}
{video.view_count > 0 && ({formatViews(video.view_count)} views
)}