+api, lol
This commit is contained in:
parent
680ef78f07
commit
2f4bfd8269
@ -183,6 +183,44 @@ function Websrv(tbot, tsql, tcfg, tlib) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else if(filePath.match(/^\.\/api/i)) { // api
|
||||
var url = filePath.split('/');
|
||||
if(url[2] === undefined) { // Mainpage
|
||||
res.writeHead(200, { 'Content-Type': contentType });
|
||||
res.end('kommt noch');
|
||||
}
|
||||
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
|
||||
+ "select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?)"; // get next item
|
||||
sql.query(query, [url[2], url[2], url[2]], (err, rows, fields) => {
|
||||
var data;
|
||||
if(rows[0].length) {
|
||||
var e = rows[0][0];
|
||||
data = {
|
||||
id: e.id,
|
||||
username: e.username,
|
||||
src: e.src,
|
||||
dest: e.dest,
|
||||
mime: e.mime,
|
||||
size: e.size,
|
||||
userchannel: e.userchannel,
|
||||
usernetwork: e.usernetwork,
|
||||
next: null,
|
||||
prev: null
|
||||
};
|
||||
if(rows[1].length)
|
||||
data.next = rows[1][0].id;
|
||||
if(rows[2].length)
|
||||
data.prev = rows[2][0].id;
|
||||
}
|
||||
else
|
||||
data = { error: 'nope' };
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
res.end(JSON.stringify(data), 'utf-8');
|
||||
});
|
||||
}
|
||||
}
|
||||
else { // errorpage
|
||||
res.writeHead(404);
|
||||
res.end('404 - f0ck you', 'utf-8');
|
||||
|
Loading…
Reference in New Issue
Block a user