commit
d897d0a22f
|
@ -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,7 +241,34 @@ function Websrv(tlib) {
|
|||
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 id = url[3];
|
||||
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.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
|
||||
|
@ -312,4 +339,4 @@ Websrv.prototype.getTpls = () => {
|
|||
"how": fs.readFileSync("./s/how.tpl.html", "utf-8"),
|
||||
"contact": fs.readFileSync("./s/contact.tpl.html", "utf-8")
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user