| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var pkg = require('./../../package.json'), | 
					
						
							|  |  |  | 	meta = require('./../meta'), | 
					
						
							|  |  |  | 	user = require('./../user'), | 
					
						
							|  |  |  | 	plugins = require('./../plugins'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var apiController = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-03 12:16:46 -05:00
										 |  |  | apiController.getConfig = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2014-03-19 02:07:14 -04:00
										 |  |  | 	var serverConfig = require('./../../config.json'); | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 02:07:14 -04:00
										 |  |  | 	var config = {}; | 
					
						
							|  |  |  | 	config.relative_path = serverConfig.relative_path; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.version = pkg.version; | 
					
						
							|  |  |  | 	config.postDelay = meta.config.postDelay; | 
					
						
							|  |  |  | 	config.minimumTitleLength = meta.config.minimumTitleLength; | 
					
						
							|  |  |  | 	config.maximumTitleLength = meta.config.maximumTitleLength; | 
					
						
							|  |  |  | 	config.minimumPostLength = meta.config.minimumPostLength; | 
					
						
							|  |  |  | 	config.hasImageUploadPlugin = plugins.hasListeners('filter:uploadImage'); | 
					
						
							|  |  |  | 	config.maximumProfileImageSize = meta.config.maximumProfileImageSize; | 
					
						
							|  |  |  | 	config.minimumUsernameLength = meta.config.minimumUsernameLength; | 
					
						
							|  |  |  | 	config.maximumUsernameLength = meta.config.maximumUsernameLength; | 
					
						
							|  |  |  | 	config.minimumPasswordLength = meta.config.minimumPasswordLength; | 
					
						
							|  |  |  | 	config.maximumSignatureLength = meta.config.maximumSignatureLength; | 
					
						
							|  |  |  | 	config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1; | 
					
						
							|  |  |  | 	config.allowGuestPosting = parseInt(meta.config.allowGuestPosting, 10) === 1; | 
					
						
							|  |  |  | 	config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1; | 
					
						
							|  |  |  | 	config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 	config.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.usePagination = parseInt(meta.config.usePagination, 10) === 1; | 
					
						
							|  |  |  | 	config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-04-03 17:36:27 -04:00
										 |  |  | 	config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5; | 
					
						
							|  |  |  | 	config.reconnectionDelay = meta.config.reconnectionDelay || 200; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.topicsPerPage = meta.config.topicsPerPage || 20; | 
					
						
							|  |  |  | 	config.postsPerPage = meta.config.postsPerPage || 20; | 
					
						
							|  |  |  | 	config.maximumFileSize = meta.config.maximumFileSize; | 
					
						
							| 
									
										
										
										
											2014-03-09 19:19:13 -04:00
										 |  |  | 	config['theme:id'] = meta.config['theme:id']; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.defaultLang = meta.config.defaultLang || 'en_GB'; | 
					
						
							|  |  |  | 	config.environment = process.env.NODE_ENV; | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 	config.isLoggedIn = !!req.user; | 
					
						
							| 
									
										
										
										
											2014-04-16 20:19:26 -04:00
										 |  |  | 	config['cache-buster'] = meta.config['cache-buster'] || ''; | 
					
						
							| 
									
										
										
										
											2014-04-30 09:12:09 -04:00
										 |  |  | 	config.version = pkg.version; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!req.user) { | 
					
						
							| 
									
										
										
										
											2014-03-03 12:16:46 -05:00
										 |  |  | 		if (res.locals.isAPI) { | 
					
						
							|  |  |  | 			res.json(200, config); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			next(null, config); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 	user.getSettings(req.user.uid, function(err, settings) { | 
					
						
							| 
									
										
										
										
											2014-04-13 15:05:17 -04:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 		config.usePagination = settings.usePagination; | 
					
						
							|  |  |  | 		config.topicsPerPage = settings.topicsPerPage; | 
					
						
							|  |  |  | 		config.postsPerPage = settings.postsPerPage; | 
					
						
							|  |  |  | 		config.notificationSounds = settings.notificationSounds; | 
					
						
							| 
									
										
										
										
											2014-04-14 15:58:13 -04:00
										 |  |  | 		config.defaultLang = settings.language || config.defaultLang; | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (res.locals.isAPI) { | 
					
						
							|  |  |  | 			res.json(200, config); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			next(err, config); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | module.exports = apiController; |