Remove tracking from twitter URLs

This commit is contained in:
ekzyis 2022-11-16 00:51:00 +01:00
parent a1690ed511
commit 3a36a211af
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,5 @@
import { UserInputError, AuthenticationError } from 'apollo-server-micro'
import { ensureProtocol } from '../../lib/url'
import { ensureProtocol, removeTracking } from '../../lib/url'
import serialize from './serial'
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
@ -518,6 +518,7 @@ export default {
upsertLink: async (parent, args, { me, models }) => {
const { id, ...data } = args
data.url = ensureProtocol(data.url)
data.url = removeTracking(data.url)
if (id) {
return await updateItem(parent, { id, data }, { me, models })

View File

@ -4,3 +4,14 @@ export function ensureProtocol (value) {
}
return value
}
export function removeTracking (value) {
const exprs = [
// twitter URLs
/^(?<url>https?:\/\/twitter\.com\/(?:#!\/)?(?<user>\w+)\/status(?:es)?\/(?<id>\d+))/,
]
for (const expr of exprs) {
value = expr.exec(value)?.groups.url ?? value;
}
return value
}