You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
966 B
JavaScript
39 lines
966 B
JavaScript
'use strict';
|
|
|
|
|
|
const nconf = require('nconf');
|
|
const meta = require('./meta');
|
|
|
|
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 = nconf.get('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] : (nconf.get('relative_path') + covers[id]);
|
|
}
|
|
return coverPhoto;
|
|
}
|
|
|
|
return defaultCover;
|
|
}
|