2017-02-18 01:56:23 -07:00
|
|
|
'use strict';
|
2015-10-29 14:55:04 -04:00
|
|
|
|
2017-05-10 21:46:11 -04:00
|
|
|
|
2015-10-29 14:55:04 -04:00
|
|
|
var nconf = require('nconf');
|
2018-11-07 15:53:14 -05:00
|
|
|
var meta = require('./meta');
|
2015-10-29 14:55:04 -04:00
|
|
|
|
2017-05-10 21:46:11 -04:00
|
|
|
var coverPhoto = module.exports;
|
2015-10-29 14:55:04 -04:00
|
|
|
|
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) {
|
2018-12-22 06:18:45 -05:00
|
|
|
const defaultCover = nconf.get('relative_path') + '/assets/images/cover-default.png';
|
2017-02-18 01:27:46 -07:00
|
|
|
if (meta.config[type + ':defaultCovers']) {
|
2018-12-22 06:18:45 -05:00
|
|
|
var covers = String(meta.config[type + ':defaultCovers']).trim().split(/[\s,]+/g);
|
|
|
|
|
let coverPhoto = defaultCover;
|
|
|
|
|
if (!covers.length) {
|
|
|
|
|
return coverPhoto;
|
|
|
|
|
}
|
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 {
|
2017-02-18 14:20:58 -07:00
|
|
|
id %= covers.length;
|
2015-10-29 15:11:52 -04:00
|
|
|
}
|
2019-05-16 10:49:40 -04:00
|
|
|
if (covers[id]) {
|
|
|
|
|
coverPhoto = covers[id].startsWith('http') ? covers[id] : (nconf.get('relative_path') + covers[id]);
|
2018-12-18 19:43:28 -05:00
|
|
|
}
|
2018-12-22 06:18:45 -05:00
|
|
|
return coverPhoto;
|
2015-10-29 14:55:04 -04:00
|
|
|
}
|
|
|
|
|
|
2018-12-22 06:18:45 -05:00
|
|
|
return defaultCover;
|
2015-10-29 14:55:04 -04:00
|
|
|
}
|