| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | var async = require('async'); | 
					
						
							|  |  |  | var validator = require('validator'); | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var meta = require('../meta'); | 
					
						
							|  |  |  | var user = require('../user'); | 
					
						
							|  |  |  | var posts = require('../posts'); | 
					
						
							|  |  |  | var topics = require('../topics'); | 
					
						
							|  |  |  | var categories = require('../categories'); | 
					
						
							|  |  |  | var privileges = require('../privileges'); | 
					
						
							|  |  |  | var plugins = require('../plugins'); | 
					
						
							|  |  |  | var widgets = require('../widgets'); | 
					
						
							| 
									
										
										
										
											2017-04-08 20:22:21 -06:00
										 |  |  | var translator = require('../translator'); | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | var apiController = module.exports; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getConfig = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2014-03-19 02:07:14 -04:00
										 |  |  | 	var config = {}; | 
					
						
							| 
									
										
										
										
											2016-02-10 12:53:39 +02:00
										 |  |  | 	config.environment = process.env.NODE_ENV; | 
					
						
							| 
									
										
										
										
											2014-11-29 23:38:36 -05:00
										 |  |  | 	config.relative_path = nconf.get('relative_path'); | 
					
						
							| 
									
										
										
										
											2015-04-16 11:30:53 +02:00
										 |  |  | 	config.version = nconf.get('version'); | 
					
						
							| 
									
										
										
										
											2016-08-27 15:45:15 +03:00
										 |  |  | 	config.siteTitle = validator.escape(String(meta.config.title || meta.config.browserTitle || 'NodeBB')); | 
					
						
							|  |  |  | 	config.browserTitle = validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB')); | 
					
						
							| 
									
										
										
										
											2015-09-23 01:59:13 -04:00
										 |  |  | 	config.titleLayout = (meta.config.titleLayout || '{pageTitle} | {browserTitle}').replace(/{/g, '{').replace(/}/g, '}'); | 
					
						
							| 
									
										
										
										
											2014-10-22 17:22:47 -04:00
										 |  |  | 	config.showSiteTitle = parseInt(meta.config.showSiteTitle, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.minimumTitleLength = meta.config.minimumTitleLength; | 
					
						
							|  |  |  | 	config.maximumTitleLength = meta.config.maximumTitleLength; | 
					
						
							|  |  |  | 	config.minimumPostLength = meta.config.minimumPostLength; | 
					
						
							| 
									
										
										
										
											2015-02-03 19:55:14 -05:00
										 |  |  | 	config.maximumPostLength = meta.config.maximumPostLength; | 
					
						
							| 
									
										
										
										
											2017-05-29 13:13:11 -04:00
										 |  |  | 	config.minimumTagsPerTopic = parseInt(meta.config.minimumTagsPerTopic || 0, 10); | 
					
						
							|  |  |  | 	config.maximumTagsPerTopic = parseInt(meta.config.maximumTagsPerTopic || 5, 10); | 
					
						
							| 
									
										
										
										
											2016-02-10 12:53:39 +02:00
										 |  |  | 	config.minimumTagLength = meta.config.minimumTagLength || 3; | 
					
						
							|  |  |  | 	config.maximumTagLength = meta.config.maximumTagLength || 15; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.hasImageUploadPlugin = plugins.hasListeners('filter:uploadImage'); | 
					
						
							|  |  |  | 	config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-05-16 16:28:35 -04:00
										 |  |  | 	config.allowGuestSearching = parseInt(meta.config.allowGuestSearching, 10) === 1; | 
					
						
							| 
									
										
										
										
											2015-06-17 14:57:10 -04:00
										 |  |  | 	config.allowGuestUserSearching = parseInt(meta.config.allowGuestUserSearching, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-12-31 12:36:25 -05:00
										 |  |  | 	config.allowGuestHandles = parseInt(meta.config.allowGuestHandles, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 	config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1; | 
					
						
							|  |  |  | 	config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1; | 
					
						
							|  |  |  | 	config.usePagination = parseInt(meta.config.usePagination, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-11-13 15:47:25 -05:00
										 |  |  | 	config.disableChat = parseInt(meta.config.disableChat, 10) === 1; | 
					
						
							| 
									
										
										
										
											2016-10-21 14:36:34 -04:00
										 |  |  | 	config.disableChatMessageEditing = parseInt(meta.config.disableChatMessageEditing, 10) === 1; | 
					
						
							| 
									
										
										
										
											2016-02-10 12:53:39 +02:00
										 |  |  | 	config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket']; | 
					
						
							|  |  |  | 	config.websocketAddress = nconf.get('socket.io:address') || ''; | 
					
						
							| 
									
										
										
										
											2014-04-03 17:36:27 -04:00
										 |  |  | 	config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5; | 
					
						
							| 
									
										
										
										
											2015-03-10 11:52:32 -04:00
										 |  |  | 	config.reconnectionDelay = meta.config.reconnectionDelay || 1500; | 
					
						
							| 
									
										
										
										
											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']; | 
					
						
							| 
									
										
										
										
											2015-08-17 16:11:26 -04:00
										 |  |  | 	config['theme:src'] = meta.config['theme:src']; | 
					
						
							| 
									
										
										
										
											2016-11-23 09:50:49 -07:00
										 |  |  | 	config.defaultLang = meta.config.defaultLang || 'en-GB'; | 
					
						
							| 
									
										
										
										
											2016-08-27 15:45:15 +03:00
										 |  |  | 	config.userLang = req.query.lang ? validator.escape(String(req.query.lang)) : config.defaultLang; | 
					
						
							| 
									
										
										
										
											2014-07-24 21:11:46 -04:00
										 |  |  | 	config.loggedIn = !!req.user; | 
					
						
							| 
									
										
										
										
											2014-04-16 20:19:26 -04:00
										 |  |  | 	config['cache-buster'] = meta.config['cache-buster'] || ''; | 
					
						
							| 
									
										
										
										
											2014-06-03 18:39:54 -04:00
										 |  |  | 	config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1; | 
					
						
							| 
									
										
										
										
											2014-06-06 22:12:14 -04:00
										 |  |  | 	config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest'; | 
					
						
							| 
									
										
										
										
											2015-01-08 13:47:15 -05:00
										 |  |  | 	config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest'; | 
					
						
							| 
									
										
										
										
											2014-11-18 14:54:54 -05:00
										 |  |  | 	config.csrf_token = req.csrfToken(); | 
					
						
							| 
									
										
										
										
											2014-11-24 12:38:44 -05:00
										 |  |  | 	config.searchEnabled = plugins.hasListeners('filter:search.query'); | 
					
						
							| 
									
										
										
										
											2017-03-07 13:09:14 +03:00
										 |  |  | 	config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin'; | 
					
						
							|  |  |  | 	config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin'; | 
					
						
							| 
									
										
										
										
											2016-11-30 16:28:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-10 14:03:07 -05:00
										 |  |  | 	if (config.useOutgoingLinksPage) { | 
					
						
							|  |  |  | 		config.outgoingLinksWhitelist = meta.config['outgoingLinks:whitelist']; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-30 16:28:25 +03:00
										 |  |  | 	var timeagoCutoff = meta.config.timeagoCutoff === undefined ? 30 : meta.config.timeagoCutoff; | 
					
						
							|  |  |  | 	config.timeagoCutoff = timeagoCutoff !== '' ? Math.max(0, parseInt(timeagoCutoff, 10)) : timeagoCutoff; | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-01 12:59:51 -04:00
										 |  |  | 	config.cookies = { | 
					
						
							|  |  |  | 		enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1, | 
					
						
							| 
									
										
										
										
											2017-03-24 14:46:51 -04:00
										 |  |  | 		message: translator.escape(validator.escape(meta.config.cookieConsentMessage || '[[global:cookies.message]]')).replace(/\\/g, '\\\\'), | 
					
						
							|  |  |  | 		dismiss: translator.escape(validator.escape(meta.config.cookieConsentDismiss || '[[global:cookies.accept]]')).replace(/\\/g, '\\\\'), | 
					
						
							|  |  |  | 		link: translator.escape(validator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]')).replace(/\\/g, '\\\\'), | 
					
						
							| 
									
										
										
										
											2016-11-01 12:59:51 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			if (!req.user) { | 
					
						
							|  |  |  | 				return next(null, config); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-08-29 12:43:32 +03:00
										 |  |  | 			user.getSettings(req.uid, next); | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-08-29 12:43:32 +03:00
										 |  |  | 		function (settings, next) { | 
					
						
							|  |  |  | 			config.usePagination = settings.usePagination; | 
					
						
							|  |  |  | 			config.topicsPerPage = settings.topicsPerPage; | 
					
						
							|  |  |  | 			config.postsPerPage = settings.postsPerPage; | 
					
						
							|  |  |  | 			config.userLang = (req.query.lang ? validator.escape(String(req.query.lang)) : null) || settings.userLang || config.defaultLang; | 
					
						
							|  |  |  | 			config.openOutgoingLinksInNewTab = settings.openOutgoingLinksInNewTab; | 
					
						
							|  |  |  | 			config.topicPostSort = settings.topicPostSort || config.topicPostSort; | 
					
						
							|  |  |  | 			config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort; | 
					
						
							|  |  |  | 			config.topicSearchEnabled = settings.topicSearchEnabled || false; | 
					
						
							|  |  |  | 			config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true; | 
					
						
							| 
									
										
										
										
											2017-03-07 13:09:14 +03:00
										 |  |  | 			config.bootswatchSkin = (settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin; | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 			plugins.fireHook('filter:config.get', config, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	], function (err, config) { | 
					
						
							| 
									
										
										
										
											2014-04-13 15:05:17 -04:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 		if (res.locals.isAPI) { | 
					
						
							|  |  |  | 			res.json(config); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			next(null, config); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-03-26 11:57:42 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-03-03 11:45:23 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.renderWidgets = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-12-13 14:11:56 +03:00
										 |  |  | 	if (!req.query.template || !req.query.locations) { | 
					
						
							| 
									
										
										
										
											2014-10-04 18:47:56 -04:00
										 |  |  | 		return res.status(200).json({}); | 
					
						
							| 
									
										
										
										
											2014-07-09 19:23:03 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 00:36:13 -07:00
										 |  |  | 	widgets.render(req.uid, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-12-13 14:11:56 +03:00
										 |  |  | 			template: req.query.template, | 
					
						
							|  |  |  | 			url: req.query.url, | 
					
						
							|  |  |  | 			locations: req.query.locations, | 
					
						
							|  |  |  | 			isMobile: req.query.isMobile === 'true', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			cid: req.query.cid, | 
					
						
							| 
									
										
										
										
											2015-09-16 00:46:11 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2015-09-16 00:36:13 -07:00
										 |  |  | 		req, | 
					
						
							|  |  |  | 		res, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (err, widgets) { | 
					
						
							| 
									
										
										
										
											2017-02-18 02:38:03 -07:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			res.status(200).json(widgets); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-07-09 15:41:03 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getPostData = function (pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 	async.parallel({ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		privileges: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			privileges.posts.get([pid], uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		post: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			posts.getPostData(pid, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	}, function (err, results) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		if (err || !results.post) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		var post = results.post; | 
					
						
							|  |  |  | 		var privileges = results.privileges[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!privileges.read || !privileges['topics:read']) { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		post.ip = privileges.isAdminOrMod ? post.ip : undefined; | 
					
						
							|  |  |  | 		var selfPost = uid && uid === parseInt(post.uid, 10); | 
					
						
							|  |  |  | 		if (post.deleted && !(privileges.isAdminOrMod || selfPost)) { | 
					
						
							|  |  |  | 			post.content = '[[topic:post_is_deleted]]'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		callback(null, post); | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getTopicData = function (tid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 	async.parallel({ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		privileges: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			privileges.topics.get(tid, uid, next); | 
					
						
							| 
									
										
										
										
											2015-09-21 12:59:41 -04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		topic: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			topics.getTopicData(tid, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	}, function (err, results) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		if (err || !results.topic) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							| 
									
										
										
										
											2015-09-21 12:59:41 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		if (!results.privileges.read || !results.privileges['topics:read'] || (parseInt(results.topic.deleted, 10) && !results.privileges.view_deleted)) { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		callback(null, results.topic); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-09-21 12:59:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getCategoryData = function (cid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 	async.parallel({ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		privileges: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			privileges.categories.get(cid, uid, next); | 
					
						
							| 
									
										
										
										
											2016-03-08 11:24:32 +02:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		category: function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 			categories.getCategoryData(cid, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	}, function (err, results) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		if (err || !results.category) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!results.privileges.read) { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							| 
									
										
										
										
											2015-09-21 12:59:41 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		callback(null, results.category); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getObject = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 	var methods = { | 
					
						
							|  |  |  | 		post: apiController.getPostData, | 
					
						
							|  |  |  | 		topic: apiController.getTopicData, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		category: apiController.getCategoryData, | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	var method = methods[req.params.type]; | 
					
						
							|  |  |  | 	if (!method) { | 
					
						
							|  |  |  | 		return next(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	method(req.params.id, req.uid, function (err, result) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		if (err || !result) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		res.json(result); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-09-21 12:59:41 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | apiController.getModerators = function (req, res, next) { | 
					
						
							|  |  |  | 	categories.getModerators(req.params.cid, function (err, moderators) { | 
					
						
							| 
									
										
										
										
											2015-09-25 18:29:02 -04:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		res.json({ moderators: moderators }); | 
					
						
							| 
									
										
										
										
											2015-09-25 13:11:11 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; |