mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	more work
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
| var nconf = require('nconf'); | var nconf = require('nconf'); | ||||||
| 	db = require('./databases/' + nconf.get('database')); | 	db = require('./database/' + nconf.get('database')); | ||||||
|  |  | ||||||
| module.exports = db; | module.exports = db; | ||||||
| @@ -0,0 +1,72 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
|  | (function(module) { | ||||||
|  | 	'use strict'; | ||||||
|  | 	var mongoClient, | ||||||
|  | 		mongo = require('mongo') | ||||||
|  | 		winston = require('winston'), | ||||||
|  | 		nconf = require('nconf'), | ||||||
|  | 		mongoHost = nconf.get('mongo:host'), | ||||||
|  | 		utils = require('./../../public/src/utils.js'); | ||||||
|  |  | ||||||
|  | 	// temp, look this up | ||||||
|  | 	mongoClient = mongo.createClient(nconf.get('mongo:port'), nconf.get('mongo:host')); | ||||||
|  |  | ||||||
|  | 	// look up how its done in mongo | ||||||
|  | 	/*if (nconf.get('mongo:password')) { | ||||||
|  | 		redisClient.auth(nconf.get('mongo:password')); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	var db = parseInt(nconf.get('mongo:database'), 10); | ||||||
|  |  | ||||||
|  | 	if (db){ | ||||||
|  | 		mongoClient.select(db, function(error) { | ||||||
|  | 			if(error) { | ||||||
|  | 				winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message); | ||||||
|  | 				process.exit(); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	}*/ | ||||||
|  |  | ||||||
|  | 	// | ||||||
|  | 	// Exported functions | ||||||
|  | 	// | ||||||
|  | 	module.getFileName = function(callback) { | ||||||
|  | 		// TODO : get mongodb filename | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	module.setObject = function(key, data, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.setObjectField = function(key, field, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObject = function(key, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObjectField = function(key, field, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObjectFields = function(key, fields, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.deleteObjectField = function(key, field, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.incrObjectField = function(key, field, value, callback) { | ||||||
|  | 		// TODO : implement in mongo | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | }(exports)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,65 +2,76 @@ | |||||||
|  |  | ||||||
| (function(module) { | (function(module) { | ||||||
| 	'use strict'; | 	'use strict'; | ||||||
| 	var RedisDB, | 	var redisClient, | ||||||
| 		redis = require('redis'), | 		redis = require('redis'), | ||||||
| 		winston = require('winston'), | 		winston = require('winston'), | ||||||
| 		nconf = require('nconf'), | 		nconf = require('nconf'), | ||||||
| 		redis_socket_or_host = nconf.get('redis:host'), | 		redis_socket_or_host = nconf.get('redis:host'), | ||||||
| 		utils = require('./../public/src/utils.js'); | 		utils = require('./../../public/src/utils.js'); | ||||||
|  |  | ||||||
| 	if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) { | 	if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) { | ||||||
| 		/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */ | 		/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */ | ||||||
| 		RedisDB = redis.createClient(nconf.get('redis:host')); | 		redisClient = redis.createClient(nconf.get('redis:host')); | ||||||
| 	} else { | 	} else { | ||||||
| 		/* Else, connect over tcp/ip */ | 		/* Else, connect over tcp/ip */ | ||||||
| 		RedisDB = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); | 		redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (nconf.get('redis:password')) { | 	if (nconf.get('redis:password')) { | ||||||
| 		RedisDB.auth(nconf.get('redis:password')); | 		redisClient.auth(nconf.get('redis:password')); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var db = parseInt(nconf.get('redis:database'), 10); | 	var db = parseInt(nconf.get('redis:database'), 10); | ||||||
|  |  | ||||||
| 	if (db){ | 	if (db){ | ||||||
| 		RedisDB.select(db, function(error){ | 		redisClient.select(db, function(error) { | ||||||
| 			if(error !== null){ | 			if(error) { | ||||||
| 				winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message); | 				winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message); | ||||||
| 				process.exit(); | 				process.exit(); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	RedisDB.handle = function(error) { |  | ||||||
| 		if (error !== null) { |  | ||||||
| 			winston.err(error); |  | ||||||
| 			if (global.env !== 'production') { |  | ||||||
| 				throw new Error(error); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * A possibly more efficient way of doing multiple sismember calls | 	 * A possibly more efficient way of doing multiple sismember calls | ||||||
| 	 */ | 	 */ | ||||||
| 	RedisDB.sismembers = function(key, needles, callback) { | 	function sismembers(key, needles, callback) { | ||||||
| 		var tempkey = key + ':temp:' + utils.generateUUID(); | 		var tempkey = key + ':temp:' + utils.generateUUID(); | ||||||
| 		RedisDB.sadd(tempkey, needles, function() { | 		redisClient.sadd(tempkey, needles, function() { | ||||||
| 			RedisDB.sinter(key, tempkey, function(err, data) { | 			redisClient.sinter(key, tempkey, function(err, data) { | ||||||
| 				RedisDB.del(tempkey); | 				redisClient.del(tempkey); | ||||||
| 				callback(err, data); | 				callback(err, data); | ||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	/* | 	// | ||||||
| 	 * gets fields of a hash as an object instead of an array | 	// Exported functions | ||||||
| 	 */ | 	// | ||||||
| 	RedisDB.hmgetObject = function(key, fields, callback) { | 	module.setObject = function(key, data, callback) { | ||||||
| 		RedisDB.hmget(key, fields, function(err, data) { | 		redisClient.hmset(key, data, callback); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.setObjectField = function(key, field, callback) { | ||||||
|  | 		redisClient.hset(key, field, callback) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObject = function(key, callback) { | ||||||
|  | 		redisClient.hgetall(key, callback) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObjectField = function(key, field, callback) { | ||||||
|  | 		module.getObjectFields(key, [field], function(err, data) { | ||||||
|  | 			if(err) { | ||||||
|  | 				return callback(err); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			callback(null, data[field]); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.getObjectFields = function(key, fields, callback) { | ||||||
|  | 		redisClient.hmget(key, fields, function(err, data) { | ||||||
| 			if(err) { | 			if(err) { | ||||||
| 				return callback(err, null); | 				return callback(err, null); | ||||||
| 			} | 			} | ||||||
| @@ -73,9 +84,18 @@ | |||||||
|  |  | ||||||
| 			callback(null, returnData); | 			callback(null, returnData); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	} | ||||||
|  |  | ||||||
|  | 	module.deleteObjectField = function(key, field, callback) { | ||||||
|  | 		redisClient.hdel(key, field, callback); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	module.incrObjectField = function(key, field, value, callback) { | ||||||
|  | 		redisClient.hincrby(key, field, value, callback); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 	module.exports = RedisDB; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| }(exports)); | }(exports)); | ||||||
|   | |||||||
							
								
								
									
										72
									
								
								src/meta.js
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								src/meta.js
									
									
									
									
									
								
							| @@ -1,11 +1,13 @@ | |||||||
| var utils = require('./../public/src/utils.js'), | var fs = require('fs'), | ||||||
| 	RDB = require('./redis.js'), |  | ||||||
| 	plugins = require('./plugins'), |  | ||||||
| 	async = require('async'), |  | ||||||
| 	path = require('path'), | 	path = require('path'), | ||||||
| 	fs = require('fs'), | 	async = require('async'), | ||||||
| 	winston = require('winston'), | 	winston = require('winston'), | ||||||
| 	nconf = require('nconf'); | 	nconf = require('nconf'), | ||||||
|  |  | ||||||
|  | 	utils = require('./../public/src/utils'), | ||||||
|  | 	db = require('./database'), | ||||||
|  | 	plugins = require('./plugins'); | ||||||
|  |  | ||||||
|  |  | ||||||
| (function (Meta) { | (function (Meta) { | ||||||
| 	Meta.config = {}; | 	Meta.config = {}; | ||||||
| @@ -15,33 +17,34 @@ var utils = require('./../public/src/utils.js'), | |||||||
| 			delete Meta.config; | 			delete Meta.config; | ||||||
|  |  | ||||||
| 			Meta.configs.list(function (err, config) { | 			Meta.configs.list(function (err, config) { | ||||||
| 				if (!err) { | 				if(err) { | ||||||
|  | 					winston.error(err); | ||||||
|  | 					return callback(err); | ||||||
|  | 				} | ||||||
|  |  | ||||||
| 				Meta.config = config; | 				Meta.config = config; | ||||||
| 				callback(); | 				callback(); | ||||||
| 				} else { |  | ||||||
| 					winston.error(err); |  | ||||||
| 				} |  | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		list: function (callback) { | 		list: function (callback) { | ||||||
| 			RDB.hgetall('config', function (err, config) { | 			db.getObject('config', function (err, config) { | ||||||
| 				if (!err) { | 				if(err) { | ||||||
|  | 					return callback(new Error('could-not-read-config')); | ||||||
|  | 				} | ||||||
|  |  | ||||||
| 				config = config || {}; | 				config = config || {}; | ||||||
| 				config.status = 'ok'; | 				config.status = 'ok'; | ||||||
| 				callback(err, config); | 				callback(err, config); | ||||||
| 				} else { |  | ||||||
| 					callback(new Error('could-not-read-config')); |  | ||||||
| 				} |  | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		get: function (field, callback) { | 		get: function (field, callback) { | ||||||
| 			RDB.hget('config', field, callback); | 			db.getObjectField('config', field, callback); | ||||||
| 		}, | 		}, | ||||||
| 		getFields: function (fields, callback) { | 		getFields: function (fields, callback) { | ||||||
| 			RDB.hmgetObject('config', fields, callback); | 			db.getObjectFields('config', fields, callback); | ||||||
| 		}, | 		}, | ||||||
| 		set: function (field, value, callback) { | 		set: function (field, value, callback) { | ||||||
| 			RDB.hset('config', field, value, function (err, res) { | 			db.setObjectField(field, value, function(err, res) { | ||||||
| 				if (callback) { | 				if (callback) { | ||||||
| 					if(!err && Meta.config) | 					if(!err && Meta.config) | ||||||
| 						Meta.config[field] = value; | 						Meta.config[field] = value; | ||||||
| @@ -59,7 +62,7 @@ var utils = require('./../public/src/utils.js'), | |||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		remove: function (field) { | 		remove: function (field) { | ||||||
| 			RDB.hdel('config', field); | 			db.deleteObjectField('config', field); | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -125,7 +128,7 @@ var utils = require('./../public/src/utils.js'), | |||||||
| 							themeData['theme:staticDir'] = config.staticDir ? config.staticDir : ''; | 							themeData['theme:staticDir'] = config.staticDir ? config.staticDir : ''; | ||||||
| 							themeData['theme:templates'] = config.templates ? config.templates : ''; | 							themeData['theme:templates'] = config.templates ? config.templates : ''; | ||||||
|  |  | ||||||
| 							RDB.hmset('config', themeData, next); | 							db.setObject('config', themeData, next); | ||||||
| 						} | 						} | ||||||
| 					], function(err) { | 					], function(err) { | ||||||
| 						callback(err); | 						callback(err); | ||||||
| @@ -134,7 +137,7 @@ var utils = require('./../public/src/utils.js'), | |||||||
|  |  | ||||||
| 				case 'bootswatch': | 				case 'bootswatch': | ||||||
| 					themeData['theme:src'] = data.src; | 					themeData['theme:src'] = data.src; | ||||||
| 					RDB.hmset('config', themeData, callback); | 					db.setObject('config', themeData, callback); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -256,11 +259,16 @@ var utils = require('./../public/src/utils.js'), | |||||||
| 				}), | 				}), | ||||||
| 				minified; | 				minified; | ||||||
|  |  | ||||||
| 			if (process.env.NODE_ENV === 'development') winston.info('Minifying client-side libraries'); | 			if (process.env.NODE_ENV === 'development') { | ||||||
|  | 				winston.info('Minifying client-side libraries'); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			minified = uglifyjs.minify(jsPaths); | 			minified = uglifyjs.minify(jsPaths); | ||||||
| 			fs.writeFile(Meta.js.minFile, minified.code, function (err) { | 			fs.writeFile(Meta.js.minFile, minified.code, function (err) { | ||||||
| 				if (!err) { | 				if (!err) { | ||||||
| 					if (process.env.NODE_ENV === 'development') winston.info('Minified client-side libraries'); | 					if (process.env.NODE_ENV === 'development') { | ||||||
|  | 						winston.info('Minified client-side libraries'); | ||||||
|  | 					} | ||||||
| 					callback(); | 					callback(); | ||||||
| 				} else { | 				} else { | ||||||
| 					winston.error('Problem minifying client-side libraries, exiting.'); | 					winston.error('Problem minifying client-side libraries, exiting.'); | ||||||
| @@ -272,23 +280,7 @@ var utils = require('./../public/src/utils.js'), | |||||||
|  |  | ||||||
| 	Meta.db = { | 	Meta.db = { | ||||||
| 		getFile: function (callback) { | 		getFile: function (callback) { | ||||||
| 			var multi = RDB.multi(); | 			db.getFileName(callback); | ||||||
|  |  | ||||||
| 			multi.config('get', 'dir'); |  | ||||||
| 			multi.config('get', 'dbfilename'); |  | ||||||
| 			multi.exec(function (err, results) { |  | ||||||
| 				if (err) { |  | ||||||
| 					return callback(err); |  | ||||||
| 				} else { |  | ||||||
| 					results = results.reduce(function (memo, config) { |  | ||||||
| 						memo[config[0]] = config[1]; |  | ||||||
| 						return memo; |  | ||||||
| 					}, {}); |  | ||||||
|  |  | ||||||
| 					var dbFile = path.join(results.dir, results.dbfilename); |  | ||||||
| 					callback(null, dbFile); |  | ||||||
| 				} |  | ||||||
| 			}); |  | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
| }(exports)); | }(exports)); | ||||||
| @@ -1,9 +1,10 @@ | |||||||
| var fs = require('fs'), | var fs = require('fs'), | ||||||
| 	path = require('path'), | 	path = require('path'), | ||||||
| 	RDB = require('./redis.js'), |  | ||||||
| 	async = require('async'), | 	async = require('async'), | ||||||
| 	winston = require('winston'), | 	winston = require('winston'), | ||||||
| 	eventEmitter = require('events').EventEmitter, | 	eventEmitter = require('events').EventEmitter, | ||||||
|  | 	db = require('./database'), | ||||||
|  |  | ||||||
| 	plugins = { | 	plugins = { | ||||||
| 		libraries: {}, | 		libraries: {}, | ||||||
| 		loadedHooks: {}, | 		loadedHooks: {}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user