Rename the unified application to dashboard
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import type { GetServerSideProps } from "next";
|
||||
import GuidanceReader, { type ReaderProps } from "@/components/GuidanceReader";
|
||||
export default function Read(props: ReaderProps) {
|
||||
return <GuidanceReader {...props} />;
|
||||
}
|
||||
export const getServerSideProps: GetServerSideProps<ReaderProps> = async ({
|
||||
params,
|
||||
query,
|
||||
res,
|
||||
req,
|
||||
}) => {
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
const revision = query.revision;
|
||||
if (
|
||||
revision !== undefined &&
|
||||
(typeof revision !== "string" ||
|
||||
!/^[1-9][0-9]{0,9}$/.test(revision) ||
|
||||
Number(revision) > 2147483647)
|
||||
)
|
||||
return { notFound: true };
|
||||
const { resolveDocument } = await import("@/lib/guidance-store");
|
||||
const document = await resolveDocument(
|
||||
String(params?.id),
|
||||
revision === undefined ? undefined : Number(revision),
|
||||
);
|
||||
if (!document) return { notFound: true };
|
||||
const links = await Promise.all(
|
||||
document.links.map(async (link) => ({
|
||||
...link,
|
||||
resolved: !!(await resolveDocument(link.target, link.revision)),
|
||||
})),
|
||||
);
|
||||
const { db } = await import("@/lib/db");
|
||||
const { currentAccount } = await import("@/lib/account");
|
||||
const user = await currentAccount(
|
||||
new Request("http://internal", {
|
||||
headers: { cookie: req.headers.cookie || "" },
|
||||
}),
|
||||
);
|
||||
const owner = await db().query(
|
||||
"SELECT owner_id,deleted_at FROM guidance_documents WHERE id=$1",
|
||||
[document.id],
|
||||
);
|
||||
const rows = await db().query(
|
||||
"SELECT revision,created_at FROM guidance_revisions WHERE document_id=$1 ORDER BY revision DESC",
|
||||
[document.id],
|
||||
);
|
||||
return {
|
||||
props: {
|
||||
document,
|
||||
source: "community",
|
||||
links,
|
||||
canEdit: !!user && owner.rows[0]?.owner_id === user.id,
|
||||
withdrawn: !!owner.rows[0]?.deleted_at,
|
||||
versions: rows.rows.map((r) => ({
|
||||
revision: r.revision,
|
||||
createdAt: new Date(r.created_at).toISOString(),
|
||||
})),
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user