Merge branch 'f0ckdev' into 'master'

F0ckdev

See merge request !61
This commit is contained in:
noxy 2017-01-23 14:00:00 +00:00
commit d897d0a22f

View File

@ -231,7 +231,7 @@ function Websrv(tlib) {
var query = "select * from `f0ck`.`items`"; var query = "select * from `f0ck`.`items`";
lib.sql.query(query, (err, rows, fields) => { lib.sql.query(query, (err, rows, fields) => {
var items = []; var items = [];
rows.forEach((e,i,a) => { rows.forEach(e => {
items.push({ items.push({
'id': e.id, 'id': e.id,
'mime': e.mime 'mime': e.mime
@ -241,7 +241,34 @@ function Websrv(tlib) {
res.end(JSON.stringify(items), 'utf-8'); res.end(JSON.stringify(items), 'utf-8');
}); });
} }
else if(url[2] == "p" && Number.isInteger(parseInt(url[3]))) { // pagination 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
var eps = 50; var eps = 50;
var id = url[3]; var id = url[3];
lib.sql.query("select * from `f0ck`.`items` where `id` < ? order by `id` desc limit ?", [id, eps], (err, rows, fields) => { lib.sql.query("select * from `f0ck`.`items` where `id` < ? order by `id` desc limit ?", [id, eps], (err, rows, fields) => {
@ -259,7 +286,7 @@ function Websrv(tlib) {
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(JSON.stringify(items), 'utf-8'); res.end(JSON.stringify(items), 'utf-8');
}); });
} }*/
else if(Number.isInteger(parseInt(url[2]))) { // Item else if(Number.isInteger(parseInt(url[2]))) { // Item
var query = "select * from `f0ck`.`items` where `id` = ? limit 1; " // get 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 + "select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); " // get previous item
@ -312,4 +339,4 @@ Websrv.prototype.getTpls = () => {
"how": fs.readFileSync("./s/how.tpl.html", "utf-8"), "how": fs.readFileSync("./s/how.tpl.html", "utf-8"),
"contact": fs.readFileSync("./s/contact.tpl.html", "utf-8") "contact": fs.readFileSync("./s/contact.tpl.html", "utf-8")
}; };
}; };