pagination

This commit is contained in:
Flummi 2017-01-13 23:38:11 +01:00
parent a153b81ce0
commit 1b8679b2ba

View File

@ -244,10 +244,30 @@ function Websrv(tlib) {
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.toString()}), 'utf-8');
res.end(JSON.stringify({'latest': rows[0].stamp}), 'utf-8');
});
}
else if(url[2] == "p" && Number.isInteger(parseInt(url[3]))) { // pagination
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": [],
"latest": stamp
};
rows.forEach(e => {
items.items.push({
id: e.id,
mime: e.mime
});
items.latest = e.id;
});
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 id = url[3];
lib.sql.query("select * from `f0ck`.`items` where `id` < ? order by `id` desc limit ?", [id, eps], (err, rows, fields) => {
@ -265,7 +285,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