mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Updating lists when rules/description and thumbnail is updated
This commit is contained in:
		@@ -8,6 +8,7 @@ var token_db = mongojs("tokens");
 | 
			
		||||
var uniqid = require('uniqid');
 | 
			
		||||
var crypto = require('crypto');
 | 
			
		||||
var ObjectId = mongojs.ObjectId;
 | 
			
		||||
var sIO = require(path.join(__dirname, '../../apps/client.js')).socketIO;
 | 
			
		||||
 | 
			
		||||
router.use(function(req, res, next) {
 | 
			
		||||
    next(); // make sure we go to the next routes and don't stop here
 | 
			
		||||
@@ -61,11 +62,17 @@ router.route('/api/approve_thumbnail').post(function(req, res){
 | 
			
		||||
         db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
 | 
			
		||||
            db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
 | 
			
		||||
               db.collection("suggested_thumbnails").remove({channel: channel}, function(err, docs){
 | 
			
		||||
                  db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
                     if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
                     if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
                     else docs[0].userpass = false;
 | 
			
		||||
                     sIO.to(channel).emit("conf", docs);
 | 
			
		||||
                     res.send(true);
 | 
			
		||||
                  });
 | 
			
		||||
               });
 | 
			
		||||
            });
 | 
			
		||||
         });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -90,10 +97,16 @@ router.route('/api/approve_rules').post(function(req, res){
 | 
			
		||||
         var rules = docs[0].rules;
 | 
			
		||||
         db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: rules}}, {upsert: true}, function(err, docs){
 | 
			
		||||
            db.collection("suggested_rules").remove({channel: channel}, function(err, docs){
 | 
			
		||||
               db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
                   if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
                   if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
                   else docs[0].userpass = false;
 | 
			
		||||
                   sIO.to(channel).emit("conf", docs);
 | 
			
		||||
                   res.send(true);
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
         });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -114,8 +127,14 @@ router.route('/api/remove_rules').post(function(req, res){
 | 
			
		||||
   if(req.isAuthenticated()){
 | 
			
		||||
      var channel = req.body.channel;
 | 
			
		||||
      db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: ""}}, function(err, docs){
 | 
			
		||||
        db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
            if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
            if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
            else docs[0].userpass = false;
 | 
			
		||||
            sIO.to(channel).emit("conf", docs);
 | 
			
		||||
            res.send(true);
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -129,11 +148,17 @@ router.route('/api/approve_description').post(function(req, res){
 | 
			
		||||
         db.collection("frontpage_lists").update({_id: channel}, {$set:{description: description}}, {upsert: true}, function(err, docs){
 | 
			
		||||
           db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: description}}, function(err, docs){
 | 
			
		||||
             db.collection("suggested_descriptions").remove({channel: channel}, function(err, docs){
 | 
			
		||||
                db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
                   if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
                   if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
                   else docs[0].userpass = false;
 | 
			
		||||
                   sIO.to(channel).emit("conf", docs);
 | 
			
		||||
                   res.send(true);
 | 
			
		||||
                });
 | 
			
		||||
              });
 | 
			
		||||
            });
 | 
			
		||||
          });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -155,9 +180,15 @@ router.route('/api/remove_thumbnail').post(function(req, res){
 | 
			
		||||
      var channel = req.body.channel;
 | 
			
		||||
      db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: ""}}, function(err, docs){
 | 
			
		||||
         db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: ""}}, function(err, docs){
 | 
			
		||||
            db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
                if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
                if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
                else docs[0].userpass = false;
 | 
			
		||||
                sIO.to(channel).emit("conf", docs);
 | 
			
		||||
                res.send(true);
 | 
			
		||||
             });
 | 
			
		||||
         });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -168,9 +199,15 @@ router.route('/api/remove_description').post(function(req, res){
 | 
			
		||||
      var channel = req.body.channel;
 | 
			
		||||
      db.collection("frontpage_lists").update({_id: channel}, {$set:{description: ""}}, function(err, docs){
 | 
			
		||||
         db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: ""}}, function(err, docs){
 | 
			
		||||
            db.collection(channel + "_settings").find(function(err, docs) {
 | 
			
		||||
                if(docs[0].adminpass !== "") docs[0].adminpass = true;
 | 
			
		||||
                if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
 | 
			
		||||
                else docs[0].userpass = false;
 | 
			
		||||
                sIO.to(channel).emit("conf", docs);
 | 
			
		||||
                res.send(true);
 | 
			
		||||
             });
 | 
			
		||||
         });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
@@ -287,10 +324,12 @@ router.route('/api/delete').post(function(req, res){
 | 
			
		||||
   if(req.isAuthenticated()){
 | 
			
		||||
      var list = req.body._id;
 | 
			
		||||
      db.collection(list).drop(function(err, docs){
 | 
			
		||||
         db.collection(list + "_settings").drop(function(err, docs){
 | 
			
		||||
            db.collection("frontpage_lists").remove({_id: list}, function(err, docs){
 | 
			
		||||
               res.send(true);
 | 
			
		||||
            })
 | 
			
		||||
         });
 | 
			
		||||
      });
 | 
			
		||||
   } else {
 | 
			
		||||
      res.send(false);
 | 
			
		||||
   }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user