npmtest-nodebb (v0.0.1)

Code coverage report for node-npmtest-nodebb/node_modules/nodebb/src/coverPhoto.js

Statements: 18.75% (3 / 16)      Branches: 0% (0 / 4)      Functions: 0% (0 / 3)      Lines: 18.75% (3 / 16)      Ignored: none     

All files » node-npmtest-nodebb/node_modules/nodebb/src/ » coverPhoto.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33    2 2                       1                                  
"use strict";
 
var coverPhoto = {};
var meta = require('./meta');
var nconf = require('nconf');
 
 
coverPhoto.getDefaultGroupCover = function (groupName) {
	return getCover('groups', groupName);
};
 
coverPhoto.getDefaultProfileCover = function (uid) {
	return getCover('profile', parseInt(uid, 10));
};
 
function getCover(type, id) {
	if (meta.config[type + ':defaultCovers']) {		
		var covers = meta.config[type + ':defaultCovers'].split(/\s*?,\s*?/g);
		
		if (typeof id === 'string') {
			id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
		} else {
			id = id % covers.length;
		}
 
		return covers[id];
	}
 
	return nconf.get('relative_path') + '/images/cover-default.png';
}
 
module.exports = coverPhoto;