adds prev + next buttons on page

This commit is contained in:
jkhsjdhjs 2016-08-16 19:34:38 +02:00
parent e4481b65cc
commit 0ffff48e32
2 changed files with 15 additions and 4 deletions

View File

@ -19,7 +19,7 @@
<img src="{{ dest }}" style="max-width: 1024px" />
{% endif %}
</div>
<div class="controls">controls f&uuml;r vor und zur&uuml;ck :^)</div><br />
<div class="controls">{% if prev != null %}<a href="/{{ prev }}">Prev</a>{% endif %} {% if next != null %}<a href="/{{ next }}">Next</a>{% endif %}</div><br />
<div class="info">
<span class="src">src: <a href="{{ src }}" target="_blank">{{ src }}</a></span><br />
<span class="dest">dest: {{ dest }}</span><br />

View File

@ -202,7 +202,7 @@ http.createServer((req, res) => {
});
}
else if(Number.isInteger(parseInt(url))) { // itempage
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1; select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?);", [url, url, url], (err, rows, fields) => {
var tpl = swig.compile(templates.item);
var data = {
id: '',
@ -215,7 +215,8 @@ http.createServer((req, res) => {
userchannel: '',
usernetwork: ''
};
rows.forEach((e,i,a) => {
if(rows.length && rows[0].id == parseInt(url)) {
var e = rows[0];
switch(e.mime) {
case "image/png":
case "image/jpeg":
@ -238,7 +239,17 @@ http.createServer((req, res) => {
data.size = formatSize(e.size);
data.userchannel = e.userchannel;
data.usernetwork = e.usernetwork;
});
if(rows.length >= 2)
if(rows[1].id > parseInt(url))
data.next = rows[1].id;
else
data.prev = rows[1].id;
if(rows.length >= 3)
if(rows[2].id > parseInt(url))
data.next = rows[2].id;
else
data.prev = rows[2].id;
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(tpl(data), 'utf-8');
});