From 1e00cbb9e7302efd62507de3bcaec832c23f6d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Fri, 2 Mar 2018 11:35:42 +0100 Subject: [PATCH] README.md update --- server/README.md | 8 ++++---- server/handlers/list.js | 2 +- server/routing/client/api.js | 30 ++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/server/README.md b/server/README.md index 8196f8f4..f4f42b92 100644 --- a/server/README.md +++ b/server/README.md @@ -13,7 +13,7 @@ All requests return things on this form (results field is added if successful.) status: STATUSCODE, error: MESSAGE, success: IF_SUCCESSFULL, - (results: RESULTS) + results: [RESULTS] } ``` @@ -74,14 +74,14 @@ PUT /api/conf/:channel_name { "userpass": USER_PASSWORD, "adminpass": PASSWORD, - "voting": BOOLEAN, + "vote": BOOLEAN, "addsongs": BOOLEAN, "longsongs": BOOLEAN, "frontpage": BOOLEAN (if you want to set userpassword, this MUST be false for it to work), "allvideos": BOOLEAN, "removeplay": BOOLEAN, - "skipping": BOOLEAN, - "shuffling": BOOLEAN, + "skip": BOOLEAN, + "shuffle": BOOLEAN, "userpass_changed": BOOLEAN (this must be true if you want to keep the userpassword you're sending) } diff --git a/server/handlers/list.js b/server/handlers/list.js index f31fd5b6..5b14f1da 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -57,7 +57,7 @@ function list(msg, guid, coll, offline, socket) { }); } else { db.createCollection(coll, function(err, docs){ - 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, "desc": ""}; + 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, "desc": "", userpass: ""}; db.collection(coll + "_settings").insert(configs, function(err, docs){ socket.join(coll); List.send_list(coll, socket, true, false, true); diff --git a/server/routing/client/api.js b/server/routing/client/api.js index 1889e7a5..21ebcdaf 100644 --- a/server/routing/client/api.js +++ b/server/routing/client/api.js @@ -37,42 +37,50 @@ var error = { status: 404, error: "Couldn't find a song like that on YouTube.", success: false, + results: [], }, local: { status: 404, error: "Couldn't find a song like that in the channel", success: false, + results: [], }, list: { status: 404, error: "The list doesn't exist", success: false, + results: [], } }, not_authenticated: { status: 403, error: "Wrong adminpassword or userpassword.", success: false, + results: [], }, formatting: { status: 400, error: "Malformed request parameters.", success: false, + results: [], }, conflicting: { status: 409, error: "That element already exists.", success: false, + results: [], }, tooMany: { status: 429, error: "You're doing too many requests, check header-field Retry-After for the wait-time left.", success: false, + results: [], }, no_error: { status: 200, error: false, success: true, + results: [], } } @@ -201,6 +209,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) { typeof(allvideos) != "boolean" || typeof(removeplay) != "boolean" || typeof(skipping) != "boolean" || typeof(shuffling) != "boolean" || typeof(userpass_changed) != "boolean") { + console.log("crash here"); throw "Wrong format"; } } catch(e) { @@ -253,7 +262,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) { {upsert:true}, function(err, docs){ updateTimeout(guid, res, "CONFIG", function(err, docs) { var to_return = error.no_error; - to_return.results = obj; + to_return.results = [obj]; res.status(200).send(JSON.stringify(to_return)); return; }); @@ -311,7 +320,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) { List.getNextSong(channel_name, function() { updateTimeout(guid, res, "PUT", function(err, docs) { var to_return = error.no_error; - to_return.results = song[0]; + to_return.results = song; res.status(200).send(JSON.stringify(to_return)); return; }); @@ -357,7 +366,9 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) { return; } updateTimeout(guid, res, "POST", function(err, docs) { - res.status(200).send(JSON.stringify(list[0])); + var to_return = error.no_error; + to_return.results = list; + res.status(200).send(JSON.stringify(to_return)); }); }); } else { @@ -471,7 +482,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { }); } else if(fetch_only) { var to_return = error.no_error; - to_return.results = result[0]; + to_return.results = result; res.status(200).send(JSON.stringify(to_return)); return; } else { @@ -531,7 +542,7 @@ router.route('/api/list/:channel_name/:video_id').get(function(req, res) { return; } var to_return = error.no_error; - to_return.results = docs[0]; + to_return.results = docs; res.status(200).send(JSON.stringify(to_return)); return; }); @@ -556,7 +567,7 @@ router.route('/api/conf/:channel_name').get(function(req, res) { } else { conf.adminpass = false; } - if(conf.userpass != "") { + if(conf.userpass != "" && conf.userpass != undefined) { conf.userpass = true; } else { conf.userpass = false; @@ -785,7 +796,10 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) { if(conf.length > 0 && ((conf[0].userpass == undefined || conf[0].userpass == "" || conf[0].userpass == userpass))) { exists = true; } else if(conf.length > 0 && type != "config") { - res.status(404).send(JSON.stringify(error.not_authenticated)); + res.status(404).send(JSON.stringify(error.not_found.list)); + return; + } else if(conf.length == 0) { + res.status(404).send(JSON.stringify(error.not_found.list)); return; } @@ -813,7 +827,7 @@ function postEnd(channel_name, configs, new_song, guid, res, authenticated) { List.getNextSong(channel_name, function() { updateTimeout(guid, res, "POST", function(err, docs) { var to_return = error.no_error; - to_return.results = new_song; + to_return.results = [new_song]; res.status(authenticated ? 200 : 403).send(JSON.stringify(to_return)); return; });