Files
NodeBB/src/coverPhoto.js

39 lines
966 B
JavaScript
Raw Normal View History

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
2019-09-23 22:30:17 -04:00
const nconf = require('nconf');
const meta = require('./meta');
2015-10-29 14:55:04 -04:00
2019-09-23 22:30:17 -04:00
const coverPhoto = module.exports;
2015-10-29 14:55:04 -04:00
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) {
const defaultCover = nconf.get('relative_path') + '/assets/images/cover-default.png';
2017-02-18 01:27:46 -07:00
if (meta.config[type + ':defaultCovers']) {
2019-09-23 22:30:17 -04:00
const 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 {
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]);
}
return coverPhoto;
2015-10-29 14:55:04 -04:00
}
return defaultCover;
2015-10-29 14:55:04 -04:00
}