Verify the preference is available
This commit is contained in:
parent
39261de45e
commit
ef08edf1fb
|
@ -1,18 +1,27 @@
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import { LinksRouteTo } from "@prisma/client";
|
import { LinksRouteTo } from "@prisma/client";
|
||||||
|
import { pdfAvailable, readabilityAvailable, screenshotAvailable } from "../shared/getArchiveValidity";
|
||||||
|
|
||||||
export const generateLinkHref = (link: LinkIncludingShortenedCollectionAndTags): string => {
|
export const generateLinkHref = (link: LinkIncludingShortenedCollectionAndTags): string => {
|
||||||
const { account } = useAccountStore();
|
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) {
|
switch (account.linksRouteTo) {
|
||||||
case LinksRouteTo.ORIGINAL:
|
case LinksRouteTo.ORIGINAL:
|
||||||
return link.url || '';
|
return link.url || '';
|
||||||
case LinksRouteTo.PDF:
|
case LinksRouteTo.PDF:
|
||||||
|
if (!pdfAvailable(link)) return link.url || '';
|
||||||
|
|
||||||
return `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;
|
return `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;
|
||||||
case LinksRouteTo.READABLE:
|
case LinksRouteTo.READABLE:
|
||||||
|
if (!readabilityAvailable(link)) return link.url || '';
|
||||||
|
|
||||||
return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
|
return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
|
||||||
case LinksRouteTo.SCREENSHOT:
|
case LinksRouteTo.SCREENSHOT:
|
||||||
|
if (!screenshotAvailable(link)) return link.url || '';
|
||||||
|
|
||||||
return `/preserved/${link?.id}?format=${link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg}`;
|
return `/preserved/${link?.id}?format=${link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg}`;
|
||||||
default:
|
default:
|
||||||
return link.url || '';
|
return link.url || '';
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export function screenshotAvailable(link: any) {
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
|
|
||||||
|
export function screenshotAvailable(link: LinkIncludingShortenedCollectionAndTags) {
|
||||||
return (
|
return (
|
||||||
link &&
|
link &&
|
||||||
link.image &&
|
link.image &&
|
||||||
|
@ -7,13 +9,13 @@ export function screenshotAvailable(link: any) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pdfAvailable(link: any) {
|
export function pdfAvailable(link: LinkIncludingShortenedCollectionAndTags) {
|
||||||
return (
|
return (
|
||||||
link && link.pdf && link.pdf !== "pending" && link.pdf !== "unavailable"
|
link && link.pdf && link.pdf !== "pending" && link.pdf !== "unavailable"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readabilityAvailable(link: any) {
|
export function readabilityAvailable(link: LinkIncludingShortenedCollectionAndTags) {
|
||||||
return (
|
return (
|
||||||
link &&
|
link &&
|
||||||
link.readable &&
|
link.readable &&
|
||||||
|
|
Ŝarĝante…
Reference in New Issue