fix: dont crash if default cover is invalid

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 9f3efd79db
commit 41fb5cca81

@ -15,19 +15,24 @@ coverPhoto.getDefaultProfileCover = function (uid) {
};
function getCover(type, id) {
const defaultCover = nconf.get('relative_path') + '/assets/images/cover-default.png';
if (meta.config[type + ':defaultCovers']) {
var covers = meta.config[type + ':defaultCovers'].trim().split(/[\s,]+/g);
var covers = String(meta.config[type + ':defaultCovers']).trim().split(/[\s,]+/g);
let coverPhoto = defaultCover;
if (!covers.length) {
return coverPhoto;
}
if (typeof id === 'string') {
id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
} else {
id %= covers.length;
}
if (!covers[id].startsWith('http')) {
covers = nconf.get('relative_path') + covers[id];
if (covers[id] && !covers[id].startsWith('http')) {
coverPhoto = nconf.get('relative_path') + covers[id];
}
return covers;
return coverPhoto;
}
return nconf.get('relative_path') + '/assets/images/cover-default.png';
return defaultCover;
}

Loading…
Cancel
Save