'use client'; import { PageShell } from '@/components/layout/PageShell'; import { useVconRole } from '@/components/layout/VconShell'; import { Button } from '@/components/ui/Button'; import { Icon } from '@/components/ui/Icon'; import { getVconRoleCapabilities } from '@/lib/vconUiHelpers'; import React, { useCallback, useEffect, useState } from 'react'; type EngineStatus = 'checking' | 'online' | 'offline'; interface FilesEngineStatusResponse { ok?: boolean; engine?: string; role?: string; readOnly?: boolean; proxyMode?: 'nginx' | 'standalone'; wsSupported?: boolean; wsHint?: string | null; error?: string; code?: string; } const FILES_ENGINE_STATUS_URL = '/api/files/status'; const FILES_ENGINE_FRAME_URL = '/vcon/files-engine'; export function FilesManagerWorkspace() { const currentRole = useVconRole(); const { canOperate } = getVconRoleCapabilities(currentRole); const [status, setStatus] = useState('checking'); const [statusError, setStatusError] = useState(''); const [wsHint, setWsHint] = useState(null); const [engineReadOnly, setEngineReadOnly] = useState(!canOperate); const [frameKey, setFrameKey] = useState(1); const [probing, setProbing] = useState(false); const checkEngineStatus = useCallback(async (reloadFrame = false) => { setProbing(true); setStatusError(''); try { const response = await fetch(FILES_ENGINE_STATUS_URL, { method: 'GET', cache: 'no-store', credentials: 'same-origin', }); if (response.status === 401) { window.location.assign('/vcon/login?next=%2Fvcon%2Ffiles'); return; } const data = (await response.json().catch(() => ({}))) as FilesEngineStatusResponse; setWsHint(typeof data.wsHint === 'string' && data.wsHint ? data.wsHint : null); if (response.ok && data.ok) { setEngineReadOnly(Boolean(data.readOnly)); setStatus('online'); if (reloadFrame) { setFrameKey((prev) => prev + 1); } return; } setStatus('offline'); setStatusError( data.error || `Files Manager engine returned HTTP ${response.status}. Ensure the Port 4000 ingestion server is running.` ); } catch { setStatus('offline'); setStatusError( 'Cannot reach the Port 4000 Files Manager engine. Start both services with "npm run dev:all" or Docker Compose.' ); } finally { setProbing(false); } }, []); useEffect(() => { void checkEngineStatus(false); }, [checkEngineStatus]); const effectiveReadOnly = !canOperate || engineReadOnly; return ( {effectiveReadOnly ? `Read-only (${currentRole})` : `Full Access (${currentRole})`} {status === 'online' && ( Full View )} } >
Root: /storage/data — browse, edit, rename, upload, download, and ZIP/UNZIP client partitions.
{effectiveReadOnly ? 'Viewer mode: browse, view & download only' : 'Active *.lock files are protected; avoid editing live UTC-today CSVs during peak flush'}
{status === 'online' && wsHint && (
{wsHint}
)}
{status === 'checking' && (

Connecting to Files Manager engine...

Verifying admin session and storage root on Port 4000

)} {status === 'offline' && (

Files Manager Engine Unavailable

{statusError || 'The Port 4000 ingestion and files engine is currently offline.'}

Local: npm run dev:all  |  Production: docker compose up
)} {status === 'online' && (