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