Skip to content

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

[Enhancement] Accounting for "www." prefix for duplicates

GoodM4vencac90524ed39
diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.ts
index ec03d2a9..e286454c 100644
--- a/lib/api/controllers/links/postLink.ts
+++ b/lib/api/controllers/links/postLink.ts
@@ -116,9 +116,18 @@ export default async function postLink(
});
if (user?.preventDuplicateLinks) {
+ const trimmedUrl = link.url?.trim();
+ const wwwPrefix = 'www.';
+ const hasWwwPrefix = trimmedUrl?.includes(`://${wwwPrefix}`);
+ const urlWithoutWww = hasWwwPrefix ? trimmedUrl?.replace(`://${wwwPrefix}`, '://') : trimmedUrl;
+ const urlWithWww = hasWwwPrefix ? trimmedUrl : trimmedUrl?.replace('://', `://${wwwPrefix}`);
+
const existingLink = await prisma.link.findFirst({
where: {
- url: link.url?.trim(),
+ OR: [
+ { url: trimmedUrl },
+ { url: hasWwwPrefix ? urlWithoutWww : urlWithWww }, // Toggling "www."
+ ],
collection: {
ownerId: userId,
},