Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: fixed
Marc Seitz3e739c907964
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsxindex 5cac0de3..bac7e083 100644--- a/components/view/document-view.tsx+++ b/components/view/document-view.tsx@@ -63,8 +63,8 @@ export default function DocumentView({linkId: link.id,documentId: document.id,userId: userId || null,- documentVersionId: document.versions[0].id,- hasPages: document.versions[0].hasPages,+ documentVersionId: document.versions[0].id || null,+ hasPages: document.versions[0].hasPages || null,}),});diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].tsindex e04cd02b..c11e0b44 100644--- a/pages/api/links/domains/[...domainSlug].ts+++ b/pages/api/links/domains/[...domainSlug].ts@@ -35,6 +35,7 @@ export default async function handle(versions: {where: { isPrimary: true },select: {+ id: true,versionNumber: true,hasPages: true,type: true,diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsxindex cdf763c7..ebc598c0 100644--- a/pages/view/domains/[domain]/[slug]/index.tsx+++ b/pages/view/domains/[domain]/[slug]/index.tsx@@ -12,73 +12,79 @@ import { ExtendedRecordMap } from "notion-types";import notion from "@/lib/notion";import { parsePageId } from "notion-utils";-// export const getStaticProps = async (context: GetStaticPropsContext) => {-// const { domain, slug } = context.params as { domain: string; slug: string };--// // Fetch the link-// const res = await fetch(-// `${process.env.NEXTAUTH_URL}/api/links/domains/${encodeURIComponent(-// domain,-// )}/${encodeURIComponent(slug)}`,-// );-// if (!res.ok) {-// return { notFound: true };-// }-// const link = (await res.json()) as LinkWithDocument;--// let pageId = null;-// let recordMap = null;--// const { type, file, ...versionWithoutTypeAndFile } =-// link.document.versions[0];--// if (type === "notion") {-// // regex match to get the page id from the notion url-// const notionPageId = parsePageId(file, { uuid: false });-// if (!notionPageId) {-// return {-// notFound: true,-// };-// }--// pageId = notionPageId;-// recordMap = await notion.getPage(pageId);-// }--// return {-// props: {-// // return link without file and type to avoid sending the file to the client-// link: {-// ...link,-// document: {-// ...link.document,-// versions: [versionWithoutTypeAndFile],-// },-// },-// notionData: {-// rootNotionPageId: pageId,-// recordMap,-// },-// },-// };-// };--// export async function getStaticPaths() {-// return {-// paths: [],-// fallback: true,-// };-// }--export default function ViewPage() {- const { link, error } = useDomainLink();- const { data: session, status } = useSession();+export const getStaticProps = async (context: GetStaticPropsContext) => {+ const { domain, slug } = context.params as { domain: string; slug: string };++ // Fetch the link+ const res = await fetch(+ `${process.env.NEXTAUTH_URL}/api/links/domains/${encodeURIComponent(+ domain,+ )}/${encodeURIComponent(slug)}`,+ );+ if (!res.ok) {+ return { notFound: true };+ }+ const link = (await res.json()) as LinkWithDocument;++ let pageId = null;+ let recordMap = null;++ const { type, file, ...versionWithoutTypeAndFile } =+ link.document.versions[0];- if (error && error.status === 404) {- return <NotFound />;+ if (type === "notion") {+ // regex match to get the page id from the notion url+ const notionPageId = parsePageId(file, { uuid: false });+ if (!notionPageId) {+ return {+ notFound: true,+ };+ }++ pageId = notionPageId;+ recordMap = await notion.getPage(pageId);}- if (!link || status === "loading") {+ return {+ props: {+ // return link without file and type to avoid sending the file to the client+ link: {+ ...link,+ document: {+ ...link.document,+ versions: [versionWithoutTypeAndFile],+ },+ },+ notionData: {+ rootNotionPageId: pageId,+ recordMap,+ },+ },+ revalidate: 10,+ };+};++export async function getStaticPaths() {+ return {+ paths: [],+ fallback: true,+ };+}++export default function ViewPage({+ link,+ notionData,+}: {+ link: LinkWithDocument;+ notionData: {+ rootNotionPageId: string | null;+ recordMap: ExtendedRecordMap | null;+ };+}) {+ const router = useRouter();+ const { data: session, status } = useSession();++ if (!link || status === "loading" || router.isFallback) {return (<div className="h-screen flex items-center justify-center"><LoadingSpinner className="h-20 w-20" />@@ -115,7 +121,7 @@ export default function ViewPage() {userEmail={userEmail}userId={userId}isProtected={true}- // notionData={notionData}+ notionData={notionData}/>);}@@ -126,7 +132,7 @@ export default function ViewPage() {userEmail={userEmail}userId={userId}isProtected={false}- // notionData={notionData}+ notionData={notionData}/>);}