import { revalidatePath } from "next/cache"; import Link from "next/link"; import { listFolders, createLibrary, deleteLibrary, fetchLibraries, getBookCoverUrl, LibraryDto, FolderItem } from "../../lib/api"; import type { TranslationKey } from "../../lib/i18n/fr"; import { getServerTranslations } from "../../lib/i18n/server"; import { LibraryActions } from "../components/LibraryActions"; import { LibraryForm } from "../components/LibraryForm"; import { ProviderIcon } from "../components/ProviderIcon"; import { Card, CardHeader, CardTitle, CardDescription, CardContent, Button, Badge } from "../components/ui"; export const dynamic = "force-dynamic"; function formatNextScan(nextScanAt: string | null, imminentLabel: string): string { if (!nextScanAt) return "-"; const date = new Date(nextScanAt); const now = new Date(); const diff = date.getTime() - now.getTime(); if (diff < 0) return imminentLabel; if (diff < 60000) return "< 1 min"; if (diff < 3600000) return `${Math.floor(diff / 60000)}m`; if (diff < 86400000) return `${Math.floor(diff / 3600000)}h`; return `${Math.floor(diff / 86400000)}d`; } export default async function LibrariesPage() { const { t } = await getServerTranslations(); const [libraries, folders] = await Promise.all([ fetchLibraries().catch(() => [] as LibraryDto[]), listFolders().catch(() => [] as FolderItem[]) ]); const thumbnailMap = new Map( libraries.map(lib => [ lib.id, (lib.thumbnail_book_ids || []).map(bookId => getBookCoverUrl(bookId)), ]) ); async function addLibrary(formData: FormData) { "use server"; const name = formData.get("name") as string; const rootPath = formData.get("root_path") as string; if (name && rootPath) { await createLibrary(name, rootPath); revalidatePath("/libraries"); } } async function removeLibrary(formData: FormData) { "use server"; const id = formData.get("id") as string; await deleteLibrary(id); revalidatePath("/libraries"); } return ( <>
{lib.root_path}