'use client'; import { Button } from '@/components/ui/Button'; import { Card } from '@/components/ui/Card'; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, TableWrap, } from '@/components/ui/Table'; import { useToast } from '@/components/ui/Toast'; import { useCallback, useEffect, useState } from 'react'; export default function StoragePage() { const { success, error } = useToast(); const [stats, setStats] = useState(null); const [files, setFiles] = useState([]); const [loading, setLoading] = useState(true); const [flushing, setFlushing] = useState(false); const fetchStorageData = useCallback(async () => { try { const res = await fetch('/api/storage'); if (res.ok) { const data = await res.json(); setStats(data.stats); setFiles(data.files || []); } } catch { // ignore } finally { setLoading(false); } }, []); useEffect(() => { fetchStorageData(); }, [fetchStorageData]); const handleManualFlush = async () => { setFlushing(true); try { const res = await fetch('/api/storage', { method: 'POST' }); if (res.ok) { const data = await res.json(); success('Buffer Flushed', `Flushed ${data.flushedCount} events to CSV files`); fetchStorageData(); } else { error('Flush Failed', 'Could not flush buffer to disk'); } } catch (err: any) { error('Error', err.message); } finally { setFlushing(false); } }; return (
{/* Header */}

CSV Storage

{/* Storage Summary Cards */}
Disk Usage {stats?.totalMB ?? '0.00'} MB CSV Files {stats?.totalFiles ?? 0} Persisted Rows {stats?.totalRows ? stats.totalRows.toLocaleString() : 0} Rotation Rule 100MB / Daily
{/* Partition Files Table */}

CSV Files on Disk

Client Folder Partition Filename File Size Data Lines Last Rotation / Append {files.length === 0 ? ( ) : ( files.map((file, idx) => ( {file.clientId} {file.filename} {(file.sizeBytes / 1024).toFixed(1)} KB {file.linesCount.toLocaleString()} {new Date(file.modifiedAt).toLocaleString()} )) )}
); }