Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
archived issue fix
Rohit Nandi616974f2d3fd
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsxindex be3d0dfc..06dc695d 100644--- a/components/view/document-view.tsx+++ b/components/view/document-view.tsx@@ -1,6 +1,9 @@import React, { useEffect, useRef, useState } from "react";import PDFViewer from "@/components/PDFViewer";-import AccessForm, { DEFAULT_ACCESS_FORM_DATA, DEFAULT_ACCESS_FORM_TYPE } from "@/components/view/access-form";+import AccessForm, {+ DEFAULT_ACCESS_FORM_DATA,+ DEFAULT_ACCESS_FORM_TYPE,+} from "@/components/view/access-form";import { usePlausible } from "next-plausible";import { toast } from "sonner";import { LinkWithDocument } from "@/lib/types";@@ -35,10 +38,9 @@ export default function DocumentView({pages: null,});const [data, setData] = useState<DEFAULT_ACCESS_FORM_TYPE>(- DEFAULT_ACCESS_FORM_DATA+ DEFAULT_ACCESS_FORM_DATA,);-const handleSubmission = async (): Promise<void> => {setIsLoading(true);const response = await fetch("/api/views", {@@ -69,12 +71,12 @@ export default function DocumentView({};const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (- event: React.FormEvent+ event: React.FormEvent,): Promise<void> => {event.preventDefault();await handleSubmission();};-+// If link is not submitted and does not have email / password protection, show the access formuseEffect(() => {if (!didMount.current) {diff --git a/pages/404.tsx b/pages/404.tsxindex 24c8973e..3bf5b284 100644--- a/pages/404.tsx+++ b/pages/404.tsx@@ -1,6 +1,6 @@import Link from "next/link";-export default function NotFound() {+export default function NotFound({ message }: { message?: string }) {return (<><div className="min-h-screen pt-16 pb-12 flex flex-col">@@ -14,7 +14,8 @@ export default function NotFound() {Page not found.</h1><p className="mt-2 text-base text-gray-600">- Sorry, we couldn’t find the page you’re looking for.+ {message ||+ "Sorry, we couldn’t find the page you’re looking for."}</p><div className="mt-6"><Linkdiff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex 887c0179..794d157a 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -7,7 +7,7 @@ import { authOptions } from "../../auth/[...nextauth]";export default async function handle(req: NextApiRequest,- res: NextApiResponse+ res: NextApiResponse,) {if (req.method === "GET") {// GET /api/links/:id@@ -24,16 +24,8 @@ export default async function handle(emailProtected: true,allowDownload: true,password: true,- document: {- select: {- id: true,- versions: {- where: { isPrimary: true },- select: { versionNumber: true },- take: 1,- }- }- },+ isArchived: true,+ document: { select: { id: true, name: true } },},});diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].tsindex 3451a53d..eaaa82fd 100644--- a/pages/api/links/domains/[...domainSlug].ts+++ b/pages/api/links/domains/[...domainSlug].ts@@ -3,7 +3,7 @@ import prisma from "@/lib/prisma";export default async function handle(req: NextApiRequest,- res: NextApiResponse+ res: NextApiResponse,) {if (req.method === "GET") {// GET /api/links/domains/:domain/:slug@@ -27,6 +27,7 @@ export default async function handle(emailProtected: true,allowDownload: true,password: true,+ isArchived: true,document: {select: {id: true,@@ -44,24 +45,20 @@ export default async function handle(console.log("plan", link);if (!link || !link.document.team) {- return res- .status(404)- .json({- error: "Link not found",- message: `no link found, team ${link?.document.team}`,- });+ return res.status(404).json({+ error: "Link not found",+ message: `no link found, team ${link?.document.team}`,+ });}console.log("plan", link.document.team.plan);// if owner of document is on free plan, return 404if (link.document.team.plan === "free") {- return res- .status(404)- .json({- error: "Link not found",- message: `link found, team ${link.document.team.plan}`,- });+ return res.status(404).json({+ error: "Link not found",+ message: `link found, team ${link.document.team.plan}`,+ });}res.status(200).json(link);diff --git a/pages/view/[linkId].tsx b/pages/view/[linkId].tsxindex 395b1d5b..5ab98b1d 100644--- a/pages/view/[linkId].tsx+++ b/pages/view/[linkId].tsx@@ -20,13 +20,26 @@ export default function ViewPage() {);}- const { expiresAt, emailProtected, password: linkPassword } = link;+ const {+ expiresAt,+ emailProtected,+ password: linkPassword,+ isArchived,+ } = link;const { email: userEmail } = session?.user || {};// If the link is expired, show a 404 pageif (expiresAt && new Date(expiresAt) < new Date()) {- return <NotFound />;+ return (+ <NotFound message="Sorry, the link you're looking for is expired." />+ );+ }++ if (isArchived) {+ return (+ <NotFound message="Sorry, the file you're looking for is archived." />+ );}if (emailProtected || linkPassword) {diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsxindex 7f51598f..a53a7f0c 100644--- a/pages/view/domains/[domain]/[slug]/index.tsx+++ b/pages/view/domains/[domain]/[slug]/index.tsx@@ -9,7 +9,7 @@ export default function ViewPage() {const { data: session, status } = useSession();if (error && error.status === 404) {- return <NotFound />;+ <NotFound />;}if (!link || status === "loading") {@@ -20,13 +20,24 @@ export default function ViewPage() {);}- const { expiresAt, emailProtected, password: linkPassword } = link;+ const {+ expiresAt,+ emailProtected,+ password: linkPassword,+ isArchived,+ } = link;const { email: userEmail } = session?.user || {};// If the link is expired, show a 404 pageif (expiresAt && new Date(expiresAt) < new Date()) {- return <NotFound />;+ <NotFound message="Sorry, the link you're looking for is expired." />;+ }++ if (isArchived) {+ return (+ <NotFound message="Sorry, the file you're looking for is archived." />+ );}if (emailProtected || linkPassword) {