mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Limiting on how much you can shuffle
This commit is contained in:
		@@ -8,6 +8,7 @@ try {
 | 
			
		||||
}
 | 
			
		||||
var mongojs = require('mongojs');
 | 
			
		||||
var db = mongojs('mongodb://' + mongo_config.host + '/' + mongo_config.config);
 | 
			
		||||
var ObjectId = mongojs.ObjectId;
 | 
			
		||||
 | 
			
		||||
db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 });
 | 
			
		||||
db.collection("timeout_api").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 5 });
 | 
			
		||||
 
 | 
			
		||||
@@ -242,6 +242,28 @@ function shuffle(msg, coll, guid, offline, socket) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        db.collection("timeout_api").find({
 | 
			
		||||
            type: "shuffle",
 | 
			
		||||
            guid: guid,
 | 
			
		||||
        }, function(err, docs) {
 | 
			
		||||
            if(docs.length > 0) {
 | 
			
		||||
                var date = new Date(docs[0].createdAt);
 | 
			
		||||
                date.setSeconds(date.getSeconds() + 5);
 | 
			
		||||
                var now = new Date();
 | 
			
		||||
                var retry_in = (date.getTime() - now.getTime()) / 1000;
 | 
			
		||||
                if(retry_in > 0) {
 | 
			
		||||
                    socket.emit("toast", "wait_longer");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            var now_date = new Date();
 | 
			
		||||
            db.collection("timeout_api").update({type: "shuffle", guid: guid}, {
 | 
			
		||||
                $set: {
 | 
			
		||||
                    "createdAt": now_date,
 | 
			
		||||
                    type: "shuffle",
 | 
			
		||||
                    guid: guid,
 | 
			
		||||
                },
 | 
			
		||||
            }, {upsert: true}, function(err, docs) {
 | 
			
		||||
                Functions.check_inlist(coll, guid, socket, offline);
 | 
			
		||||
                var hash;
 | 
			
		||||
                if(msg.adminpass === "") hash = msg.adminpass;
 | 
			
		||||
@@ -275,7 +297,8 @@ function shuffle(msg, coll, guid, offline, socket) {
 | 
			
		||||
                        List.getNextSong(coll);
 | 
			
		||||
                    }
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }else
 | 
			
		||||
    socket.emit("toast", "wrongpass");
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,9 @@ var Admin = {
 | 
			
		||||
            case "faulty_start_end":
 | 
			
		||||
                msg = "You tried to send a faulty start/end value. Try again..";
 | 
			
		||||
                break;
 | 
			
		||||
            case "wait_longer":
 | 
			
		||||
                msg = Helper.rnd(["Have you tried to wait longer between commands?!", "Looks like you're clicking that button too much..", "You need to wait longer between clicks.."]);
 | 
			
		||||
                break;
 | 
			
		||||
            case "suggested_description":
 | 
			
		||||
                msg = "The description has been suggested!";
 | 
			
		||||
                break;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
var express = require('express');
 | 
			
		||||
var router = express.Router();
 | 
			
		||||
var path = require('path');
 | 
			
		||||
var mongojs = require('mongojs');
 | 
			
		||||
var ObjectId = mongojs.ObjectId;
 | 
			
		||||
 | 
			
		||||
router.use(function(req, res, next) {
 | 
			
		||||
    next(); // make sure we go to the next routes and don't stop here
 | 
			
		||||
@@ -43,6 +45,21 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    db.collection("timeout_api").find({
 | 
			
		||||
        type: "DELETE",
 | 
			
		||||
        guid: guid,
 | 
			
		||||
    }, function(err, docs) {
 | 
			
		||||
        if(docs.length > 0) {
 | 
			
		||||
            var date = new Date(docs[0].createdAt);
 | 
			
		||||
            date.setSeconds(date.getSeconds() + 5);
 | 
			
		||||
            var now = new Date();
 | 
			
		||||
            var retry_in = (date.getTime() - now.getTime()) / 1000;
 | 
			
		||||
            if(retry_in > 0) {
 | 
			
		||||
                res.header({'Retry-After': retry_in});
 | 
			
		||||
                res.sendStatus(429);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        validateLogin(adminpass, userpass, channel_name, "delete", res, function(exists) {
 | 
			
		||||
            if(!exists) {
 | 
			
		||||
                res.sendStatus(404);
 | 
			
		||||
@@ -62,17 +79,34 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
 | 
			
		||||
                        io.to(channel_name).emit("channel", {type:"deleted", value: video_id});
 | 
			
		||||
                        if(dont_increment) {
 | 
			
		||||
                            db.collection("frontpage_lists").update({_id: channel_name, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){
 | 
			
		||||
                                db.collection("timeout_api").update({type: "DELETE", guid: guid}, {
 | 
			
		||||
                                    $set: {
 | 
			
		||||
                                        "createdAt": new Date(),
 | 
			
		||||
                                        type: "DELETE",
 | 
			
		||||
                                        guid: guid,
 | 
			
		||||
                                    },
 | 
			
		||||
                                }, {upsert: true}, function(err, docs) {
 | 
			
		||||
                                    res.sendStatus(200);
 | 
			
		||||
                                    return;
 | 
			
		||||
                                });
 | 
			
		||||
                            });
 | 
			
		||||
                        } else {
 | 
			
		||||
                            db.collection("timeout_api").update({type: "DELETE", guid: guid}, {
 | 
			
		||||
                                $set: {
 | 
			
		||||
                                    "createdAt": new Date(),
 | 
			
		||||
                                    type: "DELETE",
 | 
			
		||||
                                    guid: guid,
 | 
			
		||||
                                },
 | 
			
		||||
                            }, {upsert: true}, function(err, docs) {
 | 
			
		||||
                                res.sendStatus(200);
 | 
			
		||||
                                return;
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function cleanChannelName(channel_name) {
 | 
			
		||||
@@ -148,7 +182,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    db.collection("timeout_api").find({
 | 
			
		||||
        type: "DELETE",
 | 
			
		||||
        type: "CONFIG",
 | 
			
		||||
        guid: guid,
 | 
			
		||||
    }, function(err, docs) {
 | 
			
		||||
        if(docs.length > 0) {
 | 
			
		||||
@@ -156,10 +190,12 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
 | 
			
		||||
            date.setSeconds(date.getSeconds() + 5);
 | 
			
		||||
            var now = new Date();
 | 
			
		||||
            var retry_in = (date.getTime() - now.getTime()) / 1000;
 | 
			
		||||
            if(retry_in > 0) {
 | 
			
		||||
                res.header({'Retry-After': retry_in});
 | 
			
		||||
                res.sendStatus(429);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        validateLogin(adminpass, userpass, channel_name, "config", res, function(exists) {
 | 
			
		||||
            if(!exists) {
 | 
			
		||||
                res.sendStatus(404);
 | 
			
		||||
@@ -203,10 +239,10 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
 | 
			
		||||
                    frontpage:frontpage, accessed: Functions.get_time()}
 | 
			
		||||
                },
 | 
			
		||||
                {upsert:true}, function(err, docs){
 | 
			
		||||
                    db.collection("timeout_api").update({type: "DELETE", guid: guid}, {
 | 
			
		||||
                    db.collection("timeout_api").update({type: "CONFIG", guid: guid}, {
 | 
			
		||||
                        $set: {
 | 
			
		||||
                            "createdAt": new Date(),
 | 
			
		||||
                            type: "DELETE",
 | 
			
		||||
                            type: "CONFIG",
 | 
			
		||||
                            guid: guid,
 | 
			
		||||
                        },
 | 
			
		||||
                    }, {upsert: true}, function(err, docs) {
 | 
			
		||||
@@ -217,7 +253,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
})
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
 | 
			
		||||
    res.header("Access-Control-Allow-Origin", "*");
 | 
			
		||||
@@ -254,10 +290,12 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
 | 
			
		||||
            date.setSeconds(date.getSeconds() + 5);
 | 
			
		||||
            var now = new Date();
 | 
			
		||||
            var retry_in = (date.getTime() - now.getTime()) / 1000;
 | 
			
		||||
            if(retry_in > 0) {
 | 
			
		||||
                res.header({'Retry-After': retry_in});
 | 
			
		||||
                res.sendStatus(429);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) {
 | 
			
		||||
            if(!exists) {
 | 
			
		||||
@@ -338,10 +376,12 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
 | 
			
		||||
            date.setSeconds(date.getSeconds() + 5);
 | 
			
		||||
            var now = new Date();
 | 
			
		||||
            var retry_in = (date.getTime() - now.getTime()) / 1000;
 | 
			
		||||
            if(retry_in > 0) {
 | 
			
		||||
                res.header({'Retry-After': retry_in});
 | 
			
		||||
                res.sendStatus(429);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        validateLogin(adminpass, userpass, channel_name, "add", res, function(exists) {
 | 
			
		||||
            db.collection(channel_name).find({id: video_id}, function(err, result) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user