Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

Merge branch 'dev' of https://github.com/linkwarden/linkwarden into feat/single-file

daniel31x13359d22e61bf2
diff --cc components/LinkViews/LinkComponents/LinkIcon.tsx
index bbf61463,055b432d..e38e8d19
--- a/components/LinkViews/LinkComponents/LinkIcon.tsx
+++ b/components/LinkViews/LinkComponents/LinkIcon.tsx
@@@ -22,28 -38,38 +38,40 @@@ export default function LinkIcon(
return (
<>
- {link.url && url && showFavicon ? (
- <Image
- src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}
- width={64}
- height={64}
- alt=""
- className={iconClasses}
- draggable="false"
- onError={() => {
- setShowFavicon(false);
- }}
- />
- ) : showFavicon === false ? (
- <div className={iconClasses}>
- <i className="bi-link-45deg text-4xl text-black"></i>
- </div>
+ {link.type === "url" && url ? (
+ showFavicon ? (
+ <Image
+ src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}
+ width={64}
+ height={64}
+ alt=""
+ className={iconClasses + dimension}
+ draggable="false"
+ onError={() => {
+ setShowFavicon(false);
+ }}
+ />
+ ) : (
+ <LinkPlaceholderIcon
+ iconClasses={iconClasses + dimension}
+ size={size}
+ icon="bi-link-45deg"
+ />
+ )
) : link.type === "pdf" ? (
- <i className={`bi-file-earmark-pdf ${iconClasses}`}></i>
+ <LinkPlaceholderIcon
+ iconClasses={iconClasses + dimension}
+ size={size}
+ icon="bi-file-earmark-pdf"
+ />
) : link.type === "image" ? (
- <i className={`bi-file-earmark-image ${iconClasses}`}></i>
+ <LinkPlaceholderIcon
+ iconClasses={iconClasses + dimension}
+ size={size}
+ icon="bi-file-earmark-image"
+ />
+ ) : link.type === "singlefile" ? (
+ <i className={`bi-filetype-html ${iconClasses}`}></i>
) : undefined}
</>
);
diff --cc components/ModalContent/PreservedFormatsModal.tsx
index e6906a7f,66ae53cd..0030250e
--- a/components/ModalContent/PreservedFormatsModal.tsx
+++ b/components/ModalContent/PreservedFormatsModal.tsx
@@@ -18,7 -17,7 +18,8 @@@ import
import PreservedFormatRow from "@/components/PreserverdFormatRow";
import useAccountStore from "@/store/account";
import getPublicUserData from "@/lib/client/getPublicUserData";
+ import { useTranslation } from "next-i18next";
+import { BeatLoader } from "react-spinners";
type Props = {
onClose: Function;
@@@ -125,10 -108,10 +124,10 @@@ export default function PreservedFormat
clearInterval(interval);
}
};
- }, [link?.image, link?.pdf, link?.readable, link?.singlefile]);
- }, [link, getLink]);
++ }, [link, getLink, link?.singlefile]);
const updateArchive = async () => {
- const load = toast.loading("Sending request...");
+ const load = toast.loading(t("sending_request"));
const response = await fetch(`/api/v1/links/${link?.id}/archive`, {
method: "PUT",
@@@ -149,96 -131,58 +147,76 @@@
return (
<Modal toggleModal={onClose}>
- <p className="text-xl font-thin">Preserved Formats</p>
-
+ <p className="text-xl font-thin">{t("preserved_formats")}</p>
<div className="divider mb-2 mt-1"></div>
-
- {isReady() &&
- (screenshotAvailable(link) ||
- pdfAvailable(link) ||
- readabilityAvailable(link)) ? (
+ {screenshotAvailable(link) ||
+ pdfAvailable(link) ||
+ readabilityAvailable(link) ||
+ singlefileAvailable(link) ? (
- <p className="mb-3">
- The following formats are available for this link:
- </p>
+ <p className="mb-3">{t("available_formats")}</p>
) : (
""
)}
- <div className="flex flex-col gap-3">
- {isReady() ? (
- <>
- {screenshotAvailable(link) ? (
- <PreservedFormatRow
- name={t("screenshot")}
- icon={"bi-file-earmark-image"}
- format={
- link?.image?.endsWith("png")
- ? ArchivedFormat.png
- : ArchivedFormat.jpeg
- }
- activeLink={link}
- downloadable={true}
- />
- ) : undefined}
- {pdfAvailable(link) ? (
- <PreservedFormatRow
- name={t("pdf")}
- icon="bi-file-earmark-pdf"
- format={ArchivedFormat.pdf}
- activeLink={link}
- downloadable={true}
- />
- ) : undefined}
- {readabilityAvailable(link) ? (
- <PreservedFormatRow
- name={t("readable")}
- icon="bi-file-earmark-text"
- format={ArchivedFormat.readability}
- activeLink={link}
- />
- ) : undefined}
- </>
- ) : (
- <div className="w-full h-full flex flex-col justify-center p-10 skeleton bg-base-200">
- <i className="bi-stack drop-shadow text-primary text-8xl mx-auto mb-5"></i>
+ <div className={`flex flex-col gap-3`}>
+ {screenshotAvailable(link) ? (
+ <PreservedFormatRow
- name={"Screenshot"}
++ name={t("screenshot")}
+ icon={"bi-file-earmark-image"}
+ format={
+ link?.image?.endsWith("png")
+ ? ArchivedFormat.png
+ : ArchivedFormat.jpeg
+ }
+ activeLink={link}
+ downloadable={true}
+ />
+ ) : undefined}
+
+ {pdfAvailable(link) ? (
+ <PreservedFormatRow
- name={"PDF"}
++ name={t("pdf")}
+ icon={"bi-file-earmark-pdf"}
+ format={ArchivedFormat.pdf}
+ activeLink={link}
+ downloadable={true}
+ />
+ ) : undefined}
+
- {singlefileAvailable(link) ? (
- <PreservedFormatRow
- name={"SingleFile (Full Copy)"}
- icon={"bi-filetype-html"}
- format={ArchivedFormat.singlefile}
- activeLink={link}
- downloadable={true}
- />
- ) : undefined}
-
+ {readabilityAvailable(link) ? (
+ <PreservedFormatRow
- name={"Readable"}
++ name={t("readable")}
+ icon={"bi-file-earmark-text"}
+ format={ArchivedFormat.readability}
+ activeLink={link}
+ />
+ ) : undefined}
+
+ {!isReady() && !atLeastOneFormatAvailable() ? (
+ <div className={`w-full h-full flex flex-col justify-center p-10`}>
+ <BeatLoader
+ color="oklch(var(--p))"
+ className="mx-auto mb-3"
+ size={30}
+ />
+
- <p className="text-center text-2xl">
- Link preservation is in the queue
- </p>
- <p className="text-center text-lg">
- Please check back later to see the result
- </p>
+ <p className="text-center text-2xl">{t("preservation_in_queue")}</p>
+ <p className="text-center text-lg">{t("check_back_later")}</p>
</div>
- )}
+ ) : !isReady() && atLeastOneFormatAvailable() ? (
+ <div className={`w-full h-full flex flex-col justify-center p-5`}>
+ <BeatLoader
+ color="oklch(var(--p))"
+ className="mx-auto mb-3"
+ size={20}
+ />
+
+ <p className="text-center">
+ There are more preserved formats in the queue
+ </p>
- <p className="text-center text-sm">
- Please check back later to see the result
- </p>
++ <p className="text-center text-sm">{t("check_back_later")}</p>
+ </div>
+ ) : undefined}
<div
className={`flex flex-col sm:flex-row gap-3 items-center justify-center ${
diff --cc components/ModalContent/UploadFileModal.tsx
index 96617a79,1dc7a8c3..469bee6f
--- a/components/ModalContent/UploadFileModal.tsx
+++ b/components/ModalContent/UploadFileModal.tsx
@@@ -101,59 -92,21 +93,42 @@@ export default function UploadFileModal
const submit = async () => {
if (!submitLoader && file) {
- setSubmitLoader(true);
- const load = toast.loading(t("creating"));
+ let fileType: ArchivedFormat | null = null;
+ let linkType: "url" | "image" | "singlefile" | "pdf" | null = null;
+
+ if (file?.type === "image/jpg" || file.type === "image/jpeg") {
+ fileType = ArchivedFormat.jpeg;
+ linkType = "image";
+ } else if (file.type === "image/png") {
+ fileType = ArchivedFormat.png;
+ linkType = "image";
+ } else if (file.type === "text/html") {
+ fileType = ArchivedFormat.singlefile;
+ linkType = "singlefile";
+ } else if (file.type === "application/pdf") {
+ fileType = ArchivedFormat.pdf;
+ linkType = "pdf";
+ }
+
+ if (fileType !== null && linkType !== null) {
+ setSubmitLoader(true);
+
+ let response;
+
- const load = toast.loading("Creating...");
-
- response = await addLink({
- ...link,
- type: linkType,
- name: link.name ? link.name : file.name.replace(/\.[^/.]+$/, ""),
- });
-
- toast.dismiss(load);
++ const load = toast.loading(t("creating"));
- if (response.ok) {
- const formBody = new FormData();
- file && formBody.append("file", file);
+ const response = await uploadFile(link, file);
- await fetch(
- `/api/v1/archives/${
- (response.data as LinkIncludingShortenedCollectionAndTags).id
- }?format=${fileType}`,
- {
- body: formBody,
- method: "POST",
- }
- );
- toast.success(`Created!`);
- onClose();
- } else toast.error(response.data as string);
-
- setSubmitLoader(false);
-
- return response;
+ toast.dismiss(load);
+ if (response.ok) {
+ toast.success(t("created"));
+ onClose();
+ } else {
+ toast.error(response.data as string);
}
+
+ setSubmitLoader(false);
+ return response;
}
};
@@@ -175,8 -128,9 +150,9 @@@
/>
</label>
<p className="text-xs font-semibold mt-2">
- PDF, PNG, JPG, HTML (Up to {process.env.NEXT_PUBLIC_MAX_FILE_SIZE || 30}
- MB)
- {t("file_types", {
++ {t("file_types", {
+ size: process.env.NEXT_PUBLIC_MAX_FILE_SIZE || 30,
+ })}
</p>
</div>
<div className="sm:col-span-2 col-span-5">
diff --cc components/PreserverdFormatRow.tsx
index b50036a1,e7100cd3..a5c9061a
--- a/components/PreserverdFormatRow.tsx
+++ b/components/PreserverdFormatRow.tsx
@@@ -1,6 -1,9 +1,10 @@@
import React, { useEffect, useState } from "react";
import useLinkStore from "@/store/links";
- import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags } from "@/types/global";
+ import {
+ ArchivedFormat,
+ LinkIncludingShortenedCollectionAndTags,
+ } from "@/types/global";
++import toast from "react-hot-toast";
import Link from "next/link";
import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
@@@ -65,10 -68,10 +69,15 @@@ export default function PreservedFormat
.then((response) => {
if (response.ok) {
// Create a temporary link and click it to trigger the download
- const link = document.createElement("a");
- link.href = path;
- link.download = format === ArchivedFormat.pdf ? "PDF" : "Screenshot";
- link.click();
+ const anchorElement = document.createElement("a");
+ anchorElement.href = path;
- anchorElement.download = format === ArchivedFormat.singlefile ? (link.name ?? 'index') : format === ArchivedFormat.pdf ? "PDF" : "Screenshot";
++ anchorElement.download =
++ format === ArchivedFormat.singlefile
++ ? link.name ?? "index"
++ : format === ArchivedFormat.pdf
++ ? "PDF"
++ : "Screenshot";
+ anchorElement.click();
} else {
console.error("Failed to download file");
}
diff --cc lib/api/archiveHandler.ts
index acec0a70,0cb514d7..24212a0f
--- a/lib/api/archiveHandler.ts
+++ b/lib/api/archiveHandler.ts
@@@ -1,14 -1,15 +1,14 @@@
import { LaunchOptions, chromium, devices } from "playwright";
import { prisma } from "./db";
import createFile from "./storage/createFile";
-import sendToWayback from "./sendToWayback";
-import { Readability } from "@mozilla/readability";
-import { JSDOM } from "jsdom";
-import DOMPurify from "dompurify";
+import sendToWayback from "./preservationScheme/sendToWayback";
import { Collection, Link, User } from "@prisma/client";
import validateUrlSize from "./validateUrlSize";
- import removeFile from "./storage/removeFile";
- import Jimp from "jimp";
import createFolder from "./storage/createFolder";
+ import generatePreview from "./generatePreview";
+ import { removeFiles } from "./manageLinkFiles";
+import archiveAsSinglefile from "./preservationScheme/archiveAsSinglefile";
+import archiveAsReadability from "./preservationScheme/archiveAsReadablility";
type LinksAndCollectionAndOwner = Link & {
collection: Collection & {
@@@ -134,152 -168,106 +163,143 @@@ export default async function archiveHa
// Preview
- if (
- !link.preview?.startsWith("archives") &&
- !link.preview?.startsWith("unavailable")
- ) {
- const ogImageUrl = await page.evaluate(() => {
- const metaTag = document.querySelector(
- 'meta[property="og:image"]'
- );
- return metaTag ? (metaTag as any).content : null;
- });
-
- createFolder({
- filePath: `archives/preview/${link.collectionId}`,
- });
+ const ogImageUrl = await page.evaluate(() => {
+ const metaTag = document.querySelector('meta[property="og:image"]');
+ return metaTag ? (metaTag as any).content : null;
+ });
- if (ogImageUrl) {
- console.log("Found og:image URL:", ogImageUrl);
+ if (ogImageUrl) {
+ console.log("Found og:image URL:", ogImageUrl);
- // Download the image
- const imageResponse = await page.goto(ogImageUrl);
+ // Download the image
+ const imageResponse = await page.goto(ogImageUrl);
- // Check if imageResponse is not null
- if (imageResponse && !link.preview?.startsWith("archive")) {
- const buffer = await imageResponse.body();
-
- // Check if buffer is not null
- if (buffer) {
- // Load the image using Jimp
- Jimp.read(buffer, async (err, image) => {
- if (image && !err) {
- image?.resize(1280, Jimp.AUTO).quality(20);
- const processedBuffer = await image?.getBufferAsync(
- Jimp.MIME_JPEG
- );
-
- createFile({
- data: processedBuffer,
- filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
- }).then(() => {
- return prisma.link.update({
- where: { id: link.id },
- data: {
- preview: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
- },
- });
+ // Check if imageResponse is not null
+ if (imageResponse && !link.preview?.startsWith("archive")) {
+ const buffer = await imageResponse.body();
+ await generatePreview(buffer, link.collectionId, link.id);
- }
+
- await page.goBack();
- } else if (!link.preview?.startsWith("archive")) {
- console.log("No og:image found");
- await page
- .screenshot({ type: "jpeg", quality: 20 })
- .then((screenshot) => {
- return createFile({
- data: screenshot,
- filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
- });
- })
- .then(() => {
- return prisma.link.update({
- where: { id: link.id },
- data: {
- preview: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
- },
++ // Check if buffer is not null
++ if (buffer) {
++ // Load the image using Jimp
++ Jimp.read(buffer, async (err, image) => {
++ if (image && !err) {
++ image?.resize(1280, Jimp.AUTO).quality(20);
++ const processedBuffer = await image?.getBufferAsync(
++ Jimp.MIME_JPEG
++ );
++
++ createFile({
++ data: processedBuffer,
++ filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
++ }).then(() => {
++ return prisma.link.update({
++ where: { id: link.id },
++ data: {
++ preview: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
++ },
+ });
- }
- }).catch((err) => {
- console.error("Error processing the image:", err);
- });
- } else {
- console.log("No image data found.");
- }
++ });
++ }
++ }).catch((err) => {
++ console.error("Error processing the image:", err);
+ });
- });
- }
-
- // Screenshot/PDF
- await page.evaluate(
- autoScroll,
- Number(process.env.AUTOSCROLL_TIMEOUT) || 30
- );
++ } else {
++ console.log("No image data found.");
+ }
++ }
- // Check if the user hasn't deleted the link by the time we're done scrolling
- const linkExists = await prisma.link.findUnique({
- where: { id: link.id },
- });
- if (linkExists) {
- const processingPromises = [];
-
- if (
- user.archiveAsScreenshot &&
- !link.image?.startsWith("archive")
- ) {
- processingPromises.push(
- page.screenshot({ fullPage: true }).then((screenshot) => {
+ await page.goBack();
+ } else if (!link.preview?.startsWith("archive")) {
+ console.log("No og:image found");
+ await page
+ .screenshot({ type: "jpeg", quality: 20 })
+ .then((screenshot) => {
return createFile({
data: screenshot,
- filePath: `archives/${linkExists.collectionId}/${link.id}.png`,
+ filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
});
})
- );
+ .then(() => {
+ return prisma.link.update({
+ where: { id: link.id },
+ data: {
+ preview: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
+ },
+ });
+ });
}
+ }
- // apply administrator's defined pdf margins or default to 15px
- const margins = {
- top: process.env.PDF_MARGIN_TOP || "15px",
- bottom: process.env.PDF_MARGIN_BOTTOM || "15px",
- };
-
- if (user.archiveAsPDF && !link.pdf?.startsWith("archive")) {
- processingPromises.push(
- page
- .pdf({
- width: "1366px",
- height: "1931px",
- printBackground: true,
- margin: margins,
- })
- .then((pdf) => {
+ if (
+ (!link.image?.startsWith("archives") &&
+ !link.image?.startsWith("unavailable")) ||
+ (!link.pdf?.startsWith("archives") &&
+ !link.pdf?.startsWith("unavailable"))
+ ) {
+ // Screenshot/PDF
+ await page.evaluate(
+ autoScroll,
+ Number(process.env.AUTOSCROLL_TIMEOUT) || 30
+ );
+
+ // Check if the user hasn't deleted the link by the time we're done scrolling
+ const linkExists = await prisma.link.findUnique({
+ where: { id: link.id },
+ });
+ if (linkExists) {
+ const processingPromises = [];
+
+ if (
+ user.archiveAsScreenshot &&
+ !link.image?.startsWith("archive")
+ ) {
+ processingPromises.push(
+ page.screenshot({ fullPage: true }).then((screenshot) => {
return createFile({
- data: pdf,
- filePath: `archives/${linkExists.collectionId}/${link.id}.pdf`,
+ data: screenshot,
+ filePath: `archives/${linkExists.collectionId}/${link.id}.png`,
});
})
- );
+ );
+ }
+
+ // apply administrator's defined pdf margins or default to 15px
+ const margins = {
+ top: process.env.PDF_MARGIN_TOP || "15px",
+ bottom: process.env.PDF_MARGIN_BOTTOM || "15px",
+ };
+
+ if (user.archiveAsPDF && !link.pdf?.startsWith("archive")) {
+ processingPromises.push(
+ page
+ .pdf({
+ width: "1366px",
+ height: "1931px",
+ printBackground: true,
+ margin: margins,
+ })
+ .then((pdf) => {
+ return createFile({
+ data: pdf,
+ filePath: `archives/${linkExists.collectionId}/${link.id}.pdf`,
+ });
+ })
+ );
+ }
+ await Promise.allSettled(processingPromises);
+ await prisma.link.update({
+ where: { id: link.id },
+ data: {
+ image: user.archiveAsScreenshot
+ ? `archives/${linkExists.collectionId}/${link.id}.png`
+ : undefined,
+ pdf: user.archiveAsPDF
+ ? `archives/${linkExists.collectionId}/${link.id}.pdf`
+ : undefined,
+ },
+ });
}
- await Promise.allSettled(processingPromises);
- await prisma.link.update({
- where: { id: link.id },
- data: {
- image: user.archiveAsScreenshot
- ? `archives/${linkExists.collectionId}/${link.id}.png`
- : undefined,
- pdf: user.archiveAsPDF
- ? `archives/${linkExists.collectionId}/${link.id}.pdf`
- : undefined,
- },
- });
}
}
})(),
diff --cc lib/api/controllers/users/userId/updateUserById.ts
index 60c47347,b6e8bea5..fe55b057
--- a/lib/api/controllers/users/userId/updateUserById.ts
+++ b/lib/api/controllers/users/userId/updateUserById.ts
@@@ -186,8 -205,8 +205,9 @@@ export default async function updateUse
collectionOrder: data.collectionOrder.filter(
(value, index, self) => self.indexOf(value) === index
),
+ locale: i18n.locales.includes(data.locale) ? data.locale : "en",
archiveAsScreenshot: data.archiveAsScreenshot,
+ archiveAsSinglefile: data.archiveAsSinglefile,
archiveAsPDF: data.archiveAsPDF,
archiveAsWaybackMachine: data.archiveAsWaybackMachine,
linksRouteTo: data.linksRouteTo,
diff --cc lib/client/generateLinkHref.ts
index fcac1dbd,f012ab90..dd1c3984
--- a/lib/client/generateLinkHref.ts
+++ b/lib/client/generateLinkHref.ts
@@@ -7,8 -7,7 +7,8 @@@ import { LinksRouteTo } from "@prisma/c
import {
pdfAvailable,
readabilityAvailable,
- singlefileAvailable,
screenshotAvailable,
++ singlefileAvailable,
} from "../shared/getArchiveValidity";
export const generateLinkHref = (
@@@ -17,28 -16,30 +17,33 @@@
): string => {
// 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 || "";
+ if (account.linksRouteTo === LinksRouteTo.ORIGINAL && link.type === "url") {
+ return link.url || "";
+ } else if (account.linksRouteTo === LinksRouteTo.PDF || link.type === "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.pdf}`;
+ } else if (
+ account.linksRouteTo === LinksRouteTo.READABLE &&
+ link.type === "url"
+ ) {
+ if (!readabilityAvailable(link)) return link.url || "";
- return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
- case LinksRouteTo.SINGLEFILE:
- if (!singlefileAvailable(link)) return link.url || "";
+ return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
+ } else if (
+ account.linksRouteTo === LinksRouteTo.SCREENSHOT ||
+ link.type === "image"
+ ) {
- console.log(link);
+ if (!screenshotAvailable(link)) return link.url || "";
- return `/preserved/${link?.id}?format=${ArchivedFormat.singlefile}`;
- case LinksRouteTo.SCREENSHOT:
- if (!screenshotAvailable(link)) return link.url || "";
+ return `/preserved/${link?.id}?format=${
+ link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg
+ }`;
++ } else if (account.linksRouteTo === LinksRouteTo.SINGLEFILE) {
++ if (!singlefileAvailable(link)) return link.url || "";
+
- return `/preserved/${link?.id}?format=${
- link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg
- }`;
- default:
- return link.url || "";
++ return `/preserved/${link?.id}?format=${ArchivedFormat.singlefile}`;
+ } else {
+ return link.url || "";
}
};
diff --cc pages/settings/preference.tsx
index 962c061f,7579c571..5502778b
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@@ -10,25 -10,25 +10,31 @@@ import getServerSideProps from "@/lib/c
import { LinksRouteTo } from "@prisma/client";
export default function Appearance() {
+ const { t } = useTranslation();
const { updateSettings } = useLocalSettingsStore();
-
const [submitLoader, setSubmitLoader] = useState(false);
const { account, updateAccount } = useAccountStore();
- const [user, setUser] = useState<AccountSettings>(account);
+ const [user, setUser] = useState(account);
- const [preventDuplicateLinks, setPreventDuplicateLinks] =
- useState<boolean>(false);
- const [archiveAsScreenshot, setArchiveAsScreenshot] =
- useState<boolean>(false);
- const [archiveAsSinglefile, setArchiveAsSinglefile] =
- useState<boolean>(false);
- const [archiveAsPDF, setArchiveAsPDF] = useState<boolean>(false);
- const [archiveAsWaybackMachine, setArchiveAsWaybackMachine] =
- useState<boolean>(false);
- const [linksRouteTo, setLinksRouteTo] = useState<LinksRouteTo>(
- user.linksRouteTo
+ const [preventDuplicateLinks, setPreventDuplicateLinks] = useState<boolean>(
+ account.preventDuplicateLinks
+ );
+ const [archiveAsScreenshot, setArchiveAsScreenshot] = useState<boolean>(
+ account.archiveAsScreenshot
+ );
+ const [archiveAsPDF, setArchiveAsPDF] = useState<boolean>(
+ account.archiveAsPDF
+ );
++
++ const [archiveAsSinglefile, setArchiveAsSinglefile] = useState<boolean>(
++ account.archiveAsSinglefile
+ );
+
+ const [archiveAsWaybackMachine, setArchiveAsWaybackMachine] =
+ useState<boolean>(account.archiveAsWaybackMachine);
++
+ const [linksRouteTo, setLinksRouteTo] = useState(account.linksRouteTo);
+
useEffect(() => {
setUser({
...account,
@@@ -133,15 -125,8 +134,15 @@@
state={archiveAsScreenshot}
onClick={() => setArchiveAsScreenshot(!archiveAsScreenshot)}
/>
+
+ <Checkbox
+ label="Singlefile"
+ state={archiveAsSinglefile}
+ onClick={() => setArchiveAsSinglefile(!archiveAsSinglefile)}
+ />
+
<Checkbox
- label="PDF"
+ label={t("pdf")}
state={archiveAsPDF}
onClick={() => setArchiveAsPDF(!archiveAsPDF)}
/>
@@@ -215,25 -199,11 +215,43 @@@
checked={linksRouteTo === LinksRouteTo.READABLE}
onChange={() => setLinksRouteTo(LinksRouteTo.READABLE)}
/>
- <span className="label-text">Open Readable, if available</span>
+ <span className="label-text">
+ {t("open_readable_if_available")}
+ </span>
+ </label>
+
++ <label
++ className="label cursor-pointer flex gap-2 justify-start w-fit"
++ tabIndex={0}
++ role="button"
++ >
++ <input
++ type="radio"
++ name="link-preference-radio"
++ className="radio checked:bg-primary"
++ value="Singlefile"
++ checked={linksRouteTo === LinksRouteTo.SINGLEFILE}
++ onChange={() => setLinksRouteTo(LinksRouteTo.SINGLEFILE)}
++ />
++ <span className="label-text">Open Singlefile, if available</span>
+ </label>
+
+ <label
+ className="label cursor-pointer flex gap-2 justify-start w-fit"
+ tabIndex={0}
+ role="button"
+ >
+ <input
+ type="radio"
+ name="link-preference-radio"
+ className="radio checked:bg-primary"
+ value="Singlefile"
+ checked={linksRouteTo === LinksRouteTo.SINGLEFILE}
+ onChange={() => setLinksRouteTo(LinksRouteTo.SINGLEFILE)}
+ />
+ <span className="label-text">Open Singlefile, if available</span>
+ </label>
+
<label
className="label cursor-pointer flex gap-2 justify-start w-fit"
tabIndex={0}
diff --cc prisma/schema.prisma
index 88e494c7,b1af7174..5e81c398
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@@ -129,8 -137,8 +139,9 @@@ model Link
image String?
pdf String?
readable String?
+ singlefile String?
lastPreserved DateTime?
+ importDate DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}