mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Fixed api-issues
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
// Asks server where in the song it should be
|
||||
'pos', {
|
||||
channel: channel_name,
|
||||
pass: cBase64(hannel_pass)
|
||||
pass: Base64(hannel_pass)
|
||||
}
|
||||
|
||||
// Tells the server the client wants the list
|
||||
|
||||
@@ -163,7 +163,7 @@ function hash_pass(adminpass, hex) {
|
||||
|
||||
function setSessionAdminPass(id, adminpass, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ function setSessionAdminPass(id, adminpass, list, callback) {
|
||||
|
||||
function setSessionChatPass(id, name, pass, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ function setSessionChatPass(id, name, pass, callback) {
|
||||
|
||||
function getSessionChatPass(id, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ function getSessionChatPass(id, callback) {
|
||||
|
||||
function setSessionUserPass(id, userpass, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ function setSessionUserPass(id, userpass, list, callback) {
|
||||
|
||||
function getSessionAdminUser(id, list, callback) {
|
||||
try {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ function getSessionAdminUser(id, list, callback) {
|
||||
}
|
||||
|
||||
function removeSessionChatPass(id, callback) {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ function removeSessionChatPass(id, callback) {
|
||||
|
||||
|
||||
function removeSessionAdminPass(id, channel, callback) {
|
||||
if(id == "empty") {
|
||||
if(id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,12 @@ var error = {
|
||||
success: false,
|
||||
results: [],
|
||||
},
|
||||
wrong_token: {
|
||||
status: 403,
|
||||
error: "You're using a faulty token. Try getting a new token, or send the request without the token.",
|
||||
success: false,
|
||||
results: [],
|
||||
},
|
||||
tooMany: {
|
||||
status: 429,
|
||||
error: "You're doing too many requests, check header-field Retry-After for the wait-time left.",
|
||||
@@ -186,10 +192,10 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
|
||||
checkTimeout(guid, res, authorized, "DELETE", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
validateLogin(adminpass, userpass, channel_name, "delete", res, function(exists) {
|
||||
if(!exists) {
|
||||
res.status(404).send(JSON.stringify(error.not_found.list));
|
||||
@@ -227,6 +233,7 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -336,10 +343,10 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
|
||||
checkTimeout(guid, res, authorized, "CONFIG", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "CONFIG", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
validateLogin(adminpass, userpass, channel_name, "config", res, function(exists, conf) {
|
||||
if(!exists && conf.length == 0) {
|
||||
res.status(404).send(JSON.stringify(error.not_found.list));
|
||||
@@ -395,6 +402,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -458,10 +466,10 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
|
||||
checkTimeout(guid, res, authorized, "PUT", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "PUT", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) {
|
||||
if(!exists) {
|
||||
res.status(404).send(JSON.stringify(error.not_found.list));
|
||||
@@ -494,6 +502,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -504,7 +513,6 @@ router.route('/api/list/:channel_name/__np__').post(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"});
|
||||
|
||||
try {
|
||||
if(!req.body.hasOwnProperty('userpass')) {
|
||||
throw "Wrong format";
|
||||
@@ -548,10 +556,10 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
|
||||
checkTimeout(guid, res, authorized, "POST", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "POST", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
db.collection(channel_name).find({now_playing: true}, toShowChannel, function(err, list) {
|
||||
if(list.length > 0) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
@@ -569,12 +577,15 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
|
||||
var to_return = error.no_error;
|
||||
to_return.results = list;
|
||||
res.status(200).send(JSON.stringify(to_return));
|
||||
return;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.status(404).send(JSON.stringify(error.not_found.list));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -668,10 +679,10 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
checkTimeout(guid, res, authorized, "POST", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "POST", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
var type = fetch_only ? "fetch_song" : "add";
|
||||
validateLogin(adminpass, userpass, channel_name, type, res, function(exists, conf, authenticated) {
|
||||
db.collection(channel_name).find({id: video_id}, function(err, result) {
|
||||
@@ -747,6 +758,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -892,10 +904,10 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
|
||||
checkTimeout(guid, res, authorized, "POST", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, toShowConfig, function(err, docs) {
|
||||
if(docs.length > 0 && docs[0].userpass == userpass) {
|
||||
var conf = docs[0];
|
||||
@@ -925,6 +937,7 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1010,10 +1023,10 @@ router.route('/api/list/:channel_name').post(function(req, res) {
|
||||
checkTimeout(guid, res, authorized, "POST", function() {
|
||||
if(token != "" && !authorized) {
|
||||
updateTimeout(guid, res, authorized, "POST", function(err, docs) {
|
||||
res.status(403).send(JSON.stringify(error.not_authenticated));
|
||||
res.status(403).send(JSON.stringify(error.wrong_token));
|
||||
return;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
db.collection(channel_name).find({views: {$exists: false}}, toShowChannel, function(err, list) {
|
||||
if(list.length > 0) {
|
||||
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
|
||||
@@ -1039,6 +1052,7 @@ router.route('/api/list/:channel_name').post(function(req, res) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user