⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Verify the preference is available
Isaac Wiseef08edf1fb25
diff --git a/lib/client/generateLinkHref.ts b/lib/client/generateLinkHref.tsindex acb89c4a..d122383c 100644--- a/lib/client/generateLinkHref.ts+++ b/lib/client/generateLinkHref.ts@@ -1,18 +1,27 @@import useAccountStore from "@/store/account";import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags } from "@/types/global";import { LinksRouteTo } from "@prisma/client";+import { pdfAvailable, readabilityAvailable, screenshotAvailable } from "../shared/getArchiveValidity";export const generateLinkHref = (link: LinkIncludingShortenedCollectionAndTags): string => {const { account } = useAccountStore();+ // Return the links href based on the account's preference+ // If the user's preference is not available, return the original linkswitch (account.linksRouteTo) {case LinksRouteTo.ORIGINAL:return link.url || '';case LinksRouteTo.PDF:+ if (!pdfAvailable(link)) return link.url || '';+return `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;case LinksRouteTo.READABLE:+ if (!readabilityAvailable(link)) return link.url || '';+return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;case LinksRouteTo.SCREENSHOT:+ if (!screenshotAvailable(link)) return link.url || '';+return `/preserved/${link?.id}?format=${link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg}`;default:return link.url || '';diff --git a/lib/shared/getArchiveValidity.ts b/lib/shared/getArchiveValidity.tsindex 395de00c..ec74b22a 100644--- a/lib/shared/getArchiveValidity.ts+++ b/lib/shared/getArchiveValidity.ts@@ -1,4 +1,6 @@-export function screenshotAvailable(link: any) {+import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";++export function screenshotAvailable(link: LinkIncludingShortenedCollectionAndTags) {return (link &&link.image &&@@ -7,13 +9,13 @@ export function screenshotAvailable(link: any) {);}-export function pdfAvailable(link: any) {+export function pdfAvailable(link: LinkIncludingShortenedCollectionAndTags) {return (link && link.pdf && link.pdf !== "pending" && link.pdf !== "unavailable");}-export function readabilityAvailable(link: any) {+export function readabilityAvailable(link: LinkIncludingShortenedCollectionAndTags) {return (link &&link.readable &&