Skip to content

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

small change

daniel31x136bdf0f1c91b8
diff --git a/apps/web/components/LinkListOptions.tsx b/apps/web/components/LinkListOptions.tsx
index f498bbc5..bb48c160 100644
--- a/apps/web/components/LinkListOptions.tsx
+++ b/apps/web/components/LinkListOptions.tsx
@@ -7,12 +7,12 @@ import BulkEditLinksModal from "./ModalContent/BulkEditLinksModal";
import useCollectivePermissions from "@/hooks/useCollectivePermissions";
import { useRouter } from "next/router";
import useLinkStore from "@/store/links";
-import { Sort, ViewMode } from "@linkwarden/types";
import {
- useArchiveAction,
- useBulkDeleteLinks,
- useLinks,
-} from "@linkwarden/router/links";
+ LinkIncludingShortenedCollectionAndTags,
+ Sort,
+ ViewMode,
+} from "@linkwarden/types";
+import { useArchiveAction, useBulkDeleteLinks } from "@linkwarden/router/links";
import toast from "react-hot-toast";
type Props = {
@@ -24,6 +24,7 @@ type Props = {
setSortBy: Dispatch<SetStateAction<Sort>>;
editMode?: boolean;
setEditMode?: (mode: boolean) => void;
+ links: LinkIncludingShortenedCollectionAndTags[];
};
const LinkListOptions = ({
@@ -35,14 +36,13 @@ const LinkListOptions = ({
setSortBy,
editMode,
setEditMode,
+ links,
}: Props) => {
const { selectedLinks, setSelectedLinks } = useLinkStore();
const deleteLinksById = useBulkDeleteLinks();
const refreshPreservations = useArchiveAction();
- const { links } = useLinks();
-
const router = useRouter();
const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false);
diff --git a/apps/web/pages/api/v1/links/archive/index.ts b/apps/web/pages/api/v1/links/archive/index.ts
index f90c2712..098cdf25 100644
--- a/apps/web/pages/api/v1/links/archive/index.ts
+++ b/apps/web/pages/api/v1/links/archive/index.ts
@@ -6,54 +6,6 @@ import { removeFiles, removePreservationFiles } from "@linkwarden/filesystem";
import { ArchivalSettings } from "@linkwarden/types";
import { isArchivalTag } from "@linkwarden/lib";
-async function checkBulkLinkPermissions(userId: number, linkIds: number[]) {
- const collections = await prisma.collection.findMany({
- where: {
- OR: [
- { ownerId: userId },
- {
- members: {
- some: {
- userId: userId,
- canDelete: true,
- },
- },
- },
- ],
- links: {
- some: {
- id: { in: linkIds },
- },
- },
- },
- select: {
- id: true,
- links: {
- where: {
- id: { in: linkIds },
- },
- select: { id: true },
- },
- },
- });
-
- const linkToCollectionMap = new Map<number, number>();
- collections.forEach((collection) => {
- collection.links.forEach((link) => {
- linkToCollectionMap.set(link.id, collection.id);
- });
- });
-
- const unauthorizedLinkIds = linkIds.filter(
- (linkId) => !linkToCollectionMap.has(linkId)
- );
-
- return {
- authorized: unauthorizedLinkIds.length === 0,
- linkToCollectionMap,
- };
-}
-
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
if (!user) return;
@@ -73,25 +25,51 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
const { action, linkIds } = dataValidation.data;
if (linkIds) {
- const { authorized, linkToCollectionMap } =
- await checkBulkLinkPermissions(user.id, linkIds);
- if (!authorized) {
- return res.status(401).json({
- response: "Permission denied.",
- });
+ const authorizedLinks = await prisma.link.findMany({
+ where: {
+ id: { in: linkIds },
+ url: { not: null },
+ OR: [
+ {
+ collection: {
+ ownerId: user.id,
+ },
+ },
+ {
+ collection: {
+ members: {
+ some: {
+ userId: user.id,
+ canDelete: true,
+ },
+ },
+ },
+ },
+ ],
+ },
+ select: {
+ id: true,
+ collectionId: true,
+ },
+ });
+
+ if (authorizedLinks.length === 0) {
+ return res.status(401).json({ response: "Permission denied." });
}
- for (const linkId of linkIds) {
- const collectionId = linkToCollectionMap.get(linkId);
+ res.status(200).json({ response: "Success." });
+
+ for (const link of authorizedLinks) {
+ const collectionId = link.collectionId;
if (!collectionId) {
- console.error(`Collection ID not found for link ${linkId}`);
+ console.error(`Collection ID not found for link ${link.id}`);
continue;
}
- await removeFiles(linkId, collectionId);
+ await removeFiles(link.id, collectionId);
await prisma.link.update({
- where: { id: linkId },
+ where: { id: link.id },
data: {
image: null,
pdf: null,
@@ -103,10 +81,10 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
},
});
- console.log("Deleted preservation link:", linkId);
+ console.log("Deleted preservation link:", link.id);
}
- return res.status(200).json({ response: "Success." });
+ return;
}
if (action === "allAndIgnore") {
diff --git a/apps/web/pages/collections/[id].tsx b/apps/web/pages/collections/[id].tsx
index 05b5db98..1cba82a9 100644
--- a/apps/web/pages/collections/[id].tsx
+++ b/apps/web/pages/collections/[id].tsx
@@ -338,6 +338,7 @@ export default function Index() {
? setEditMode
: undefined
}
+ links={links}
>
{collections.some((e) => e.parentId === activeCollection?.id) ? (
<PageHeader
diff --git a/apps/web/pages/links/index.tsx b/apps/web/pages/links/index.tsx
index 366563d0..195e16dd 100644
--- a/apps/web/pages/links/index.tsx
+++ b/apps/web/pages/links/index.tsx
@@ -43,6 +43,7 @@ export default function Index() {
setSortBy={setSortBy}
editMode={editMode}
setEditMode={setEditMode}
+ links={links}
>
<PageHeader
icon={"bi-link-45deg"}
diff --git a/apps/web/pages/links/pinned.tsx b/apps/web/pages/links/pinned.tsx
index 1643648b..65f57ac6 100644
--- a/apps/web/pages/links/pinned.tsx
+++ b/apps/web/pages/links/pinned.tsx
@@ -38,6 +38,7 @@ export default function PinnedLinks() {
setSortBy={setSortBy}
editMode={editMode}
setEditMode={setEditMode}
+ links={links}
>
<PageHeader
icon={"bi-pin-angle"}
diff --git a/apps/web/pages/public/collections/[id]/index.tsx b/apps/web/pages/public/collections/[id]/index.tsx
index 2f0e8ba4..33d80d83 100644
--- a/apps/web/pages/public/collections/[id]/index.tsx
+++ b/apps/web/pages/public/collections/[id]/index.tsx
@@ -219,6 +219,7 @@ export default function PublicCollections() {
setViewMode={setViewMode}
sortBy={sortBy}
setSortBy={setSortBy}
+ links={links}
>
<SearchBar
placeholder={
diff --git a/apps/web/pages/search.tsx b/apps/web/pages/search.tsx
index 394563b6..9ac7b5f4 100644
--- a/apps/web/pages/search.tsx
+++ b/apps/web/pages/search.tsx
@@ -44,6 +44,7 @@ export default function Search() {
setSortBy={setSortBy}
editMode={editMode}
setEditMode={setEditMode}
+ links={links}
>
<PageHeader icon={"bi-search"} title={t("search_results")} />
</LinkListOptions>
diff --git a/apps/web/pages/tags/[id].tsx b/apps/web/pages/tags/[id].tsx
index b0e1aa2a..cb452db7 100644
--- a/apps/web/pages/tags/[id].tsx
+++ b/apps/web/pages/tags/[id].tsx
@@ -140,6 +140,7 @@ export default function Index() {
setSortBy={setSortBy}
editMode={editMode}
setEditMode={setEditMode}
+ links={links}
>
<div className="flex gap-3 items-center">
<div className="flex gap-2 items-center font-thin">