[Enhancement] Accounting for "www." prefix for duplicates
This commit is contained in:
parent
9fce74971f
commit
cac90524ed
|
@ -116,9 +116,18 @@ export default async function postLink(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user?.preventDuplicateLinks) {
|
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({
|
const existingLink = await prisma.link.findFirst({
|
||||||
where: {
|
where: {
|
||||||
url: link.url?.trim(),
|
OR: [
|
||||||
|
{ url: trimmedUrl },
|
||||||
|
{ url: hasWwwPrefix ? urlWithoutWww : urlWithWww }, // Toggling "www."
|
||||||
|
],
|
||||||
collection: {
|
collection: {
|
||||||
ownerId: userId,
|
ownerId: userId,
|
||||||
},
|
},
|
||||||
|
|
Ŝarĝante…
Reference in New Issue