import { useEffect, useState } from 'react'; import api from '../lib/api.js'; import { IconHash, IconClock, IconFileText, IconRefresh } from '@tabler/icons-react'; import { formatDateTimeWithRelative } from '../lib/datetime.js'; function S3MetaBar({ keys = [], className = '' }) { const [meta, setMeta] = useState({}); const [loading, setLoading] = useState(false); const fetchMeta = async () => { setLoading(true); try { const res = await api.get('/s3/last-modified'); setMeta(res.data || {}); } catch { setMeta({}); } finally { setLoading(false); } }; useEffect(() => { fetchMeta(); }, []); const copyMeta = async (k) => { try { const it = meta[k] || {}; const text = `etag: ${it?.etag || ''}\nlastModified: ${it?.lastModified || ''}`; await navigator.clipboard?.writeText(text); window.notify?.success?.('Скопировано в буфер'); } catch (e) { window.notify?.error?.('Не удалось скопировать', String(e)); } }; const renderKey = (k) => { const it = meta[k]; return (
{it?.etag || '—'} {it?.lastModified ? formatDateTimeWithRelative(it.lastModified) : '—'} {typeof it?.contentLength === 'number' ? `${it.contentLength} байт` : '—'}
); }; return (
{keys.length === 0 ? renderKey('domainsNew') : keys.map(renderKey)}
); } export default S3MetaBar;