Skip to content

Commit b10f6f3

Browse files
committed
MBS-13922: Add URL cleanup and validation for Naver Vibe
1 parent 9dd0c4e commit b10f6f3

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

root/static/scripts/edit/URLCleanup.js

+92
Original file line numberDiff line numberDiff line change
@@ -6156,6 +6156,98 @@ const CLEANUPS: CleanupEntries = {
61566156
};
61576157
},
61586158
},
6159+
'vibe': {
6160+
match: [
6161+
/^(https?:\/\/)?vibe\.naver\.com\//i,
6162+
/^(https?:\/\/)?music\.naver\.com\//i, // legacy URL
6163+
],
6164+
restrict: [
6165+
multiple(LINK_TYPES.downloadpurchase, LINK_TYPES.streamingpaid),
6166+
LINK_TYPES.streamingpaid,
6167+
],
6168+
select(url, sourceType) {
6169+
const m = /^https:\/\/vibe\.naver\.com\/(album|artist|track|video)/.exec(url);
6170+
if (m) {
6171+
const prefix = m[1];
6172+
switch (prefix) {
6173+
case 'album':
6174+
if (sourceType === 'release') {
6175+
return [
6176+
LINK_TYPES.downloadpurchase.release,
6177+
LINK_TYPES.streamingpaid.release,
6178+
];
6179+
}
6180+
break;
6181+
case 'artist':
6182+
if (sourceType === 'artist') {
6183+
return [
6184+
LINK_TYPES.downloadpurchase.artist,
6185+
LINK_TYPES.streamingpaid.artist,
6186+
];
6187+
}
6188+
break;
6189+
case 'track':
6190+
if (sourceType === 'recording') {
6191+
return [
6192+
LINK_TYPES.downloadpurchase.recording,
6193+
LINK_TYPES.streamingpaid.recording,
6194+
];
6195+
}
6196+
break;
6197+
default: // video
6198+
if (sourceType === 'release') {
6199+
return LINK_TYPES.streamingpaid.release;
6200+
} else if (sourceType === 'recording') {
6201+
return LINK_TYPES.streamingpaid.recording;
6202+
}
6203+
break;
6204+
}
6205+
}
6206+
return false;
6207+
},
6208+
clean(url) {
6209+
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/album\/index\.nhn\?albumId=(\d+)(?:&.+)/, 'https://vibe.naver.com/album/$1');
6210+
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/artist\/(?:\w+)\.nhn\?artistId=(\d+)(?:&.+)/, 'https://vibe.naver.com/artist/$1');
6211+
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/video\/(?:\w+)\.nhn\?videoId=(\d+)(?:&.+)/, 'https://vibe.naver.com/video/$1');
6212+
url = url.replace(/^(?:https?:\/\/)?vibe\.naver\.com\/(album|artist|track|video)\/(\d+)(?:\/\w+)/, 'https://vibe.naver.com/$1/$2');
6213+
return url;
6214+
},
6215+
validate(url, id) {
6216+
if (/https:\/\/vibe\.naver\.com\/search/.test(url)) {
6217+
return {
6218+
error: noLinkToSearchMsg(),
6219+
result: false,
6220+
target: ERROR_TARGETS.URL,
6221+
};
6222+
}
6223+
const m = /^https?:\/\/vibe\.naver\.com\/(album|artist|track|video)\/(\d+)/.exec(url);
6224+
if (m) {
6225+
const prefix = m[1];
6226+
switch (id) {
6227+
case LINK_TYPES.downloadpurchase.release:
6228+
case LINK_TYPES.streamingpaid.release:
6229+
return {
6230+
result: prefix === 'album' || prefix === 'video',
6231+
target: ERROR_TARGETS.ENTITY,
6232+
};
6233+
case LINK_TYPES.downloadpurchase.artist:
6234+
case LINK_TYPES.streamingpaid.artist:
6235+
return {
6236+
result: prefix === 'artist',
6237+
target: ERROR_TARGETS.ENTITY,
6238+
};
6239+
case LINK_TYPES.downloadpurchase.recording:
6240+
case LINK_TYPES.streamingpaid.recording:
6241+
return {
6242+
result: prefix === 'track' || prefix === 'video',
6243+
target: ERROR_TARGETS.ENTITY,
6244+
};
6245+
}
6246+
return {result: false, target: ERROR_TARGETS.RELATIONSHIP};
6247+
}
6248+
return {result: false, target: ERROR_TARGETS.URL};
6249+
},
6250+
},
61596251
'vimeo': {
61606252
match: [/^(https?:\/\/)?([^/]+\.)?vimeo\.com\/(?!(?:ondemand|store\/ondemand))/i],
61616253
restrict: [{...LINK_TYPES.streamingfree, ...LINK_TYPES.videochannel}],

root/static/scripts/tests/Control/URLCleanup.js

+60
Original file line numberDiff line numberDiff line change
@@ -6451,6 +6451,66 @@ limited_link_type_combinations: ['downloadpurchase', 'mailorder'],
64516451
input_url: 'www.viaf.org/viaf/16766997/',
64526452
expected_clean_url: 'http://viaf.org/viaf/16766997',
64536453
},
6454+
// Naver Vibe
6455+
{
6456+
input_url: 'https://vibe.naver.com/album/32004180',
6457+
input_entity_type: 'release',
6458+
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
6459+
limited_link_type_combinations: [
6460+
['downloadpurchase', 'streamingpaid'],
6461+
'streamingpaid',
6462+
],
6463+
expected_clean_url: 'https://vibe.naver.com/album/32004180',
6464+
},
6465+
{
6466+
input_url: 'https://vibe.naver.com/artist/5176052',
6467+
input_entity_type: 'artist',
6468+
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
6469+
limited_link_type_combinations: [
6470+
['downloadpurchase', 'streamingpaid'],
6471+
'streamingpaid',
6472+
],
6473+
expected_clean_url: 'https://vibe.naver.com/artist/5176052',
6474+
},
6475+
{
6476+
input_url: 'https://vibe.naver.com/artist/5176052/albums',
6477+
input_entity_type: 'artist',
6478+
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
6479+
limited_link_type_combinations: [
6480+
['downloadpurchase', 'streamingpaid'],
6481+
'streamingpaid',
6482+
],
6483+
expected_clean_url: 'https://vibe.naver.com/artist/5176052',
6484+
},
6485+
{
6486+
input_url: 'https://vibe.naver.com/video/406927',
6487+
input_entity_type: 'release',
6488+
expected_relationship_type: 'streamingpaid',
6489+
expected_clean_url: 'https://vibe.naver.com/video/406927',
6490+
only_valid_entity_types: ['release', 'recording'],
6491+
},
6492+
{
6493+
input_url: 'https://vibe.naver.com/search?query=NMIXX',
6494+
input_entity_type: 'artist',
6495+
input_relationship_type: 'streamingpaid',
6496+
expected_relationship_type: undefined,
6497+
expected_clean_url: 'https://vibe.naver.com/search?query=NMIXX',
6498+
expected_error: {
6499+
error: 'a link to a search result',
6500+
target: 'url',
6501+
},
6502+
only_valid_entity_types: [],
6503+
},
6504+
{
6505+
input_url: 'http://music.naver.com/album/index.nhn?albumId=307278',
6506+
input_entity_type: 'release',
6507+
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
6508+
limited_link_type_combinations: [
6509+
['downloadpurchase', 'streamingpaid'],
6510+
'streamingpaid',
6511+
],
6512+
expected_clean_url: 'https://vibe.naver.com/album/307278',
6513+
},
64546514
// Videogam.in
64556515
{
64566516
input_url: 'http://videogam.in/music/?id=PCCG-00486',

0 commit comments

Comments
 (0)