mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Updating to have type always
This commit is contained in:
15
server/apps/addtype.js
Normal file
15
server/apps/addtype.js
Normal file
@@ -0,0 +1,15 @@
|
||||
path = require('path'),
|
||||
pathThumbnails = __dirname;
|
||||
db = require(pathThumbnails + '/../handlers/db.js');
|
||||
|
||||
db.getCollectionNames(function(err, docs) {
|
||||
for(var i = 0; i < docs.length; i++) {
|
||||
addType(docs[i]);
|
||||
}
|
||||
})
|
||||
|
||||
function addType(name) {
|
||||
db.collection(name).update({duration: {$exists: true},type:{$ne:"suggested"}}, {$set: { type: "video" }}, {multi: true}, function(err, doc) {
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
@@ -108,17 +108,16 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
} else {
|
||||
np = false;
|
||||
}
|
||||
db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end)}, {upsert: true}, function(err, docs){
|
||||
if(np)
|
||||
{
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end)};
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video"};
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
db.collection(coll + "_settings").update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}});
|
||||
List.send_play(coll, undefined);
|
||||
Frontpage.update_frontpage(coll, id, title);
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, false);
|
||||
} else {
|
||||
var new_song = {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end)};
|
||||
io.to(coll).emit("channel", {type: "added", value: new_song});
|
||||
if(!full_list) Search.get_correct_info(new_song, coll, true);
|
||||
}
|
||||
@@ -202,21 +201,17 @@ function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(msg.type == "del")
|
||||
ListChange.del(msg, socket, socketid);
|
||||
else
|
||||
{
|
||||
if(msg.type == "del") {
|
||||
ListChange.del(msg, socket, socketid);
|
||||
} else {
|
||||
var id = msg.id;
|
||||
var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass));
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false))
|
||||
{
|
||||
ListChange.vote(coll, id, guid, socket, false, false);
|
||||
}else{
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
});
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false)) {
|
||||
ListChange.vote(coll, id, guid, socket, false, false);
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
@@ -363,7 +358,7 @@ function delete_all(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
|
||||
function vote(coll, id, guid, socket, full_list, last) {
|
||||
db.collection(coll).find({id:id, now_playing: false}, function(err, docs){
|
||||
db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){
|
||||
if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid))
|
||||
{
|
||||
db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs)
|
||||
|
||||
@@ -14,6 +14,7 @@ var toShowChannel = {
|
||||
type: 1,
|
||||
_id: 0,
|
||||
now_playing: 1,
|
||||
type: 1,
|
||||
};
|
||||
var toShowConfig = {
|
||||
addsongs: 1,
|
||||
@@ -241,7 +242,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
db.collection(channel_name).find({id: video_id, now_playing: false}, function(err, song) {
|
||||
db.collection(channel_name).find({id: video_id, now_playing: false, type:"video"}, function(err, song) {
|
||||
if(song.length == 0) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
@@ -251,7 +252,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
|
||||
} else {
|
||||
song[0].votes += 1;
|
||||
song[0].guids.push(guid);
|
||||
db.collection(channel_name).update({id: video_id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, success) {
|
||||
db.collection(channel_name).update({id: video_id}, {$inc:{votes:1}, $set:{added:Functions.get_time(), type: "video"}, $push :{guids: guid}}, function(err, success) {
|
||||
io.to(channel_name).emit("channel", {type: "vote", value: video_id, time: Functions.get_time()});
|
||||
List.getNextSong(channel_name, function() {
|
||||
updateTimeout(guid, res, "PUT", function(err, docs) {
|
||||
@@ -345,26 +346,27 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.log("crash here", e);
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
|
||||
checkTimeout(guid, res, "POST", function() {
|
||||
var type = fetch_only ? "fetch_song" : "add";
|
||||
validateLogin(adminpass, userpass, channel_name, type, res, function(exists) {
|
||||
validateLogin(adminpass, userpass, channel_name, type, res, function(exists, conf, authenticated) {
|
||||
db.collection(channel_name).find({id: video_id}, function(err, result) {
|
||||
if(result.length == 0) {
|
||||
if(fetch_only) {
|
||||
if(result.length == 0 || result[0].type == "suggested") {
|
||||
var song_type = authenticated ? "video" : "suggested";
|
||||
if(fetch_only && result.length == 0) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
db.collection(channel_name).find({now_playing: true}, function(err, now_playing) {
|
||||
var set_np = false;
|
||||
if(now_playing.length == 0) {
|
||||
if(now_playing.length == 0 && authenticated) {
|
||||
set_np = true;
|
||||
}
|
||||
var new_song = {"added": Functions.get_time(),"guids":[guid],"id":video_id,"now_playing":set_np,"title":title,"votes":1, "duration":duration, "start": parseInt(start_time), "end": parseInt(end_time)};
|
||||
var new_song = {"added": Functions.get_time(),"guids":[guid],"id":video_id,"now_playing":set_np,"title":title,"votes":1, "duration":duration, "start": parseInt(start_time), "end": parseInt(end_time), "type": song_type};
|
||||
db.collection("frontpage_lists").find({"_id": channel_name}, function(err, count) {
|
||||
var create_frontpage_lists = false;
|
||||
if(count.length == 0) {
|
||||
@@ -376,9 +378,14 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
io.to(channel_name).emit("conf", configs);
|
||||
});
|
||||
}
|
||||
db.collection(channel_name).insert(new_song, function(err, success) {
|
||||
db.collection(channel_name).update(new_song, {upsert: true}, function(err, success) {
|
||||
if(create_frontpage_lists) {
|
||||
db.collection("frontpage_lists").insert({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(err, docs) {
|
||||
db.collection("frontpage_lists").update({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, {upsert: true}, function(err, docs) {
|
||||
if(authenticated) {
|
||||
io.to(channel_name).emit("channel", {type: "added", value: new_song});
|
||||
} else {
|
||||
io.to(coll).emit("suggested", new_song);
|
||||
}
|
||||
postEnd(channel_name, configs, new_song, guid, res);
|
||||
});
|
||||
} else if(set_np) {
|
||||
@@ -712,6 +719,8 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) {
|
||||
(type == "config" && (conf[0].adminpass == "" || conf[0].adminpass == undefined || conf[0].adminpass == adminpass))
|
||||
) {
|
||||
callback(exists, conf);
|
||||
} else if(type == "add") {
|
||||
callback(exists, conf, false);
|
||||
} else {
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user