Fix PostgreSQL migration resume and home crash guard

This commit is contained in:
ShukeBta
2026-06-15 20:13:30 +08:00
parent 0a628a76f1
commit fea1b1dda1
8 changed files with 356 additions and 44 deletions
+42 -5
View File
@@ -1,4 +1,4 @@
import { Suspense, lazy } from 'react'
import { Component, Suspense, lazy, type ErrorInfo, type ReactNode } from 'react'
import { Navigate, Route, Routes } from 'react-router-dom'
import { Layout } from './components/Layout'
@@ -105,10 +105,46 @@ const LicensePage = lazy(() =>
const Loading = () => <p className="px-6 py-8 text-sand-500">加载中…</p>
class AppErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean }> {
state = { hasError: false }
static getDerivedStateFromError() {
return { hasError: true }
}
componentDidCatch(error: Error, info: ErrorInfo) {
console.error('MediaStation UI crashed', error, info)
}
render() {
if (this.state.hasError) {
return (
<div className="min-h-screen bg-gray-50 px-6 py-16 text-gray-900">
<div className="mx-auto max-w-xl rounded-2xl border border-gray-200 bg-white p-6 shadow-sm">
<p className="text-lg font-bold">页面加载失败</p>
<p className="mt-2 text-sm text-gray-500">
当前页面遇到异常,刷新后会重新加载资源和登录状态。
</p>
<button
type="button"
onClick={() => window.location.reload()}
className="mt-5 rounded-xl bg-gray-950 px-4 py-2 text-sm font-bold text-white hover:bg-gray-800"
>
刷新页面
</button>
</div>
</div>
)
}
return this.props.children
}
}
export default function App() {
return (
<Suspense fallback={<Loading />}>
<Routes>
<AppErrorBoundary>
<Suspense fallback={<Loading />}>
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route
path="/"
@@ -275,7 +311,8 @@ export default function App() {
/>
</Route>
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</Suspense>
</Routes>
</Suspense>
</AppErrorBoundary>
)
}
+5 -4
View File
@@ -11,6 +11,7 @@ import type { Library, Media } from '../types'
import { groupSeries } from '../utils/groupSeries'
const hasArtwork = (media?: Media | null) => !!(media?.poster_url || media?.backdrop_url)
const asArray = <T,>(value: unknown): T[] => (Array.isArray(value) ? value as T[] : [])
export function HomePage() {
const [libraries, setLibraries] = useState<Library[]>([])
@@ -24,14 +25,14 @@ export function HomePage() {
setLoading(true)
try {
const [libs, recentItems, hist] = await Promise.all([
libraryAPI.list().catch(() => [] as Library[]),
mediaAPI.search('', 120).then((d) => d.items).catch(() => [] as Media[]),
playbackAPI.recentHistory().catch(() => [] as HistoryItem[]),
libraryAPI.list().then((rows) => asArray<Library>(rows)).catch(() => [] as Library[]),
mediaAPI.search('', 120).then((d) => asArray<Media>(d?.items)).catch(() => [] as Media[]),
playbackAPI.recentHistory().then((rows) => asArray<HistoryItem>(rows)).catch(() => [] as HistoryItem[]),
])
if (cancelled) return
setLibraries(libs)
setRecent(recentItems)
setHistory(hist.filter((h) => !h.completed && !!h.media))
setHistory(hist.filter((h) => h && !h.completed && !!h.media))
} finally {
if (!cancelled) setLoading(false)
}
+4 -2
View File
@@ -60,9 +60,11 @@ function seriesTitleFromPath(path?: string): string {
return normalizeTitle(parts[dirIndex])
}
export function groupSeries(items: Media[]): SeriesCard[] {
export function groupSeries(items: Media[] = []): SeriesCard[] {
const safeItems = Array.isArray(items) ? items : []
const groups = new Map<string, SeriesCard>()
for (const m of items) {
for (const m of safeItems) {
if (!m) continue
const key = getSeriesKey(m)
const g = groups.get(key)