Update storage-overview.tsx

This commit is contained in:
MacRimi
2026-04-12 22:58:49 +02:00
parent 1841feb643
commit adb4815c9b

View File

@@ -1913,19 +1913,18 @@ function SmartTestTab({ disk }: SmartTestTabProps) {
try { try {
setInstalling(true) setInstalling(true)
setTestError(null) setTestError(null)
const res = await fetch('/api/storage/smart/tools/install', { const data = await fetchApi<{ success: boolean; error?: string }>('/api/storage/smart/tools/install', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ install_all: true }) body: JSON.stringify({ install_all: true })
}) })
const data = await res.json()
if (data.success) { if (data.success) {
fetchSmartStatus() fetchSmartStatus()
} else { } else {
setTestError(data.error || 'Installation failed. Try manually: apt-get install smartmontools nvme-cli') setTestError(data.error || 'Installation failed. Try manually: apt-get install smartmontools nvme-cli')
} }
} catch { } catch (err) {
setTestError('Failed to install tools. Try manually: apt-get install smartmontools nvme-cli') const message = err instanceof Error ? err.message : 'Failed to install tools'
setTestError(`${message}. Try manually: apt-get install smartmontools nvme-cli`)
} finally { } finally {
setInstalling(false) setInstalling(false)
} }
@@ -1935,19 +1934,11 @@ function SmartTestTab({ disk }: SmartTestTabProps) {
try { try {
setRunningTest(testType) setRunningTest(testType)
setTestError(null) setTestError(null)
const response = await fetch(`/api/storage/smart/${disk.name}/test`, { await fetchApi(`/api/storage/smart/${disk.name}/test`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ test_type: testType }) body: JSON.stringify({ test_type: testType })
}) })
if (!response.ok) {
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }))
setTestError(errorData.error || 'Failed to start test')
setRunningTest(null)
return
}
// Poll for status updates // Poll for status updates
const pollInterval = setInterval(async () => { const pollInterval = setInterval(async () => {
try { try {
@@ -1963,7 +1954,8 @@ function SmartTestTab({ disk }: SmartTestTabProps) {
} }
}, 5000) }, 5000)
} catch (err) { } catch (err) {
setTestError('Failed to connect to server') const message = err instanceof Error ? err.message : 'Failed to start test'
setTestError(message)
setRunningTest(null) setRunningTest(null)
} }
} }