get latest id

This commit is contained in:
Flummi 2017-01-13 23:01:16 +01:00
parent e658e13d6a
commit cc8dc9b37e

View File

@ -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,i,a) => {
rows.forEach(e => {
items.push({
'id': e.id,
'mime': e.mime
@ -241,6 +241,12 @@ function Websrv(tlib) {
res.end(JSON.stringify(items), 'utf-8');
});
}
else if(url[2] == "latest") {
lib.sql.query("select max(stamp) from `f0ck`.`items` limit 1", (err, rows) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({latest: rows[0].id}), 'utf-8');
});
}
else if(url[2] == "p" && Number.isInteger(parseInt(url[3]))) { // pagination
var eps = 50;
var id = url[3];