'use client'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { BookSource } from '@/lib/book.types'; function BooksHomeSkeleton() { return (
{Array.from({ length: 6 }).map((_, index) => (
))}
); } export default function BooksHomePage() { const [sources, setSources] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { if (typeof window !== 'undefined' && !(window as Window & { RUNTIME_CONFIG?: { BOOKS_ENABLED?: boolean } }).RUNTIME_CONFIG?.BOOKS_ENABLED) { window.location.href = '/'; return; } fetch('/api/books/sources') .then((res) => res.json()) .then((data) => setSources(data.sources || [])) .catch((err) => setError(err.message || '加载书源失败')) .finally(() => setLoading(false)); }, []); return (

电子书源

{loading ? : null} {error ?
{error}
: null}
{sources.map((source) => (
{source.name}
{source.type === 'legado' ? 'Legado' : 'OPDS'}
分类{source.capabilities?.catalogSupported ? '可用' : '不可用'} 搜索{source.capabilities?.searchSupported ? '可用' : '不可用'}
{source.capabilities?.catalogSupported && 浏览目录} {source.capabilities?.searchSupported && 搜索书籍}
))}
); }