@@ -102,8 +99,8 @@ export default function LinkCardCompact({
collection={collection}
position="top-3 right-3"
flipDropdown={flipDropdown}
- // toggleShowInfo={() => setShowInfo(!showInfo)}
- // linkInfo={showInfo}
+ // toggleShowInfo={() => setShowInfo(!showInfo)}
+ // linkInfo={showInfo}
/>
{showInfo ? (
diff --git a/lib/api/controllers/users/userId/updateUserById.ts b/lib/api/controllers/users/userId/updateUserById.ts
index 285e44e..162f246 100644
--- a/lib/api/controllers/users/userId/updateUserById.ts
+++ b/lib/api/controllers/users/userId/updateUserById.ts
@@ -97,18 +97,18 @@ export default async function updateUserById(
id: { not: userId },
OR: emailEnabled
? [
- {
- username: data.username.toLowerCase(),
- },
- {
- email: data.email?.toLowerCase(),
- },
- ]
+ {
+ username: data.username.toLowerCase(),
+ },
+ {
+ email: data.email?.toLowerCase(),
+ },
+ ]
: [
- {
- username: data.username.toLowerCase(),
- },
- ],
+ {
+ username: data.username.toLowerCase(),
+ },
+ ],
},
});
@@ -186,6 +186,7 @@ export default async function updateUserById(
archiveAsScreenshot: data.archiveAsScreenshot,
archiveAsPDF: data.archiveAsPDF,
archiveAsWaybackMachine: data.archiveAsWaybackMachine,
+ linksRouteTo: data.linksRouteTo,
password:
data.newPassword && data.newPassword !== ""
? newHashedPassword
diff --git a/lib/client/generateLinkHref.ts b/lib/client/generateLinkHref.ts
new file mode 100644
index 0000000..d122383
--- /dev/null
+++ b/lib/client/generateLinkHref.ts
@@ -0,0 +1,29 @@
+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 link
+ switch (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 || '';
+ }
+};
\ No newline at end of file
diff --git a/lib/shared/getArchiveValidity.ts b/lib/shared/getArchiveValidity.ts
index 395de00..ec74b22 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 &&
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index ed6cc02..a831b92 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -7,6 +7,7 @@ import React from "react";
import useLocalSettingsStore from "@/store/localSettings";
import Checkbox from "@/components/Checkbox";
import SubmitButton from "@/components/SubmitButton";
+import { LinksRouteTo } from "@prisma/client";
export default function Appearance() {
const { updateSettings } = useLocalSettingsStore();
@@ -20,6 +21,9 @@ export default function Appearance() {
const [archiveAsPDF, setArchiveAsPDF] = useState
(false);
const [archiveAsWaybackMachine, setArchiveAsWaybackMachine] =
useState(false);
+ const [linksRouteTo, setLinksRouteTo] = useState(
+ user.linksRouteTo
+ );
useEffect(() => {
setUser({
@@ -27,8 +31,15 @@ export default function Appearance() {
archiveAsScreenshot,
archiveAsPDF,
archiveAsWaybackMachine,
+ linksRouteTo,
});
- }, [account, archiveAsScreenshot, archiveAsPDF, archiveAsWaybackMachine]);
+ }, [
+ account,
+ archiveAsScreenshot,
+ archiveAsPDF,
+ archiveAsWaybackMachine,
+ linksRouteTo,
+ ]);
function objectIsEmpty(obj: object) {
return Object.keys(obj).length === 0;
@@ -39,6 +50,7 @@ export default function Appearance() {
setArchiveAsScreenshot(account.archiveAsScreenshot);
setArchiveAsPDF(account.archiveAsPDF);
setArchiveAsWaybackMachine(account.archiveAsWaybackMachine);
+ setLinksRouteTo(account.linksRouteTo);
}
}, [account]);
@@ -134,6 +146,71 @@ export default function Appearance() {
Clicking on Links should:
+
+
+
+
+
+
+
+
+