'use client'; import { useState, useEffect } from 'react'; import { useNotification } from '@/app/context/NotificationContext'; import GrantSudoLink from "@/app/components/GrantSudoLink"; export default function TFTPPage() { const [files, setFiles] = useState([]); const [selectedFile, setSelectedFile] = useState(null); const { showNotification } = useNotification(); const fetchFiles = async () => { try { const response = await fetch('/api/tftp/files'); const data = await response.json(); if (response.ok) { setFiles(data.files); showNotification('File list refreshed successfully.', 'success'); } else { showNotification(data.error, 'error'); } } catch (error) { showNotification('Failed to fetch files.', 'error'); } }; const handleDownload = (filename) => { window.location.href = `/api/tftp/files/${filename}`; }; const handleDelete = async (filename) => { if (confirm(`Are you sure you want to delete ${filename}?`)) { try { const response = await fetch(`/api/tftp/files/${filename}`, { method: 'DELETE', }); const data = await response.json(); if (response.ok) { showNotification('File deleted successfully.', 'success'); fetchFiles(); } else { showNotification(data.error, 'error'); } } catch (error) { showNotification('Failed to delete file.', 'error'); } } }; const handleUpload = async (event) => { event.preventDefault(); if (!selectedFile) return; const formData = new FormData(); formData.append('file', selectedFile); try { const response = await fetch('/api/tftp/files/upload', { method: 'POST', body: formData, }); const data = await response.json(); if (response.ok) { showNotification('File uploaded successfully.', 'success'); fetchFiles(); } else { showNotification(data.error, 'error'); } } catch (error) { showNotification('Failed to upload file.', 'error'); } }; useEffect(() => { fetchFiles(); }, []); return (

TFTP Server Files

setSelectedFile(e.target.files[0])} />
If upload fails:
{files.map((file) => ( ))}
Filename Size (bytes) Actions
{file.name} {file.size}
); }