"use client"; import { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Header } from "@/components/ui/header"; interface Video { id: number; title: string; path: string; size: number; thumbnail: string; } const VideosPage = () => { const [videos, setVideos] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchVideos(); }, []); const fetchVideos = async () => { try { const res = await fetch("/api/videos"); const data = await res.json(); setVideos(data); } catch (error) { console.error('Error fetching videos:', error); } finally { setLoading(false); } }; const formatFileSize = (bytes: number) => { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; if (loading) { return (
Loading videos...
); } return (
{videos.map((video) => ( {video.title} { (e.target as HTMLImageElement).src = '/placeholder.svg'; }} /> {video.title} Size: {formatFileSize(video.size)} Path: {video.path} ))}
{videos.length === 0 && (

No videos found. Add media libraries to scan for videos.

)}
); }; export default VideosPage;