import React, { useState, useEffect } from 'react'; import axios from 'axios'; const StorageManager = () => { const [storageInfo, setStorageInfo] = useState(null); const [loading, setLoading] = useState(false); const [cleanupAge, setCleanupAge] = useState(24); const [message, setMessage] = useState(''); // Use environment variable for backend URL, default to http://localhost:7860 const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || 'http://localhost:7860'; const fetchStorageInfo = async () => { setLoading(true); try { const response = await axios.get(`${BACKEND_URL}/storage/info`); setStorageInfo(response.data); setMessage(''); } catch (error) { console.error('Error fetching storage info:', error); setMessage('Failed to fetch storage info'); } finally { setLoading(false); } }; const handleCleanup = async () => { setLoading(true); try { const response = await axios.post(`${BACKEND_URL}/storage/cleanup?max_age_hours=${cleanupAge}`); setMessage(response.data.message); fetchStorageInfo(); // Refresh info after cleanup } catch (error) { console.error('Error cleaning up storage:', error); setMessage('Failed to cleanup storage'); } finally { setLoading(false); } }; useEffect(() => { fetchStorageInfo(); }, []); return (
Files: {info.file_count !== undefined ? info.file_count : 'N/A'}
Size: {info.size_mb} MB
{info.cleanup_policy &&ℹ️ {info.cleanup_policy}
} {info.note &&ℹ️ {info.note}
}