Files
NodeBB/src/coverPhoto.js
Barış Soner Uşaklı a05905f196 performance improvements (#8795)
* perf: nconf/winston/render

cache nconf.get calls
modify middleware.pageView to call next earlier
don't call winston.verbose on every hook see https://github.com/winstonjs/winston/issues/1669
translate header/footer separately and cache results for guests

* fix: copy paste fail

* refactor: style and fire hook only log in dev mode

* fix: cache key, header changes based on template

* perf: change replace

* fix: add missing await

* perf: category

* perf: lodash clone

* perf: remove escapeRegexChars
2020-10-26 10:43:18 -04:00

41 lines
991 B
JavaScript

'use strict';
const nconf = require('nconf');
const meta = require('./meta');
const relative_path = nconf.get('relative_path');
const coverPhoto = module.exports;
coverPhoto.getDefaultGroupCover = function (groupName) {
return getCover('groups', groupName);
};
coverPhoto.getDefaultProfileCover = function (uid) {
return getCover('profile', parseInt(uid, 10));
};
function getCover(type, id) {
const defaultCover = relative_path + '/assets/images/cover-default.png';
if (meta.config[type + ':defaultCovers']) {
const 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]) {
coverPhoto = covers[id].startsWith('http') ? covers[id] : (relative_path + covers[id]);
}
return coverPhoto;
}
return defaultCover;
}