Skip to content

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

Start worker archival update/delete options

Isaacc79078131589
diff --git a/components/SettingsSidebar.tsx b/components/SettingsSidebar.tsx
index d4eb6fad..653f8d81 100644
--- a/components/SettingsSidebar.tsx
+++ b/components/SettingsSidebar.tsx
@@ -3,12 +3,15 @@ import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { useTranslation } from "next-i18next";
import { useUser } from "@/hooks/store/user";
+import { useConfig } from "@/hooks/store/config";
export default function SettingsSidebar({ className }: { className?: string }) {
const { t } = useTranslation();
const LINKWARDEN_VERSION = process.env.version;
const { data: user } = useUser();
+ const { data: config } = useConfig();
+ const isAdmin = user.id === (config?.ADMIN || 1);
const router = useRouter();
const [active, setActive] = useState("");
@@ -19,18 +22,16 @@ export default function SettingsSidebar({ className }: { className?: string }) {
return (
<div
- className={`bg-base-100 h-full w-64 overflow-y-auto border-solid border border-base-100 border-r-neutral-content p-5 z-20 flex flex-col gap-5 justify-between ${
- className || ""
- }`}
+ className={`bg-base-100 h-full w-64 overflow-y-auto border-solid border border-base-100 border-r-neutral-content p-5 z-20 flex flex-col gap-5 justify-between ${className || ""
+ }`}
>
<div className="flex flex-col gap-1">
<Link href="/settings/account">
<div
- className={`${
- active === "/settings/account"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/account"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-person text-primary text-2xl"></i>
<p className="truncate w-full pr-7">{t("account")}</p>
@@ -39,11 +40,10 @@ export default function SettingsSidebar({ className }: { className?: string }) {
<Link href="/settings/preference">
<div
- className={`${
- active === "/settings/preference"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/preference"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-sliders text-primary text-2xl"></i>
<p className="truncate w-full pr-7">{t("preference")}</p>
@@ -52,11 +52,10 @@ export default function SettingsSidebar({ className }: { className?: string }) {
<Link href="/settings/rss-subscriptions">
<div
- className={`${
- active === "/settings/rss-subscriptions"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/rss-subscriptions"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-rss text-primary text-2xl"></i>
<p className="truncate w-full pr-7">RSS Subscriptions</p>
@@ -65,11 +64,10 @@ export default function SettingsSidebar({ className }: { className?: string }) {
<Link href="/settings/access-tokens">
<div
- className={`${
- active === "/settings/access-tokens"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/access-tokens"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-key text-primary text-2xl"></i>
<p className="truncate w-full pr-7">{t("access_tokens")}</p>
@@ -78,25 +76,37 @@ export default function SettingsSidebar({ className }: { className?: string }) {
<Link href="/settings/password">
<div
- className={`${
- active === "/settings/password"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/password"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-lock text-primary text-2xl"></i>
<p className="truncate w-full pr-7">{t("password")}</p>
</div>
</Link>
+ {isAdmin && (
+ <Link href="/settings/worker">
+ <div
+ className={`${active === "/settings/worker"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ >
+ <i className="bi-gear-wide-connected text-primary text-2xl"></i>
+ <p className="truncate w-full pr-7">{t("worker")}</p>
+ </div>
+ </Link>
+ )}
+
{process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (
<Link href="/settings/billing">
<div
- className={`${
- active === "/settings/billing"
- ? "bg-primary/20"
- : "hover:bg-neutral/20"
- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
+ className={`${active === "/settings/billing"
+ ? "bg-primary/20"
+ : "hover:bg-neutral/20"
+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<i className="bi-credit-card text-primary text-2xl"></i>
<p className="truncate w-full pr-7">{t("billing")}</p>
diff --git a/hooks/store/worker.tsx b/hooks/store/worker.tsx
new file mode 100644
index 00000000..dda2aa8e
--- /dev/null
+++ b/hooks/store/worker.tsx
@@ -0,0 +1,25 @@
+import { LinkArchiveActionSchemaType } from "@/lib/shared/schemaValidation";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
+
+const useDeleteAllPreserved = () => {
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn: async (action: LinkArchiveActionSchemaType) => {
+ const response = await fetch("/api/v1/links/archive", {
+ body: JSON.stringify({ action }),
+ method: "DELETE",
+ });
+
+ const data = await response.json();
+ if (!response.ok) throw new Error(data.response);
+
+ return data.response;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["links"] });
+ },
+ });
+}
+
+export { useDeleteAllPreserved };
diff --git a/hooks/useArchivalTags.ts b/hooks/useArchivalTags.ts
index 21e3c936..40ba67a1 100644
--- a/hooks/useArchivalTags.ts
+++ b/hooks/useArchivalTags.ts
@@ -1,5 +1,5 @@
-import { ArchivalOptionKeys, ArchivalTagOption } from '@/components/InputSelect/types';
import { Tag } from '@prisma/client';
+import { ArchivalOptionKeys, ArchivalTagOption } from '../components/InputSelect/types';
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.ts
index 8a734326..f56b6324 100644
--- a/lib/shared/schemaValidation.ts
+++ b/lib/shared/schemaValidation.ts
@@ -240,10 +240,8 @@ export const PostArchivalTagSchema = z.object({
),
});
-export const DeleteLinksArchiveSchema = z.object({
- action: z.enum(["delete", "re-preserve"]),
+export const LinkArchiveActionSchema = z.object({
+ action: z.enum(["allAndRePreserve", "allAndIgnore", "allBroken"]),
});
-export const PutLinksArchiveSchema = z.object({
- links: z.array(z.number()).optional(),
-});
\ No newline at end of file
+export type LinkArchiveActionSchemaType = "allAndRePreserve" | "allAndIgnore" | "allBroken";
diff --git a/pages/api/v1/links/archive/index.ts b/pages/api/v1/links/archive/index.ts
index 794c201d..77a9baa4 100644
--- a/pages/api/v1/links/archive/index.ts
+++ b/pages/api/v1/links/archive/index.ts
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next";
import verifyUser from "@/lib/api/verifyUser";
import { prisma } from "@/lib/api/db";
-import { DeleteLinksArchiveSchema, PutLinksArchiveSchema } from "@/lib/shared/schemaValidation";
+import { LinkArchiveActionSchema } from "@/lib/shared/schemaValidation";
import { removeFiles } from "@/lib/api/manageLinkFiles";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
@@ -14,82 +14,8 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
return res.status(401).json({ response: "Permission denied." });
}
- if (req.method === "PUT") {
- const dataValidation = PutLinksArchiveSchema.safeParse(req.body);
- if (!dataValidation.success) {
- return res.status(400).json({
- response: `Error: ${dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
- });
- }
-
- const { links } = dataValidation.data;
-
- if (links && links.length > 0) {
- const brokenArchives = await prisma.link.findMany({
- where: {
- id: {
- in: links,
- },
- OR: [
- { image: "unavailable" },
- { pdf: "unavailable" },
- { readable: "unavailable" },
- { monolith: "unavailable" },
- { preview: "unavailable" },
- ],
- },
- });
-
- for (const link of brokenArchives) {
- await removeFiles(link.id, link.collectionId)
- await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
- image: null,
- pdf: null,
- readable: null,
- monolith: null,
- preview: null,
- }
- })
- }
- } else {
- const brokenArchives = await prisma.link.findMany({
- where: {
- OR: [
- { image: "unavailable" },
- { pdf: "unavailable" },
- { readable: "unavailable" },
- { monolith: "unavailable" },
- ],
- },
- });
-
- for (const link of brokenArchives) {
- await removeFiles(link.id, link.collectionId)
- await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
- image: null,
- pdf: null,
- readable: null,
- monolith: null,
- preview: null,
- }
- })
- }
- }
-
- return res.status(200).json({ response: "Broken archives deleted." });
- }
-
if (req.method === "DELETE") {
- const dataValidation = DeleteLinksArchiveSchema.safeParse(req.body);
+ const dataValidation = LinkArchiveActionSchema.safeParse(req.body);
if (!dataValidation.success) {
return res.status(400).json({
response: `Error: ${dataValidation.error.issues[0].message
@@ -99,7 +25,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
const { action } = dataValidation.data;
- if (action === 'delete') {
+ if (action === "allAndIgnore") {
const allLinks = await prisma.link.findMany();
for (const link of allLinks) {
@@ -118,8 +44,8 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
})
}
- return res.status(200).json({ response: "All archives deleted" });
- } else if (action === 're-preserve') {
+ return res.status(200).json({ response: "Success." });
+ } else if (action === "allAndRePreserve") {
const allLinks = await prisma.link.findMany();
for (const link of allLinks) {
@@ -137,7 +63,46 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
}
})
}
- return res.status(200).json({ response: "All archives deleted and are re-preserving" });
+
+ return res.status(200).json({ response: "Success." });
+ } else if (action === "allBroken") {
+ const brokenArchives = await prisma.link.findMany({
+ where: {
+ OR: [
+ { image: "unavailable" },
+ { pdf: "unavailable" },
+ { readable: "unavailable" },
+ { monolith: "unavailable" },
+ { preview: "unavailable" },
+ ],
+ },
+ include: {
+ createdBy: {
+ select: {
+ archiveAsScreenshot: true,
+ archiveAsMonolith: true,
+ archiveAsPDF: true,
+ archiveAsReadable: true,
+ archiveAsWaybackMachine: true,
+ }
+ },
+ tags: {
+ select: {
+ archiveAsScreenshot: true,
+ archiveAsMonolith: true,
+ archiveAsPDF: true,
+ archiveAsReadable: true,
+ archiveAsWaybackMachine: true,
+ }
+ }
+ }
+ });
+
+ // Need to check tags & user options for archival formats
+ // and then if the link is missing the same excluded formats
+ // then we can ignore it
+
+ return res.status(200).json({ response: "Success." });
}
}
}
diff --git a/pages/settings/rss-subscriptions.tsx b/pages/settings/rss-subscriptions.tsx
index bd7906b8..bc897b4c 100644
--- a/pages/settings/rss-subscriptions.tsx
+++ b/pages/settings/rss-subscriptions.tsx
@@ -6,7 +6,6 @@ import DeleteRssSubscriptionModal from "@/components/ModalContent/DeleteRssSubsc
import { useState } from "react";
import { RssSubscription } from "@prisma/client";
import NewRssSubscriptionModal from "@/components/ModalContent/NewRssSubscriptionModal";
-import Link from "next/link";
import { useConfig } from "@/hooks/store/config";
export default function RssSubscriptions() {
diff --git a/pages/settings/worker.tsx b/pages/settings/worker.tsx
new file mode 100644
index 00000000..78540636
--- /dev/null
+++ b/pages/settings/worker.tsx
@@ -0,0 +1,41 @@
+import SettingsLayout from "@/layouts/SettingsLayout";
+import { useTranslation } from "next-i18next";
+import getServerSideProps from "@/lib/client/getServerSideProps";
+import { useLinks } from "@/hooks/store/links";
+
+export default function Worker() {
+ const { t } = useTranslation();
+ const { links } = useLinks();
+
+ return (
+ <SettingsLayout>
+ <p className="capitalize text-3xl font-thin inline">
+ {t("worker")}
+ </p>
+
+ <div className="divider my-3"></div>
+
+ <div className="w-full flex flex-col gap-6 justify-between">
+ <div className="flex flex-col sm:flex-row sm:items-center gap-3">
+ <span>{t("regenerate_broken_preservation")}</span>
+ <button
+ className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}
+ >
+ {t("confirm")}
+ </button>
+ </div>
+ <div className="flex flex-col sm:flex-row sm:items-center gap-3">
+ <span>{t("delete_all_preservation")}</span>
+ <button
+ className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}
+ >
+ {t("confirm")}
+ </button>
+ </div>
+ </div>
+
+ </SettingsLayout>
+ );
+}
+
+export { getServerSideProps };
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 7bdad995..a3612610 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -466,5 +466,8 @@
"add_a_title_placeholder": "Add a title...",
"write_notes_here_placeholder": "Write some notes here...",
"tag_settings": "Tag archival and processing settings:",
- "ai_tagging": "AI Tagging"
+ "ai_tagging": "AI Tagging",
+ "worker": "Worker",
+ "regenerate_broken_preservation": "Delete preservation for broken webpages.",
+ "delete_all_preservation": "Delete preservation for all webpages."
}
\ No newline at end of file