Skip to content

Commit

Permalink
MBS-10108: Allow linking tweets to recordings only
Browse files Browse the repository at this point in the history
Handle Twitter update permalinks https://twitter.com/user/status/123

* auto-select “stream music for free” relationship type,
* same cleanup as for linking to Twitter accounts,
* validate linking Twitter updates to recordings only,

See https://blog.twitter.com/en_us/a/2006/twitter-has-permalinks-and-rss-feeds.html
  • Loading branch information
yvanzo committed May 23, 2019
1 parent 0547ac0 commit e8cd7b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions root/static/scripts/edit/URLCleanup.js
Expand Up @@ -2092,18 +2092,32 @@ const CLEANUPS = {
},
'twitter': {
match: [new RegExp('^(https?://)?([^/]+\\.)?twitter\\.com/', 'i')],
type: LINK_TYPES.socialnetwork,
type: _.defaults(
LINK_TYPES.socialnetwork,
LINK_TYPES.streamingmusic,
),
clean: function (url) {
url = url.replace(
/^(?:https?:\/\/)?(?:(?:www|mobile)\.)?twitter\.com(?:\/#!)?\//,
'https://twitter.com/'
);
url = url.replace(
/^(https:\/\/twitter\.com)\/@?([^\/?#]+)(?:[\/?#].*)?$/,
/^(https:\/\/twitter\.com)\/@?([^\/?#]+(?:\/status\/\d+)?)(?:[\/?#].*)?$/,
'$1/$2'
);
return url;
},
validate: function (url, id) {
const m = /^https:\/\/twitter\.com\/[^\/?#]+(\/status\/\d+)?$/.exec(url);
if (m) {
const isATweet = !!m[1];
if (_.includes(LINK_TYPES.streamingmusic, id)) {
return isATweet && (id === LINK_TYPES.streamingmusic.recording);
}
return !isATweet;
}
return false;
},
},
'unwelcomeimages': { // Block images from sites that don't allow deeplinking
match: [
Expand Down
7 changes: 7 additions & 0 deletions root/static/scripts/tests/Control/URLCleanup.js
Expand Up @@ -3032,6 +3032,13 @@ const testData = [
expected_relationship_type: 'socialnetwork',
expected_clean_url: 'https://twitter.com/UNIVERSAL_D',
},
{
input_url: 'https://twitter.com/mountain_goats/status/1062342708470132738',
input_entity_type: 'recording',
expected_relationship_type: 'streamingmusic',
expected_clean_url: 'https://twitter.com/mountain_goats/status/1062342708470132738',
only_valid_entity_types: ['recording'],
},
// Universal Music
{
input_url: 'http://www.universal-music.co.jp/sweety/products/umca-59007/',
Expand Down

0 comments on commit e8cd7b0

Please sign in to comment.