Merge pull request #507 from GoodM4ven/missing-duplicate-checks
[Enhancement] Accounting for "www." prefix for duplicates
This commit is contained in:
commit
a89274fc03
|
@ -119,15 +119,24 @@ export default async function postLink(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user?.preventDuplicateLinks) {
|
if (user?.preventDuplicateLinks) {
|
||||||
|
const url = link.url?.trim().replace(/\/+$/, ""); // trim and remove trailing slashes from the URL
|
||||||
|
const hasWwwPrefix = url?.includes(`://www.`);
|
||||||
|
const urlWithoutWww = hasWwwPrefix ? url?.replace(`://www.`, "://") : url;
|
||||||
|
const urlWithWww = hasWwwPrefix ? url : url?.replace("://", `://www.`);
|
||||||
|
|
||||||
|
console.log(url, urlWithoutWww, urlWithWww);
|
||||||
|
|
||||||
const existingLink = await prisma.link.findFirst({
|
const existingLink = await prisma.link.findFirst({
|
||||||
where: {
|
where: {
|
||||||
url: link.url?.trim(),
|
OR: [{ url: urlWithWww }, { url: urlWithoutWww }],
|
||||||
collection: {
|
collection: {
|
||||||
ownerId: userId,
|
ownerId: userId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(url, urlWithoutWww, urlWithWww, "DONE!");
|
||||||
|
|
||||||
if (existingLink)
|
if (existingLink)
|
||||||
return {
|
return {
|
||||||
response: "Link already exists",
|
response: "Link already exists",
|
||||||
|
@ -174,7 +183,7 @@ export default async function postLink(
|
||||||
|
|
||||||
const newLink = await prisma.link.create({
|
const newLink = await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
url: link.url?.trim() || null,
|
url: link.url?.trim().replace(/\/+$/, "") || null,
|
||||||
name: link.name,
|
name: link.name,
|
||||||
description,
|
description,
|
||||||
type: linkType,
|
type: linkType,
|
||||||
|
|
Ŝarĝante…
Reference in New Issue