mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
fix: dont crash if default cover is invalid
This commit is contained in:
@@ -15,19 +15,24 @@ coverPhoto.getDefaultProfileCover = function (uid) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function getCover(type, id) {
|
function getCover(type, id) {
|
||||||
|
const defaultCover = nconf.get('relative_path') + '/assets/images/cover-default.png';
|
||||||
if (meta.config[type + ':defaultCovers']) {
|
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') {
|
if (typeof id === 'string') {
|
||||||
id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
|
id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
|
||||||
} else {
|
} else {
|
||||||
id %= covers.length;
|
id %= covers.length;
|
||||||
}
|
}
|
||||||
if (!covers[id].startsWith('http')) {
|
if (covers[id] && !covers[id].startsWith('http')) {
|
||||||
covers = nconf.get('relative_path') + covers[id];
|
coverPhoto = nconf.get('relative_path') + covers[id];
|
||||||
}
|
}
|
||||||
return covers;
|
return coverPhoto;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nconf.get('relative_path') + '/assets/images/cover-default.png';
|
return defaultCover;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user