diff --git a/components/Modal/Link/PreservedFormats.tsx b/components/Modal/Link/PreservedFormats.tsx index 939f0c6..f7b5345 100644 --- a/components/Modal/Link/PreservedFormats.tsx +++ b/components/Modal/Link/PreservedFormats.tsx @@ -14,6 +14,10 @@ import useLinkStore from "@/store/links"; import { toast } from "react-hot-toast"; import { useRouter } from "next/router"; import { useSession } from "next-auth/react"; +import { + pdfAvailable, + screenshotAvailable, +} from "@/lib/shared/getArchiveValidity"; export default function PreservedFormats() { const session = useSession(); @@ -29,13 +33,13 @@ export default function PreservedFormats() { useEffect(() => { let interval: any; - if (link?.screenshotPath === "pending" || link?.pdfPath === "pending") { + if (screenshotAvailable(link) && pdfAvailable(link)) { let isPublicRoute = router.pathname.startsWith("/public") ? true : undefined; interval = setInterval( - () => getLink(link.id as number, isPublicRoute), + () => getLink(link?.id as number, isPublicRoute), 5000 ); } else { @@ -89,7 +93,7 @@ export default function PreservedFormats() { return (
- {link?.screenshotPath && link?.screenshotPath !== "pending" ? ( + {screenshotAvailable(link) ? (
@@ -112,7 +116,7 @@ export default function PreservedFormats() { ) : undefined} - {link?.pdfPath && link.pdfPath !== "pending" ? ( + {pdfAvailable(link) ? (
@@ -167,12 +171,7 @@ export default function PreservedFormats() { {link?.collection.ownerId === session.data?.user.id ? (
updateArchive()} > @@ -189,12 +188,7 @@ export default function PreservedFormats() { )}`} target="_blank" className={`text-neutral duration-100 hover:opacity-60 flex gap-2 w-fit items-center text-sm ${ - link?.pdfPath && - link?.screenshotPath && - link?.pdfPath !== "pending" && - link?.screenshotPath !== "pending" - ? "sm:mt-3" - : "" + screenshotAvailable(link) && pdfAvailable(link) ? "sm:mt-3" : "" }`} > - - Warning: Deleting this collection will permanently erase all - its contents - - , and it will become inaccessible to everyone, including members - with previous access. + Warning: Deleting this collection will permanently erase + all its contents, and it will become inaccessible to everyone, + including members with previous access.
diff --git a/components/ModalContent/DeleteLinkModal.tsx b/components/ModalContent/DeleteLinkModal.tsx index 6991128..dea90ab 100644 --- a/components/ModalContent/DeleteLinkModal.tsx +++ b/components/ModalContent/DeleteLinkModal.tsx @@ -70,7 +70,9 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) { d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /> - Warning: This action is irreversible! + + Warning: This action is irreversible! +

diff --git a/components/ModalContent/PreservedFormatsModal.tsx b/components/ModalContent/PreservedFormatsModal.tsx index 6d817bb..ff0556b 100644 --- a/components/ModalContent/PreservedFormatsModal.tsx +++ b/components/ModalContent/PreservedFormatsModal.tsx @@ -1,9 +1,4 @@ import React, { useEffect, useState } from "react"; -import { Toaster } from "react-hot-toast"; -import CollectionSelection from "@/components/InputSelect/CollectionSelection"; -import TagSelection from "@/components/InputSelect/TagSelection"; -import TextInput from "@/components/TextInput"; -import unescapeString from "@/lib/client/unescapeString"; import useLinkStore from "@/store/links"; import { ArchivedFormat, @@ -23,6 +18,10 @@ import Modal from "../Modal"; import { faFileImage, faFilePdf } from "@fortawesome/free-regular-svg-icons"; import { useRouter } from "next/router"; import { useSession } from "next-auth/react"; +import { + pdfAvailable, + screenshotAvailable, +} from "@/lib/shared/getArchiveValidity"; type Props = { onClose: Function; @@ -114,7 +113,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {

- {link?.screenshotPath && link?.screenshotPath !== "pending" ? ( + {screenshotAvailable(link) ? (
@@ -137,7 +136,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) { updateArchive()} > @@ -214,12 +208,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) { )}`} target="_blank" className={`text-neutral duration-100 hover:opacity-60 flex gap-2 w-1/2 justify-center items-center text-sm ${ - link?.pdfPath && - link?.screenshotPath && - link?.pdfPath !== "pending" && - link?.screenshotPath !== "pending" - ? "sm:mt-3" - : "" + screenshotAvailable(link) && pdfAvailable(link) ? "sm:mt-3" : "" }`} >

diff --git a/components/Navbar.tsx b/components/Navbar.tsx index e4dbb3a..c346752 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -68,7 +68,7 @@ export default function Navbar() {

-

+

+ + + + + +

{text || "You haven't created any Links Here"}

+

+ Start your journey by creating a new Link! +

{ diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx index 9df96d9..3aed4a4 100644 --- a/components/SearchBar.tsx +++ b/components/SearchBar.tsx @@ -58,7 +58,7 @@ export default function SearchBar({ placeholder }: Props) { } } }} - className="border border-neutral-content bg-base-200 focus:border-primary py-1 rounded-md pl-9 pr-2 w-44 sm:w-60 md:focus:w-80 duration-100 outline-none" + className="border border-neutral-content bg-base-200 focus:border-primary py-1 rounded-md pl-9 pr-2 w-full max-w-[15rem] md:focus:w-80 md:w-[15rem] md:max-w-full duration-200 outline-none" />
); diff --git a/lib/shared/getArchiveValidity.ts b/lib/shared/getArchiveValidity.ts new file mode 100644 index 0000000..0650e7c --- /dev/null +++ b/lib/shared/getArchiveValidity.ts @@ -0,0 +1,28 @@ +import { Link } from "@prisma/client"; + +export function screenshotAvailable(link: any) { + return ( + link && + link.screenshotPath && + link.screenshotPath !== "pending" && + link.screenshotPath !== "failed" + ); +} + +export function pdfAvailable(link: any) { + return ( + link && + link.pdfPath && + link.pdfPath !== "pending" && + link.pdfPath !== "failed" + ); +} + +export function readabilityAvailable(link: any) { + return ( + link && + link.readabilityPath && + link.readabilityPath !== "pending" && + link.readabilityPath !== "failed" + ); +} diff --git a/pages/links/[id].tsx b/pages/links/[id].tsx index ec40373..694932b 100644 --- a/pages/links/[id].tsx +++ b/pages/links/[id].tsx @@ -21,6 +21,7 @@ import { import useModalStore from "@/store/modals"; import { useSession } from "next-auth/react"; import useLocalSettingsStore from "@/store/localSettings"; +import { readabilityAvailable } from "@/lib/shared/getArchiveValidity"; type LinkContent = { title: string; @@ -66,11 +67,7 @@ export default function Index() { useEffect(() => { const fetchLinkContent = async () => { - if ( - router.query.id && - link?.readabilityPath && - link?.readabilityPath !== "pending" - ) { + if (router.query.id && readabilityAvailable(link)) { const response = await fetch( `/api/v1/archives/${link?.id}?format=${ArchivedFormat.readability}` ); @@ -86,11 +83,7 @@ export default function Index() { useEffect(() => { let interval: any; - if ( - link?.screenshotPath === "pending" || - link?.pdfPath === "pending" || - link?.readabilityPath === "pending" - ) { + if (link?.readabilityPath === "pending") { interval = setInterval(() => getLink(link.id as number), 5000); } else { if (interval) { diff --git a/pages/public/links/[id].tsx b/pages/public/links/[id].tsx index c26cc1c..d9641cc 100644 --- a/pages/public/links/[id].tsx +++ b/pages/public/links/[id].tsx @@ -17,6 +17,7 @@ import { faBoxesStacked, faFolder } from "@fortawesome/free-solid-svg-icons"; import useModalStore from "@/store/modals"; import { useSession } from "next-auth/react"; import useLocalSettingsStore from "@/store/localSettings"; +import { readabilityAvailable } from "@/lib/shared/getArchiveValidity"; type LinkContent = { title: string; @@ -62,11 +63,7 @@ export default function Index() { useEffect(() => { const fetchLinkContent = async () => { - if ( - router.query.id && - link?.readabilityPath && - link?.readabilityPath !== "pending" - ) { + if (router.query.id && readabilityAvailable(link)) { const response = await fetch( `/api/v1/archives/${link?.id}?format=${ArchivedFormat.readability}` ); @@ -82,11 +79,7 @@ export default function Index() { useEffect(() => { let interval: any; - if ( - link?.screenshotPath === "pending" || - link?.pdfPath === "pending" || - link?.readabilityPath === "pending" - ) { + if (link?.readabilityPath === "pending") { interval = setInterval(() => getLink(link.id as number, true), 5000); } else { if (interval) { diff --git a/scripts/worker.ts b/scripts/worker.ts index cba684c..213fa7c 100644 --- a/scripts/worker.ts +++ b/scripts/worker.ts @@ -15,8 +15,9 @@ type LinksAndCollectionAndOwner = Link & { }; async function processBatch() { - const links = await prisma.link.findMany({ + const linksOldToNew = await prisma.link.findMany({ where: { + url: { not: null }, OR: [ { collection: { @@ -71,6 +72,63 @@ async function processBatch() { }, }); + const linksNewToOld = await prisma.link.findMany({ + where: { + url: { not: null }, + OR: [ + { + collection: { + owner: { + archiveAsScreenshot: true, + }, + }, + screenshotPath: null, + }, + { + collection: { + owner: { + archiveAsScreenshot: true, + }, + }, + screenshotPath: "pending", + }, + /////////////////////// + { + collection: { + owner: { + archiveAsPDF: true, + }, + }, + pdfPath: null, + }, + { + collection: { + owner: { + archiveAsPDF: true, + }, + }, + pdfPath: "pending", + }, + /////////////////////// + { + readabilityPath: null, + }, + { + readabilityPath: "pending", + }, + ], + }, + take: archiveTakeCount, + orderBy: { createdAt: "desc" }, + include: { + collection: { + include: { + owner: true, + }, + }, + }, + }); + const archiveLink = async (link: LinksAndCollectionAndOwner) => { try { console.log( @@ -94,7 +152,9 @@ async function processBatch() { }; // Process each link in the batch concurrently - const processingPromises = links.map((e) => archiveLink(e)); + const processingPromises = [...linksOldToNew, ...linksNewToOld].map((e) => + archiveLink(e) + ); await Promise.allSettled(processingPromises); }