mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Added a own aggregates file
- Aggregate and project missing fields - Updated how channels are created, to add the new fields
This commit is contained in:
@@ -9,6 +9,7 @@ var uniqid = require('uniqid');
|
||||
var crypto = require('crypto');
|
||||
var ObjectId = mongojs.ObjectId;
|
||||
var sIO = require(path.join(__dirname, '../../apps/client.js')).socketIO;
|
||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||
|
||||
router.use(function(req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
@@ -62,7 +63,16 @@ 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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
@@ -97,7 +107,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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
@@ -127,7 +146,16 @@ 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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
@@ -148,7 +176,16 @@ 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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
@@ -180,7 +217,16 @@ 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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
@@ -199,7 +245,16 @@ 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) {
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
{
|
||||
"$match": {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], 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;
|
||||
|
||||
@@ -14,60 +14,7 @@ var Search = require(pathThumbnails + '/handlers/search.js');
|
||||
var uniqid = require('uniqid');
|
||||
var Filter = require('bad-words');
|
||||
var filter = new Filter({ placeHolder: 'x'});
|
||||
|
||||
var toShowChannel = {
|
||||
start: 1,
|
||||
end: 1,
|
||||
added: 1,
|
||||
id: 1,
|
||||
title: 1,
|
||||
votes: 1,
|
||||
duration: 1,
|
||||
type: 1,
|
||||
_id: 0,
|
||||
now_playing: 1,
|
||||
type: 1,
|
||||
source: 1,
|
||||
thumbnail: 1,
|
||||
};
|
||||
|
||||
var project_object = {
|
||||
"_id": 0,
|
||||
"id": 1,
|
||||
"added": 1,
|
||||
"now_playing": 1,
|
||||
"title": 1,
|
||||
"votes": 1,
|
||||
"start": 1,
|
||||
"duration": 1,
|
||||
"end": 1,
|
||||
"type": 1,
|
||||
"source": { $ifNull: [ "$source", "youtube" ] },
|
||||
"thumbnail": {
|
||||
$ifNull: [ "$thumbnail", {
|
||||
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
|
||||
} ]
|
||||
}
|
||||
};
|
||||
|
||||
var toShowConfig = {
|
||||
addsongs: 1,
|
||||
adminpass: 1,
|
||||
allvideos: 1,
|
||||
frontpage: 1,
|
||||
longsongs: 1,
|
||||
removeplay: 1,
|
||||
shuffle: 1,
|
||||
skip: 1,
|
||||
startTime: 1,
|
||||
userpass: 1,
|
||||
vote: 1,
|
||||
toggleChat: 1,
|
||||
description: { $ifNull: [ "$description", "" ] },
|
||||
thumbnail: { $ifNull: [ "$thumbnail", "" ] },
|
||||
rules: { $ifNull: [ "$rules", "" ] },
|
||||
_id: 0
|
||||
};
|
||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||
|
||||
var error = {
|
||||
not_found: {
|
||||
@@ -610,7 +557,7 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
db.collection(channel_name).find({now_playing: true}, toShowChannel, function(err, list) {
|
||||
db.collection(channel_name).find({now_playing: true}, projects.toShowChannel, function(err, list) {
|
||||
if(list.length > 0) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
if(authorized) {
|
||||
@@ -847,35 +794,17 @@ router.route('/api/list/:channel_name').get(function(req, res) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
res.header({"Content-Type": "application/json"});
|
||||
var project_object = {
|
||||
"_id": 0,
|
||||
"id": 1,
|
||||
"added": 1,
|
||||
"now_playing": 1,
|
||||
"title": 1,
|
||||
"votes": 1,
|
||||
"start": 1,
|
||||
"duration": 1,
|
||||
"end": 1,
|
||||
"type": 1,
|
||||
"source": { $ifNull: [ "$source", "youtube" ] },
|
||||
"thumbnail": {
|
||||
$ifNull: [ "$thumbnail", {
|
||||
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
|
||||
} ]
|
||||
}
|
||||
};
|
||||
var channel_name = cleanChannelName(req.params.channel_name);
|
||||
db.collection(channel_name).aggregate([
|
||||
{
|
||||
"$match": { }
|
||||
},
|
||||
{
|
||||
"$project": project_object
|
||||
"$project": projects.project_object
|
||||
},
|
||||
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
||||
], function(err, docs) {
|
||||
//db.collection(channel_name).find({views: {$exists: false}}, toShowChannel, function(err, docs) {
|
||||
//db.collection(channel_name).find({views: {$exists: false}}, projects.toShowChannel, function(err, docs) {
|
||||
if(docs.length > 0) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
if(conf.length == 0) {
|
||||
@@ -906,7 +835,7 @@ router.route('/api/list/:channel_name/:video_id').get(function(req, res) {
|
||||
if(video_id == "__np__") {
|
||||
searchQuery = {now_playing: true};
|
||||
}
|
||||
db.collection(channel_name).find(searchQuery, toShowChannel, function(err, docs) {
|
||||
db.collection(channel_name).find(searchQuery, projects.toShowChannel, function(err, docs) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
if(conf.length == 0) {
|
||||
res.status(404).send(error.not_found.list);
|
||||
@@ -946,7 +875,7 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": toShowConfig
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
if(docs.length > 0 && (docs[0].userpass == "" || docs[0].userpass == undefined)) {
|
||||
@@ -1038,7 +967,7 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": toShowConfig
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
if(docs.length > 0 && docs[0].userpass == userpass) {
|
||||
@@ -1164,32 +1093,14 @@ router.route('/api/list/:channel_name').post(function(req, res) {
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
var project_object = {
|
||||
"_id": 0,
|
||||
"id": 1,
|
||||
"added": 1,
|
||||
"now_playing": 1,
|
||||
"title": 1,
|
||||
"votes": 1,
|
||||
"start": 1,
|
||||
"duration": 1,
|
||||
"end": 1,
|
||||
"type": 1,
|
||||
"source": { $ifNull: [ "$source", "youtube" ] },
|
||||
"thumbnail": {
|
||||
$ifNull: [ "$thumbnail", {
|
||||
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
|
||||
} ]
|
||||
}
|
||||
};
|
||||
db.collection(channel_name).aggregate([
|
||||
{
|
||||
"$match": { }
|
||||
},
|
||||
{ "$project": project_object },
|
||||
{ "$project": projects.project_object },
|
||||
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
||||
], function(err, list) {
|
||||
//db.collection(channel_name).find({views: {$exists: false}}, toShowChannel, function(err, list) {
|
||||
//db.collection(channel_name).find({views: {$exists: false}}, projects.toShowChannel, function(err, list) {
|
||||
if(list.length > 0) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
if(conf.length == 0) {
|
||||
|
||||
Reference in New Issue
Block a user