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 { 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 })
|
||||
|
|
11
lib/url.js
11
lib/url.js
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue