Files
NodeBB/src/coverPhoto.js

33 lines
725 B
JavaScript
Raw Normal View History

2015-10-29 14:55:04 -04:00
"use strict";
var coverPhoto = {};
var meta = require('./meta');
var nconf = require('nconf');
coverPhoto.getDefaultGroupCover = function (groupName) {
2015-10-29 14:55:04 -04:00
return getCover('groups', groupName);
};
coverPhoto.getDefaultProfileCover = function (uid) {
2015-10-29 15:11:52 -04:00
return getCover('profile', parseInt(uid, 10));
};
2015-10-29 14:55:04 -04:00
function getCover(type, id) {
2017-02-18 01:27:46 -07:00
if (meta.config[type + ':defaultCovers']) {
var covers = meta.config[type + ':defaultCovers'].trim().split(/[\s,]+/g);
2017-02-18 01:27:46 -07:00
2015-10-29 15:11:52 -04:00
if (typeof id === 'string') {
id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
} else {
id = id % covers.length;
}
return covers[id];
2015-10-29 14:55:04 -04:00
}
return nconf.get('relative_path') + '/assets/images/cover-default.png';
2015-10-29 14:55:04 -04:00
}
module.exports = coverPhoto;