2017-03-23 16:27:59 +09:00
|
|
|
import { addCallback } from 'meteor/vulcan:core';
|
2015-09-03 14:30:35 +09:00
|
|
|
|
|
|
|
// limit the number of items that can be requested at once
|
2017-01-05 15:53:41 +01:00
|
|
|
const CommentsMaxLimit = (parameters, terms) => {
|
2015-09-03 14:30:35 +09:00
|
|
|
var maxLimit = 1000;
|
2015-05-08 09:20:58 +09:00
|
|
|
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
|
2015-09-03 14:30:35 +09:00
|
|
|
if (typeof terms.limit !== 'undefined') {
|
2015-05-08 09:20:58 +09:00
|
|
|
_.extend(parameters.options, {limit: parseInt(terms.limit)});
|
2015-09-03 14:30:35 +09:00
|
|
|
}
|
2015-05-08 09:20:58 +09:00
|
|
|
|
2015-09-03 14:30:35 +09:00
|
|
|
// limit to "maxLimit" items at most when limit is undefined, equal to 0, or superior to maxLimit
|
|
|
|
if(!parameters.options.limit || parameters.options.limit === 0 || parameters.options.limit > maxLimit) {
|
2015-05-08 09:20:58 +09:00
|
|
|
parameters.options.limit = maxLimit;
|
|
|
|
}
|
|
|
|
return parameters;
|
2015-09-03 14:30:35 +09:00
|
|
|
}
|
2017-01-05 15:53:41 +01:00
|
|
|
|
|
|
|
addCallback("comments.parameters", CommentsMaxLimit);
|