mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +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) {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user