Skip to content
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
38 changes: 37 additions & 1 deletion root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4508,7 +4508,43 @@ export const CLEANUPS: CleanupEntries = {
match: [/^(https?:\/\/)?([^/]+\.)?mora\.jp/i],
restrict: [LINK_TYPES.downloadpurchase],
clean(url) {
return url.replace(/^(?:https?:\/\/)?(?:[^.]+\.)?mora\.jp\/package\/([0-9]+)\/([a-zA-Z0-9_-]+)(\/)?.*$/, 'https://mora.jp/package/$1/$2/');
const artistPattern = /^(?:https?:\/\/)?(?:[^.]+\.)?mora\.jp\/artist\/(\d+)(?:\/)?.*$/;
const trackPattern = /^(?:https?:\/\/)?(?:[^.]+\.)?mora\.jp\/package\/([0-9]+)\/([a-zA-Z0-9_-]+)(?:\/)?\?trackMaterialNo=(\d+).*$/;
const packagePattern = /^(?:https?:\/\/)?(?:[^.]+\.)?mora\.jp\/package\/([0-9]+)\/([a-zA-Z0-9_-]+)(?:\/)?.*$/;
if (artistPattern.test(url)) {
return url.replace(artistPattern, 'https://mora.jp/artist/$1/');
}
if (trackPattern.test(url)) {
return url.replace(trackPattern, 'https://mora.jp/package/$1/$2/?trackMaterialNo=$3');
}
if (packagePattern.test(url)) {
return url.replace(packagePattern, 'https://mora.jp/package/$1/$2/');
}
/**
* Mora links use various query parameters for identifying resources,
* for simplicity sake only known and accepted link types are cleaned.
*/
return url;
},
validate(url, id) {
switch (id) {
case LINK_TYPES.downloadpurchase.artist:
return {
result: /^https:\/\/mora\.jp\/artist\/(\d+)\/$/.test(url),
target: ERROR_TARGETS.URL,
};
case LINK_TYPES.downloadpurchase.recording:
return {
result: /^https:\/\/mora\.jp\/package\/([0-9]+)\/([a-zA-Z0-9_-]+)\/\?trackMaterialNo=(\d+)$/.test(url),
target: ERROR_TARGETS.URL,
};
case LINK_TYPES.downloadpurchase.release:
return {
result: /^https:\/\/mora\.jp\/package\/([0-9]+)\/([a-zA-Z0-9_-]+)\/$/.test(url),
target: ERROR_TARGETS.URL,
};
}
return {result: false, target: ERROR_TARGETS.ENTITY};
},
},
'musicapopularcl': {
Expand Down
34 changes: 34 additions & 0 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4399,27 +4399,61 @@ limited_link_type_combinations: [
only_valid_entity_types: ['artist', 'series'],
},
// mora
{
input_url: 'https://mora.jp/artist/2024469/#',
input_entity_type: 'artist',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/artist/2024469/',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://mora.jp/artist/2024469?test',
input_entity_type: 'artist',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/artist/2024469/',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://mora.jp/package/43000011/4580789738098_HD?trackMaterialNo=42101983&test#test',
input_entity_type: 'recording',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000011/4580789738098_HD/?trackMaterialNo=42101983',
only_valid_entity_types: ['recording'],
},
{
input_url: 'https://mora.jp/package/43000001/4534530058010/',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000001/4534530058010/',
only_valid_entity_types: ['release'],
},
{
input_url: 'https://mora.jp/package/43000014/KIZC-211/',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000014/KIZC-211/',
only_valid_entity_types: ['release'],
},
{
input_url: 'http://mora.jp/package/43000021/SQEX-20016_F/#',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000021/SQEX-20016_F/',
only_valid_entity_types: ['release'],
},
{
input_url: 'https://www.mora.jp/package/43000002/ANTCD-3106?test',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000002/ANTCD-3106/',
only_valid_entity_types: ['release'],
},
{
input_url: 'mora.jp/package/43000002/ANTCD-3106/',
input_entity_type: 'release',
expected_relationship_type: 'downloadpurchase',
expected_clean_url: 'https://mora.jp/package/43000002/ANTCD-3106/',
only_valid_entity_types: ['release'],
},
// Musa24
{
Expand Down