Skip to content

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

urls are now editable

daniel31x138bb6e32bfa2a
diff --git a/components/LinkDetails.tsx b/components/LinkDetails.tsx
index 4681d743..d83d711b 100644
--- a/components/LinkDetails.tsx
+++ b/components/LinkDetails.tsx
@@ -327,7 +327,25 @@ export default function LinkDetails({
</div>
)}
- {link.url && (
+ {mode === "edit" && (
+ <>
+ <br />
+
+ <div>
+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">
+ {t("name")}
+ </p>
+ <TextInput
+ value={link.name}
+ onChange={(e) => setLink({ ...link, name: e.target.value })}
+ placeholder={t("placeholder_example_link")}
+ className="bg-base-200"
+ />
+ </div>
+ </>
+ )}
+
+ {link.url && mode === "view" ? (
<>
<br />
@@ -335,12 +353,7 @@ export default function LinkDetails({
<div className="relative">
<div className="rounded-md p-2 bg-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14">
- <Link
- href={link.url}
- title={link.url}
- target="_blank"
- className={clsx(mode === "edit" && "pointer-events-none")}
- >
+ <Link href={link.url} title={link.url} target="_blank">
{link.url}
</Link>
<div className="absolute right-0 px-2 bg-base-200">
@@ -349,25 +362,23 @@ export default function LinkDetails({
</div>
</div>
</>
- )}
-
- {mode === "edit" && (
+ ) : activeLink.url ? (
<>
<br />
<div>
<p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">
- {t("name")}
+ {t("link")}
</p>
<TextInput
- value={link.name}
- onChange={(e) => setLink({ ...link, name: e.target.value })}
+ value={link.url || ""}
+ onChange={(e) => setLink({ ...link, url: e.target.value })}
placeholder={t("placeholder_example_link")}
className="bg-base-200"
/>
</div>
</>
- )}
+ ) : undefined}
<br />
diff --git a/lib/api/controllers/links/linkId/updateLinkById.ts b/lib/api/controllers/links/linkId/updateLinkById.ts
index 9c793166..587c2b27 100644
--- a/lib/api/controllers/links/linkId/updateLinkById.ts
+++ b/lib/api/controllers/links/linkId/updateLinkById.ts
@@ -2,7 +2,8 @@ import { prisma } from "@/lib/api/db";
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
import { UsersAndCollections } from "@prisma/client";
import getPermission from "@/lib/api/getPermission";
-import { moveFiles } from "@/lib/api/manageLinkFiles";
+import { moveFiles, removeFiles } from "@/lib/api/manageLinkFiles";
+import isValidUrl from "@/lib/shared/isValidUrl";
export default async function updateLinkById(
userId: number,
@@ -89,16 +90,32 @@ export default async function updateLinkById(
status: 401,
};
else {
+ const oldLink = await prisma.link.findUnique({
+ where: {
+ id: linkId,
+ },
+ });
+
+ if (oldLink && oldLink?.url !== data.url) {
+ await removeFiles(oldLink.id, oldLink.collectionId);
+ }
+
const updatedLink = await prisma.link.update({
where: {
id: linkId,
},
data: {
name: data.name,
+ url: data.url,
description: data.description,
icon: data.icon,
iconWeight: data.iconWeight,
color: data.color,
+ image: oldLink?.url !== data.url ? null : undefined,
+ pdf: oldLink?.url !== data.url ? null : undefined,
+ readable: oldLink?.url !== data.url ? null : undefined,
+ monolith: oldLink?.url !== data.url ? null : undefined,
+ preview: oldLink?.url !== data.url ? null : undefined,
collection: {
connect: {
id: data.collection.id,
diff --git a/pages/api/v1/links/[id]/archive/index.ts b/pages/api/v1/links/[id]/archive/index.ts
index 6cacf73b..72583ae8 100644
--- a/pages/api/v1/links/[id]/archive/index.ts
+++ b/pages/api/v1/links/[id]/archive/index.ts
@@ -54,7 +54,20 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: "Invalid URL.",
});
- await deleteArchivedFiles(link);
+ await prisma.link.update({
+ where: {
+ id: link.id,
+ },
+ data: {
+ image: null,
+ pdf: null,
+ readable: null,
+ monolith: null,
+ preview: null,
+ },
+ });
+
+ await removeFiles(link.id, link.collection.id);
return res.status(200).json({
response: "Link is being archived.",
@@ -72,20 +85,3 @@ const getTimezoneDifferenceInMinutes = (future: Date, past: Date) => {
return diffInMinutes;
};
-
-const deleteArchivedFiles = async (link: Link & { collection: Collection }) => {
- await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
- image: null,
- pdf: null,
- readable: null,
- monolith: null,
- preview: null,
- },
- });
-
- await removeFiles(link.id, link.collection.id);
-};