|
|
@ -3,13 +3,14 @@ import { query } from '../../utils/db';
|
|
|
|
|
|
|
|
|
|
|
|
export async function get(req, res) {
|
|
|
|
export async function get(req, res) {
|
|
|
|
if (req.user) {
|
|
|
|
if (req.user) {
|
|
|
|
const offset = req.params.offset || 0;
|
|
|
|
const page_size = 100;
|
|
|
|
|
|
|
|
const offset = req.query.offset ? parseInt(req.query.offset) : 0;
|
|
|
|
const rows = await query(`
|
|
|
|
const rows = await query(`
|
|
|
|
select g.uid, g.name, coalesce(g.updated_at, g.created_at) as updated_at
|
|
|
|
select g.uid, g.name, coalesce(g.updated_at, g.created_at) as updated_at
|
|
|
|
from gists g
|
|
|
|
from gists g
|
|
|
|
where g.user_id = $1
|
|
|
|
where g.user_id = $1
|
|
|
|
order by updated_at desc
|
|
|
|
order by id desc
|
|
|
|
limit 100
|
|
|
|
limit ${page_size + 1}
|
|
|
|
offset $2
|
|
|
|
offset $2
|
|
|
|
`, [req.user.id, offset]);
|
|
|
|
`, [req.user.id, offset]);
|
|
|
|
|
|
|
|
|
|
|
@ -17,7 +18,8 @@ export async function get(req, res) {
|
|
|
|
row.uid = row.uid.replace(/-/g, '');
|
|
|
|
row.uid = row.uid.replace(/-/g, '');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
send(res, 200, rows);
|
|
|
|
const more = rows.length > page_size;
|
|
|
|
|
|
|
|
send(res, 200, { apps: rows.slice(0, page_size), offset: more ? offset + page_size : null });
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send(res, 401);
|
|
|
|
send(res, 401);
|
|
|
|
}
|
|
|
|
}
|
|
|
|