From 4e631f03739dbd5876297dacf64bdfae83d2ca36 Mon Sep 17 00:00:00 2001 From: nl Date: Tue, 8 Apr 2025 08:03:20 +0900 Subject: [PATCH] Fix: Treat subdomains as distinct in dupe URL detection (#2068) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * commented the lines to make sure dupes are also checked on subdomains * chore: fix lint issues * fix the underlying issue instead --------- Co-authored-by: 김현희 Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b --- api/resolvers/item.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 5f65a9e8..781cd776 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -15,7 +15,6 @@ import { FULL_COMMENTS_THRESHOLD } from '@/lib/constants' import { msatsToSats } from '@/lib/format' -import { parse } from 'tldts' import uu from 'url-unshort' import { actSchema, advSchema, bountySchema, commentSchema, discussionSchema, jobSchema, linkSchema, pollSchema, validateSchema } from '@/lib/validate' import { defaultCommentSort, isJob, deleteItemByAuthor } from '@/lib/item' @@ -26,6 +25,7 @@ import assertApiKeyNotPermitted from './apiKey' import performPaidAction from '../paidAction' import { GqlAuthenticationError, GqlInputError } from '@/lib/error' import { verifyHmac } from './wallet' +import { parse } from 'tldts' function commentsOrderByClause (me, models, sort) { const sharedSortsArray = [] @@ -613,7 +613,6 @@ export default { const urlObj = new URL(ensureProtocol(url)) let { hostname, pathname } = urlObj - // remove subdomain from hostname const parseResult = parse(urlObj.hostname) if (parseResult?.subdomain?.length > 0) { hostname = hostname.replace(`${parseResult.subdomain}.`, '') @@ -639,6 +638,9 @@ export default { } else if (urlObj.hostname === 'yewtu.be') { const matches = url.match(/(https?:\/\/)?yewtu\.be.*(v=|embed\/)(?[_0-9a-z-]+)/i) similar = `^(http(s)?:\\/\\/)?yewtu\\.be\\/(watch\\?v\\=|embed\\/)${matches?.groups?.id}&?` + } else { + // only allow ending of mismatching search params + similar += '(?:\\?.*)?$' } return await itemQueryWithMeta({