From f29164d9592927458566e81e1e92cdfc5835c36c Mon Sep 17 00:00:00 2001 From: noxy Date: Mon, 23 Jan 2017 14:04:56 +0000 Subject: [PATCH] Revert "Merge branch 'f0ckdev' into 'master'" This reverts merge request !61 --- src/websrv.js | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/src/websrv.js b/src/websrv.js index 3567df6..2649134 100644 --- a/src/websrv.js +++ b/src/websrv.js @@ -231,7 +231,7 @@ function Websrv(tlib) { var query = "select * from `f0ck`.`items`"; lib.sql.query(query, (err, rows, fields) => { var items = []; - rows.forEach(e => { + rows.forEach((e,i,a) => { items.push({ 'id': e.id, 'mime': e.mime @@ -241,34 +241,7 @@ function Websrv(tlib) { res.end(JSON.stringify(items), 'utf-8'); }); } - else if(url[2] == "latest") { - lib.sql.query("select * from `f0ck`.`items` order by `stamp` desc limit 1", (err, rows) => { - res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(JSON.stringify({'latest': rows[0].stamp}), 'utf-8'); - }); - } - else if(url[2] == "p" && Number.isInteger(parseInt(url[3])) && Number.isInteger(parseInt(url[4]))) { // pagination - // /api/p/stamp/eps - var eps = parseInt(url[4]); - var stamp = parseInt(url[3]); - lib.sql.query("select * from `f0ck`.`items` where `stamp` < ? order by `stamp` desc limit ?", [stamp, eps], (err, rows) => { - var items = { - "items": [], - "first": stamp, - "latest": 0 - }; - rows.forEach(e => { - items.items.push({ - id: e.id, - mime: e.mime - }); - items.latest = e.stamp; - }); - res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(JSON.stringify(items), 'utf-8'); - }); - } - /*else if(url[2] == "p" && Number.isInteger(parseInt(url[3]))) { // pagination + else if(url[2] == "p" && Number.isInteger(parseInt(url[3]))) { // pagination var eps = 50; var id = url[3]; lib.sql.query("select * from `f0ck`.`items` where `id` < ? order by `id` desc limit ?", [id, eps], (err, rows, fields) => { @@ -286,7 +259,7 @@ function Websrv(tlib) { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(JSON.stringify(items), 'utf-8'); }); - }*/ + } else if(Number.isInteger(parseInt(url[2]))) { // Item var query = "select * from `f0ck`.`items` where `id` = ? limit 1; " // get item + "select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); " // get previous item @@ -339,4 +312,4 @@ Websrv.prototype.getTpls = () => { "how": fs.readFileSync("./s/how.tpl.html", "utf-8"), "contact": fs.readFileSync("./s/contact.tpl.html", "utf-8") }; -}; +}; \ No newline at end of file