2017-02-18 01:56:23 -07:00
|
|
|
'use strict';
|
2015-10-29 14:55:04 -04:00
|
|
|
|
|
|
|
|
var coverPhoto = {};
|
|
|
|
|
var meta = require('./meta');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
coverPhoto.getDefaultGroupCover = function (groupName) {
|
2015-10-29 14:55:04 -04:00
|
|
|
return getCover('groups', groupName);
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
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']) {
|
2017-01-26 18:04:51 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2017-01-14 22:36:10 -07:00
|
|
|
return nconf.get('relative_path') + '/assets/images/cover-default.png';
|
2015-10-29 14:55:04 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-26 18:04:51 -05:00
|
|
|
module.exports = coverPhoto;
|