mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
do not do rate limit checks for admin, and use createdAt instead of submitted
This commit is contained in:
parent
f7fff10572
commit
63abe81d2c
2 changed files with 11 additions and 8 deletions
|
@ -32,12 +32,15 @@ Meteor.methods({
|
|||
throw new Meteor.Error(603, 'This link has already been posted', postWithSameLink._id);
|
||||
}
|
||||
|
||||
// check that user waits more than 30 seconds between posts
|
||||
if(!this.isSimulation && timeSinceLastPost < postInterval)
|
||||
throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again');
|
||||
if(!isAdmin(Meteor.user())){
|
||||
// check that user waits more than X seconds between posts
|
||||
if(!this.isSimulation && timeSinceLastPost < postInterval)
|
||||
throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again');
|
||||
|
||||
if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours)
|
||||
throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day');
|
||||
// check that the user doesn't post more than Y posts per day
|
||||
if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours)
|
||||
throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day');
|
||||
}
|
||||
|
||||
post = _.extend(post, {
|
||||
headline: headline,
|
||||
|
|
|
@ -49,20 +49,20 @@ userProfileComplete = function(user) {
|
|||
}
|
||||
|
||||
findLast = function(user, collection){
|
||||
return collection.findOne({userId: user._id}, {sort: {submitted: -1}});
|
||||
return collection.findOne({userId: user._id}, {sort: {createdAt: -1}});
|
||||
}
|
||||
timeSinceLast = function(user, collection){
|
||||
var now = new Date().getTime();
|
||||
var last = findLast(user, collection);
|
||||
if(!last)
|
||||
return 999; // if this is the user's first post or comment ever, stop here
|
||||
return Math.abs(Math.floor((now-last.submitted)/1000));
|
||||
return Math.abs(Math.floor((now-last.createdAt)/1000));
|
||||
}
|
||||
numberOfItemsInPast24Hours = function(user, collection){
|
||||
var mDate = moment(new Date());
|
||||
var items=collection.find({
|
||||
userId: user._id,
|
||||
submitted: {
|
||||
createdAt: {
|
||||
$gte: mDate.subtract('hours',24).valueOf()
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue