Remove tracking from twitter URLs
This commit is contained in:
parent
a1690ed511
commit
3a36a211af
@ -1,5 +1,5 @@
|
|||||||
import { UserInputError, AuthenticationError } from 'apollo-server-micro'
|
import { UserInputError, AuthenticationError } from 'apollo-server-micro'
|
||||||
import { ensureProtocol } from '../../lib/url'
|
import { ensureProtocol, removeTracking } from '../../lib/url'
|
||||||
import serialize from './serial'
|
import serialize from './serial'
|
||||||
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
||||||
import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
|
import { getMetadata, metadataRuleSets } from 'page-metadata-parser'
|
||||||
@ -518,6 +518,7 @@ export default {
|
|||||||
upsertLink: async (parent, args, { me, models }) => {
|
upsertLink: async (parent, args, { me, models }) => {
|
||||||
const { id, ...data } = args
|
const { id, ...data } = args
|
||||||
data.url = ensureProtocol(data.url)
|
data.url = ensureProtocol(data.url)
|
||||||
|
data.url = removeTracking(data.url)
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
return await updateItem(parent, { id, data }, { me, models })
|
return await updateItem(parent, { id, data }, { me, models })
|
||||||
|
11
lib/url.js
11
lib/url.js
@ -4,3 +4,14 @@ export function ensureProtocol (value) {
|
|||||||
}
|
}
|
||||||
return 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user