mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +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:
57
server/handlers/aggregates.js
Normal file
57
server/handlers/aggregates.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
var toShowConfig = {
|
||||||
|
"addsongs": true,
|
||||||
|
"adminpass": 1,
|
||||||
|
"allvideos": 1,
|
||||||
|
"frontpage": 1,
|
||||||
|
"longsongs": 1,
|
||||||
|
"removeplay": 1,
|
||||||
|
"shuffle": 1,
|
||||||
|
"skip": 1,
|
||||||
|
"startTime": 1,
|
||||||
|
"userpass": 1,
|
||||||
|
"vote": 1,
|
||||||
|
"toggleChat": { $ifNull: [ "$toggleChat", true ] },
|
||||||
|
"description": { $ifNull: [ "$description", "" ] },
|
||||||
|
"thumbnail": { $ifNull: [ "$thumbnail", "" ] },
|
||||||
|
"rules": { $ifNull: [ "$rules", "" ] },
|
||||||
|
"_id": 0
|
||||||
|
};
|
||||||
|
|
||||||
|
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 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,
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.project_object = project_object;
|
||||||
|
module.exports.toShowConfig = toShowConfig;
|
||||||
|
module.exports.toShowChannel = toShowChannel;
|
||||||
@@ -2,6 +2,7 @@ var ColorThief = require('color-thief-jimp');
|
|||||||
var Jimp = require('jimp');
|
var Jimp = require('jimp');
|
||||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||||
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
|
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
|
||||||
|
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var Filter = require('bad-words');
|
var Filter = require('bad-words');
|
||||||
var filter = new Filter({ placeHolder: 'x'});
|
var filter = new Filter({ placeHolder: 'x'});
|
||||||
@@ -98,7 +99,7 @@ function list(msg, guid, coll, offline, socket) {
|
|||||||
} else {
|
} else {
|
||||||
db.createCollection(coll, function(err, docs){
|
db.createCollection(coll, function(err, docs){
|
||||||
db.collection(coll).createIndex({ id: 1}, {unique: true}, function(e, d) {
|
db.collection(coll).createIndex({ id: 1}, {unique: true}, function(e, d) {
|
||||||
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "description": "", "thumbnail": "", "rules": "", userpass: "", id: "config"};
|
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "description": "", "thumbnail": "", "rules": "", userpass: "", id: "config", "toggleChat": true};
|
||||||
db.collection(coll + "_settings").insert(configs, function(err, docs){
|
db.collection(coll + "_settings").insert(configs, function(err, docs){
|
||||||
socket.join(coll);
|
socket.join(coll);
|
||||||
send_list(coll, socket, true, false, true);
|
send_list(coll, socket, true, false, true);
|
||||||
@@ -421,38 +422,29 @@ function change_song_post(coll, next_song, conf, callback, socket) {
|
|||||||
function send_list(coll, socket, send, list_send, configs, shuffled)
|
function send_list(coll, socket, send, list_send, configs, shuffled)
|
||||||
{
|
{
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
db.collection(coll + "_settings").find({id: "config"}, function(err, _conf){
|
db.collection(coll + "_settings").aggregate([
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
id: "config"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$project": projects.toShowConfig
|
||||||
|
},
|
||||||
|
], function(err, _conf){
|
||||||
var conf = _conf;
|
var conf = _conf;
|
||||||
if(conf.length == 0) {
|
if(conf.length == 0) {
|
||||||
var conf = {"id": "config", "addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": "", userpass: ""};
|
var conf = {"id": "config", "addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "description": "", "thumbnail": "", "rules": "", "toggleChat": true, userpass: ""};
|
||||||
db.collection(coll + "_settings").update({id: "config"}, conf, {upsert: true}, function(err, docs) {
|
db.collection(coll + "_settings").update({id: "config"}, conf, {upsert: true}, function(err, docs) {
|
||||||
send_list(coll, socket, send, list_send, configs, shuffled);
|
send_list(coll, socket, send, list_send, configs, shuffled);
|
||||||
});
|
});
|
||||||
} else {
|
} 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(coll).aggregate([
|
db.collection(coll).aggregate([
|
||||||
{
|
{
|
||||||
"$match": {type: {$ne: "suggested"}}
|
"$match": {type: {$ne: "suggested"}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$project": project_object
|
"$project": projects.project_object
|
||||||
},
|
},
|
||||||
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
||||||
], function(err, docs)
|
], function(err, docs)
|
||||||
|
|||||||
@@ -230,7 +230,16 @@ function conf_function(params, coll, guid, offline, socket) {
|
|||||||
$set:obj
|
$set:obj
|
||||||
}, function(err, docs){
|
}, function(err, docs){
|
||||||
Functions.setSessionUserPass(Functions.getSession(socket), obj["userpass"], coll, function() {
|
Functions.setSessionUserPass(Functions.getSession(socket), obj["userpass"], coll, function() {
|
||||||
db.collection(coll + "_settings").find(function(err, docs){
|
db.collection(coll + "_settings").aggregate([
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
id: "config"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$project": projects.toShowConfig
|
||||||
|
},
|
||||||
|
], function(err, docs){
|
||||||
if(docs[0].adminpass !== "") docs[0].adminpass = true;
|
if(docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var uniqid = require('uniqid');
|
|||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var ObjectId = mongojs.ObjectId;
|
var ObjectId = mongojs.ObjectId;
|
||||||
var sIO = require(path.join(__dirname, '../../apps/client.js')).socketIO;
|
var sIO = require(path.join(__dirname, '../../apps/client.js')).socketIO;
|
||||||
|
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||||
|
|
||||||
router.use(function(req, res, next) {
|
router.use(function(req, res, next) {
|
||||||
next(); // make sure we go to the next routes and don't stop here
|
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("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(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("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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
@@ -97,7 +107,16 @@ router.route('/api/approve_rules').post(function(req, res){
|
|||||||
var rules = docs[0].rules;
|
var rules = docs[0].rules;
|
||||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: rules}}, {upsert: true}, function(err, docs){
|
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("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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
@@ -127,7 +146,16 @@ router.route('/api/remove_rules').post(function(req, res){
|
|||||||
if(req.isAuthenticated()){
|
if(req.isAuthenticated()){
|
||||||
var channel = req.body.channel;
|
var channel = req.body.channel;
|
||||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: ""}}, function(err, docs){
|
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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
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("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(channel + "_settings").update({views:{$exists:true}}, {$set:{description: description}}, function(err, docs){
|
||||||
db.collection("suggested_descriptions").remove({channel: channel}, 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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
@@ -180,7 +217,16 @@ router.route('/api/remove_thumbnail').post(function(req, res){
|
|||||||
var channel = req.body.channel;
|
var channel = req.body.channel;
|
||||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: ""}}, function(err, docs){
|
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").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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
@@ -199,7 +245,16 @@ router.route('/api/remove_description').post(function(req, res){
|
|||||||
var channel = req.body.channel;
|
var channel = req.body.channel;
|
||||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{description: ""}}, function(err, docs){
|
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").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].adminpass !== "") docs[0].adminpass = true;
|
||||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||||
else docs[0].userpass = false;
|
else docs[0].userpass = false;
|
||||||
|
|||||||
@@ -14,60 +14,7 @@ var Search = require(pathThumbnails + '/handlers/search.js');
|
|||||||
var uniqid = require('uniqid');
|
var uniqid = require('uniqid');
|
||||||
var Filter = require('bad-words');
|
var Filter = require('bad-words');
|
||||||
var filter = new Filter({ placeHolder: 'x'});
|
var filter = new Filter({ placeHolder: 'x'});
|
||||||
|
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||||
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 error = {
|
var error = {
|
||||||
not_found: {
|
not_found: {
|
||||||
@@ -610,7 +557,7 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
} else {
|
} 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) {
|
if(list.length > 0) {
|
||||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||||
if(authorized) {
|
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-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
res.header({"Content-Type": "application/json"});
|
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);
|
var channel_name = cleanChannelName(req.params.channel_name);
|
||||||
db.collection(channel_name).aggregate([
|
db.collection(channel_name).aggregate([
|
||||||
{
|
{
|
||||||
"$match": { }
|
"$match": { }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$project": project_object
|
"$project": projects.project_object
|
||||||
},
|
},
|
||||||
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
||||||
], function(err, docs) {
|
], 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) {
|
if(docs.length > 0) {
|
||||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||||
if(conf.length == 0) {
|
if(conf.length == 0) {
|
||||||
@@ -906,7 +835,7 @@ router.route('/api/list/:channel_name/:video_id').get(function(req, res) {
|
|||||||
if(video_id == "__np__") {
|
if(video_id == "__np__") {
|
||||||
searchQuery = {now_playing: true};
|
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) {
|
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||||
if(conf.length == 0) {
|
if(conf.length == 0) {
|
||||||
res.status(404).send(error.not_found.list);
|
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) {
|
], function(err, docs) {
|
||||||
if(docs.length > 0 && (docs[0].userpass == "" || docs[0].userpass == undefined)) {
|
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) {
|
], function(err, docs) {
|
||||||
if(docs.length > 0 && docs[0].userpass == userpass) {
|
if(docs.length > 0 && docs[0].userpass == userpass) {
|
||||||
@@ -1164,32 +1093,14 @@ router.route('/api/list/:channel_name').post(function(req, res) {
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
} else {
|
} 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([
|
db.collection(channel_name).aggregate([
|
||||||
{
|
{
|
||||||
"$match": { }
|
"$match": { }
|
||||||
},
|
},
|
||||||
{ "$project": project_object },
|
{ "$project": projects.project_object },
|
||||||
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
{ "$sort" : { "now_playing" : -1, "votes": -1, "added": 1 } }
|
||||||
], function(err, list) {
|
], 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) {
|
if(list.length > 0) {
|
||||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||||
if(conf.length == 0) {
|
if(conf.length == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user