mblinks: fix up release-group image source links

Issue caused by a mix up of 'release-group' and 'release_group' which remains
unseen with the bandcamp importer since it doesn't use any type with '-'.
This commit is contained in:
Laurent Monin 2015-06-05 21:50:52 +02:00
parent 5dcd552f13
commit b6a7eced65

View file

@ -57,9 +57,10 @@ var MBLinks = function (cachekey, expiration) {
}
},
this.createMusicBrainzLink = function (mb_url, mb_type) {
return '<a href="' + mb_url + '" title="Link to MB ' + mb_type +
'"><img src="' + this.mb_server + '/static/images/entity/' + mb_type + '.png" /></a> ';
this.createMusicBrainzLink = function (mb_url, _type) {
var title = 'Link to MB ' + _type;
var img_url = this.mb_server + '/static/images/entity/' + _type + '.png';
return '<a href="' + mb_url + '" title="' + title + '"><img src="' + img_url + '"/></a> ';
};
// Search for ressource 'url' on MB, for relation of type 'mb_type' (artist, release, label, release-group, ...)
@ -67,12 +68,13 @@ var MBLinks = function (cachekey, expiration) {
// entry found
this.searchAndDisplayMbLink = function (url, mb_type, insert_func) {
var mblinks = this;
var _type = mb_type.replace('-', '_'); // underscored type
if (mblinks.cache[url]
&& mblinks.expirationMinutes > 0
&& new Date().getTime() < mblinks.cache[url].timestamp) {
$.each(mblinks.cache[url].urls, function (idx, mb_url) {
insert_func(mblinks.createMusicBrainzLink(mb_url, mb_type));
insert_func(mblinks.createMusicBrainzLink(mb_url, _type));
});
} else {
mblinks.ajax_requests.push($.proxy(function () {
@ -86,13 +88,12 @@ var MBLinks = function (cachekey, expiration) {
timestamp: expires,
urls: []
};
var _type = context.mb_type.replace('-', '_');
$.each(data['relations'], function (idx, relation) {
if (_type in relation) {
var mb_url = mblinks.mb_server + '/' + context.mb_type + '/' + relation[_type]['id'];
if ($.inArray(mb_url, mblinks.cache[context.url].urls) == -1) { // prevent dupes
mblinks.cache[context.url].urls.push(mb_url);
context.insert_func(mblinks.createMusicBrainzLink(mb_url, mb_type));
context.insert_func(mblinks.createMusicBrainzLink(mb_url, _type));
}
}
});