Reinterpreted from the plan's YAGNI 'Scale-out' (OpenSearch/object-storage /multi-tenant deferred at KB scale). Phase 4 = make the Phase 3 async + revision system correct, secure, observable, deployable. - T1 (correctness bug): restoreRevision now rebuilds semantic chunks via new @mcpedia/core reindexChunks(slug) so semantic/hybrid search stay consistent after a restore (previously document_chunks held the NEW body while documents.body held the restored OLD body -> stale search). - T2 (security): /hooks/* git-sync webhooks now require x-webhook-secret header matching WEBHOOK_SECRET (401 otherwise); API fails fast at startup if unset. Added WEBHOOK_SECRET to @mcpedia/config + .env.example; set real secret in .env. - T3 (UX): web doc page shows a History panel (revision no/reason/date/length) with per-revision Restore; app/api/revisions/restore/route.ts calls restoreRevision + revalidatePath (server-component only, no client JS). - T4: listRevisions gains offset paging; summary never includes body. - T5 (ops): deploy/mcpedia-api.service + deploy/mcpedia-worker.service systemd units (Restart=on-failure, EnvironmentFile=.env). Not auto-enabled on host. Verified against live imrnes Redis + Postgres: turbo typecheck+build green; restore-rebuilds-chunks (marker present -> gone after restore); webhook 401/200; web restore route redirects to doc + reverts body; revisions API returns summary (no body); systemd-analyze verify passes.
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import { getDocument, listDocuments, getRelated, listRevisions } from "@mcpedia/core";
|
|
import Markdown from "@/components/Markdown";
|
|
|
|
export default async function DocPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ section: string; slug: string[] }>;
|
|
}) {
|
|
const { section, slug } = await params;
|
|
const fullSlug = `${section}/${slug.join("/")}`;
|
|
const doc = await getDocument(fullSlug);
|
|
if (!doc) notFound();
|
|
|
|
const related = await getRelated(fullSlug, 5);
|
|
const revisions = await listRevisions(fullSlug, 10);
|
|
|
|
return (
|
|
<article className="space-y-4">
|
|
<div>
|
|
<Link href="/" className="text-sm text-zinc-500 hover:underline">
|
|
← Back
|
|
</Link>
|
|
<h1 className="text-2xl font-semibold tracking-tight mt-2">
|
|
{doc.title}
|
|
</h1>
|
|
<div className="text-xs text-zinc-500 mt-1">
|
|
{doc.tags.map((t) => `#${t}`).join(" ")} · {doc.author || "unknown"}
|
|
</div>
|
|
</div>
|
|
|
|
<Markdown source={doc.body} />
|
|
|
|
{related.length > 0 && (
|
|
<aside className="mt-8 border-t border-zinc-200 dark:border-zinc-800 pt-4">
|
|
<h2 className="text-sm font-medium mb-2">Related</h2>
|
|
<ul className="text-sm space-y-1">
|
|
{related.map((r) => (
|
|
<li key={r.slug}>
|
|
<Link
|
|
href={`/${r.section}/${r.slug}`}
|
|
className="hover:underline"
|
|
>
|
|
{r.title}
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</aside>
|
|
)}
|
|
|
|
{revisions.length > 0 && (
|
|
<aside className="mt-8 border-t border-zinc-200 dark:border-zinc-800 pt-4">
|
|
<h2 className="text-sm font-medium mb-2">History</h2>
|
|
<ul className="text-sm space-y-1">
|
|
{revisions.map((rev) => (
|
|
<li
|
|
key={rev.id}
|
|
className="flex items-center justify-between gap-2"
|
|
>
|
|
<span className="text-zinc-600 dark:text-zinc-400">
|
|
#{rev.revisionNo} · {rev.reason} ·{" "}
|
|
{new Date(rev.createdAt).toLocaleString()} · {rev.bodyLength} chars
|
|
</span>
|
|
<form action={`/api/revisions/restore/`} method="post">
|
|
<input type="hidden" name="id" value={rev.id} />
|
|
<button
|
|
type="submit"
|
|
className="rounded border border-zinc-300 dark:border-zinc-700 px-2 py-0.5 text-xs hover:bg-zinc-100 dark:hover:bg-zinc-800"
|
|
>
|
|
Restore
|
|
</button>
|
|
</form>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</aside>
|
|
)}
|
|
</article>
|
|
);
|
|
}
|
|
|
|
export async function generateStaticParams() {
|
|
const docs = await listDocuments();
|
|
return docs.map((d) => ({
|
|
section: d.section,
|
|
slug: d.slug.split("/").slice(1),
|
|
}));
|
|
}
|