function CommentsNewRateLimit (comment, user) { if (!Users.isAdmin(user)) { const timeSinceLastComment = Users.timeSinceLast(user, Comments); const commentInterval = Math.abs(parseInt(getSetting('commentInterval',15))); // check that user waits more than 15 seconds between comments if((timeSinceLastComment < commentInterval)) { throw new Error(Utils.encodeIntlError({id: "comments.rate_limit_error", value: commentInterval-timeSinceLastComment})); } } return comment; }
////////////////////////////////////////////////////// // posts.new.validate // ////////////////////////////////////////////////////// /** * @summary Rate limiting */ function PostsNewRateLimit (post, user) { if(!Users.isAdmin(user)){ var timeSinceLastPost = Users.timeSinceLast(user, Posts), numberOfPostsInPast24Hours = Users.numberOfItemsInPast24Hours(user, Posts), postInterval = Math.abs(parseInt(getSetting('postInterval', 30))), maxPostsPer24Hours = Math.abs(parseInt(getSetting('maxPostsPerDay', 5))); // check that user waits more than X seconds between posts if(timeSinceLastPost < postInterval) throw new Error(Utils.encodeIntlError({id: "posts.rate_limit_error", value: postInterval-timeSinceLastPost})); // check that the user doesn't post more than Y posts per day if(numberOfPostsInPast24Hours >= maxPostsPer24Hours) throw new Error(Utils.encodeIntlError({id: "posts.max_per_day", value: maxPostsPer24Hours})); } return post; }