Fix: Treat subdomains as distinct in dupe URL detection (#2068)

* commented the lines to make sure dupes are also checked on subdomains

* chore: fix lint issues

* fix the underlying issue instead

---------

Co-authored-by: 김현희 <pygmal@gimhyeonhuiui-MacBookAir.local>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
nl 2025-04-08 08:03:20 +09:00 committed by GitHub
parent f635514c32
commit 4e631f0373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,7 +15,6 @@ import {
FULL_COMMENTS_THRESHOLD FULL_COMMENTS_THRESHOLD
} from '@/lib/constants' } from '@/lib/constants'
import { msatsToSats } from '@/lib/format' import { msatsToSats } from '@/lib/format'
import { parse } from 'tldts'
import uu from 'url-unshort' import uu from 'url-unshort'
import { actSchema, advSchema, bountySchema, commentSchema, discussionSchema, jobSchema, linkSchema, pollSchema, validateSchema } from '@/lib/validate' import { actSchema, advSchema, bountySchema, commentSchema, discussionSchema, jobSchema, linkSchema, pollSchema, validateSchema } from '@/lib/validate'
import { defaultCommentSort, isJob, deleteItemByAuthor } from '@/lib/item' import { defaultCommentSort, isJob, deleteItemByAuthor } from '@/lib/item'
@ -26,6 +25,7 @@ import assertApiKeyNotPermitted from './apiKey'
import performPaidAction from '../paidAction' import performPaidAction from '../paidAction'
import { GqlAuthenticationError, GqlInputError } from '@/lib/error' import { GqlAuthenticationError, GqlInputError } from '@/lib/error'
import { verifyHmac } from './wallet' import { verifyHmac } from './wallet'
import { parse } from 'tldts'
function commentsOrderByClause (me, models, sort) { function commentsOrderByClause (me, models, sort) {
const sharedSortsArray = [] const sharedSortsArray = []
@ -613,7 +613,6 @@ export default {
const urlObj = new URL(ensureProtocol(url)) const urlObj = new URL(ensureProtocol(url))
let { hostname, pathname } = urlObj let { hostname, pathname } = urlObj
// remove subdomain from hostname
const parseResult = parse(urlObj.hostname) const parseResult = parse(urlObj.hostname)
if (parseResult?.subdomain?.length > 0) { if (parseResult?.subdomain?.length > 0) {
hostname = hostname.replace(`${parseResult.subdomain}.`, '') hostname = hostname.replace(`${parseResult.subdomain}.`, '')
@ -639,6 +638,9 @@ export default {
} else if (urlObj.hostname === 'yewtu.be') { } else if (urlObj.hostname === 'yewtu.be') {
const matches = url.match(/(https?:\/\/)?yewtu\.be.*(v=|embed\/)(?<id>[_0-9a-z-]+)/i) const matches = url.match(/(https?:\/\/)?yewtu\.be.*(v=|embed\/)(?<id>[_0-9a-z-]+)/i)
similar = `^(http(s)?:\\/\\/)?yewtu\\.be\\/(watch\\?v\\=|embed\\/)${matches?.groups?.id}&?` similar = `^(http(s)?:\\/\\/)?yewtu\\.be\\/(watch\\?v\\=|embed\\/)${matches?.groups?.id}&?`
} else {
// only allow ending of mismatching search params
similar += '(?:\\?.*)?$'
} }
return await itemQueryWithMeta({ return await itemQueryWithMeta({