.
This commit is contained in:
@ -84,23 +84,15 @@ router.get(/^\/api\/p\/([0-9]+)/, async (req, res) => { // legacy
|
||||
router.get(/^\/api\/item\/[0-9]+$/, async (req, res) => {
|
||||
try {
|
||||
const rows = await sql.query(queries.item, Array(3).fill(req.url.split[2]));
|
||||
const data = rows[0].length > 0 ? {
|
||||
...rows[0][0], ...{
|
||||
thumb: `${cfg.main.url}/t/${rows[0][0].id}.png`,
|
||||
srchost: parse(rows[0][0].src).hostname,
|
||||
next: rows[1].length ? rows[1][0].id : null,
|
||||
prev: rows[2].length ? rows[2][0].id : null,
|
||||
}
|
||||
} : {
|
||||
error: true
|
||||
};
|
||||
res
|
||||
.writeHead(200, { "Content-Type": "application/json" })
|
||||
.end(JSON.stringify(data), "utf-8");
|
||||
res.reply({
|
||||
type: "application/json",
|
||||
body: JSON.stringify(rows?.shift() || [])
|
||||
});
|
||||
} catch(err) {
|
||||
res
|
||||
.writeHead(500)
|
||||
.end(JSON.stringify(err), "utf-8");
|
||||
res.reply({
|
||||
code: 500,
|
||||
body: JSON.stringify(err)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -109,13 +101,14 @@ router.get(/^\/api\/user\/.*(\/[0-9]+)?$/, async (req, res) => { // auf qs umste
|
||||
const eps = Math.min(req.url.split[3] || 50, 50);
|
||||
try {
|
||||
const rows = await sql.query(queries.user, [ user, eps ]);
|
||||
res
|
||||
.writeHead(200, { "Content-Type": "application/json" })
|
||||
.end(JSON.stringify(rows.length > 0 ? rows : []), "utf-8");
|
||||
res.reply({
|
||||
type: "application/json",
|
||||
body: JSON.stringify(rows.length > 0 ? rows : [])
|
||||
});
|
||||
} catch(err) {
|
||||
res
|
||||
.writeHead(500)
|
||||
.end(JSON.stringify(err), "utf-8");
|
||||
res.reply({
|
||||
code: 500,
|
||||
body: JSON.stringify(err)
|
||||
});
|
||||
}
|
||||
db.end();
|
||||
});
|
||||
|
@ -9,9 +9,10 @@ export const queries = {
|
||||
main: "select id, mime, size, username, userchannel, usernetwork, stamp, dest, src from items ",
|
||||
where: where => `${where?`where ${where}`:""} order by rand() limit 1`
|
||||
},
|
||||
item: "select id, mime, dest, size, src, stamp, userchannel, username, usernetwork from items where id = ? limit 1;"
|
||||
+ "select id from items where id = (select min(id) from items where id > ?);"
|
||||
+ "select id from items where id = (select max(id) from items where id < ?)",
|
||||
item: "select id, mime, dest, size, src, stamp, userchannel, username, usernetwork, "
|
||||
+ "(select id from items where id = (select min(id) from items where id > ?)) as next, "
|
||||
+ "(select id from items where id = (select max(id) from items where id < ?)) as prev "
|
||||
+ "from items where items.id = ? limit 1",
|
||||
p: (trend, order) => `select id, mime from items where id ${trend} ? order by id ${order} limit ?`,
|
||||
user: "select id, mime, size, src, stamp, userchannel, username, usernetwork from items where username = ? limit ?"
|
||||
};
|
||||
|
Reference in New Issue
Block a user