Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-13922: Add URL cleanup and validation for Naver Vibe #3463

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6156,6 +6156,98 @@ const CLEANUPS: CleanupEntries = {
};
},
},
'vibe': {
match: [
/^(https?:\/\/)?vibe\.naver\.com\//i,
/^(https?:\/\/)?music\.naver\.com\//i, // legacy URL
],
restrict: [
multiple(LINK_TYPES.downloadpurchase, LINK_TYPES.streamingpaid),
LINK_TYPES.streamingpaid,
],
select(url, sourceType) {
const m = /^https:\/\/vibe\.naver\.com\/(album|artist|track|video)/.exec(url);
if (m) {
const prefix = m[1];
switch (prefix) {
case 'album':
if (sourceType === 'release') {
return [
LINK_TYPES.downloadpurchase.release,
LINK_TYPES.streamingpaid.release,
];
}
break;
case 'artist':
if (sourceType === 'artist') {
return [
LINK_TYPES.downloadpurchase.artist,
LINK_TYPES.streamingpaid.artist,
];
}
break;
case 'track':
if (sourceType === 'recording') {
return [
LINK_TYPES.downloadpurchase.recording,
LINK_TYPES.streamingpaid.recording,
];
}
break;
default: // video
if (sourceType === 'release') {
return LINK_TYPES.streamingpaid.release;
} else if (sourceType === 'recording') {
return LINK_TYPES.streamingpaid.recording;
}
break;
}
}
return false;
},
clean(url) {
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/album\/index\.nhn\?albumId=(\d+).*$/, 'https://vibe.naver.com/album/$1');
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/artist\/(?:\w+)\.nhn\?artistId=(\d+).*$/, 'https://vibe.naver.com/artist/$1');
url = url.replace(/^(?:https?:\/\/)?music\.naver\.com\/video\/(?:\w+)\.nhn\?videoId=(\d+).*$/, 'https://vibe.naver.com/video/$1');
url = url.replace(/^(?:https?:\/\/)?vibe\.naver\.com\/(album|artist|track|video)\/(\d+).*$/, 'https://vibe.naver.com/$1/$2');
return url;
},
validate(url, id) {
if (/https:\/\/vibe\.naver\.com\/search/.test(url)) {
return {
error: noLinkToSearchMsg(),
result: false,
target: ERROR_TARGETS.URL,
};
}
const m = /^https?:\/\/vibe\.naver\.com\/(album|artist|track|video)\/(\d+)/.exec(url);
if (m) {
const prefix = m[1];
switch (id) {
case LINK_TYPES.downloadpurchase.release:
case LINK_TYPES.streamingpaid.release:
return {
result: prefix === 'album' || prefix === 'video',
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.downloadpurchase.artist:
case LINK_TYPES.streamingpaid.artist:
return {
result: prefix === 'artist',
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.downloadpurchase.recording:
case LINK_TYPES.streamingpaid.recording:
return {
result: prefix === 'track' || prefix === 'video',
target: ERROR_TARGETS.ENTITY,
};
}
return {result: false, target: ERROR_TARGETS.RELATIONSHIP};
}
return {result: false, target: ERROR_TARGETS.URL};
},
},
'vimeo': {
match: [/^(https?:\/\/)?([^/]+\.)?vimeo\.com\/(?!(?:ondemand|store\/ondemand))/i],
restrict: [{...LINK_TYPES.streamingfree, ...LINK_TYPES.videochannel}],
Expand Down
60 changes: 60 additions & 0 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6451,6 +6451,66 @@ limited_link_type_combinations: ['downloadpurchase', 'mailorder'],
input_url: 'www.viaf.org/viaf/16766997/',
expected_clean_url: 'http://viaf.org/viaf/16766997',
},
// Naver Vibe
{
input_url: 'https://vibe.naver.com/album/32004180',
input_entity_type: 'release',
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'streamingpaid',
],
expected_clean_url: 'https://vibe.naver.com/album/32004180',
},
{
input_url: 'https://vibe.naver.com/artist/5176052',
input_entity_type: 'artist',
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'streamingpaid',
],
expected_clean_url: 'https://vibe.naver.com/artist/5176052',
},
{
input_url: 'https://vibe.naver.com/artist/5176052/albums',
input_entity_type: 'artist',
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'streamingpaid',
],
expected_clean_url: 'https://vibe.naver.com/artist/5176052',
},
{
input_url: 'https://vibe.naver.com/video/406927',
input_entity_type: 'release',
expected_relationship_type: 'streamingpaid',
expected_clean_url: 'https://vibe.naver.com/video/406927',
only_valid_entity_types: ['release', 'recording'],
},
{
input_url: 'https://vibe.naver.com/search?query=NMIXX',
input_entity_type: 'artist',
input_relationship_type: 'streamingpaid',
expected_relationship_type: undefined,
expected_clean_url: 'https://vibe.naver.com/search?query=NMIXX',
expected_error: {
error: 'a link to a search result',
target: 'url',
},
only_valid_entity_types: [],
},
{
input_url: 'http://music.naver.com/album/index.nhn?albumId=307278',
input_entity_type: 'release',
expected_relationship_type: ['downloadpurchase', 'streamingpaid'],
limited_link_type_combinations: [
['downloadpurchase', 'streamingpaid'],
'streamingpaid',
],
expected_clean_url: 'https://vibe.naver.com/album/307278',
},
// Videogam.in
{
input_url: 'http://videogam.in/music/?id=PCCG-00486',
Expand Down