diff --git a/src/inc/routeinc/f0cklib.mjs b/src/inc/routeinc/f0cklib.mjs index 3c26ac9..836ecfb 100644 --- a/src/inc/routeinc/f0cklib.mjs +++ b/src/inc/routeinc/f0cklib.mjs @@ -65,7 +65,7 @@ export default { and "user".user ilike ${user} group by "items".id `; - total = total[0].total; + total = total[0]?.total ?? 0; } } diff --git a/src/inc/routes/index.mjs b/src/inc/routes/index.mjs index 6309dad..3be1caa 100644 --- a/src/inc/routes/index.mjs +++ b/src/inc/routes/index.mjs @@ -10,6 +10,53 @@ const auth = async (req, res, next) => { }; export default (router, tpl) => { + router.get(/\/user\/(?.*)/, async (req, res) => { + const user = req.params.user; + + const query = await db` + select "user".user, user_options.* + from user_options + left join "user" on "user".id = user_options.user_id + where "user".user ilike ${user} + limit 1 + `; + + if(!query.length) { + return res.reply({ + code: 404, + body: tpl.render('error', { + message: 'this user does not exists', + tmp: null + }, req) + }); + } + + const f0cks = await f0cklib.getf0cks({ + user: user, + mode: req.session.mode, + fav: false + }); + const favs = await f0cklib.getf0cks({ + user: user, + mode: req.session.mode, + fav: true + }); + + if('items' in f0cks) + f0cks.items = f0cks.items.slice(0, 50); + if('items' in favs) + favs.items = favs.items.slice(0, 50); + + const data = { + user: query[0], + f0cks, + favs, + tmp: null + }; + + return res.reply({ body: tpl.render('user', data, req) }); + }); + router.get(/^\/?(?:\/tag\/(?.+?))?(?:\/user\/(?.+?)\/(?f0cks|favs))?(?:\/(?image|audio|video))?(?:\/p\/(?\d+))?(?:\/(?\d+))?$/, async (req, res) => { const mode = req.params.itemid ? 'item' : 'index'; const data = await (req.params.itemid ? f0cklib.getf0ck : f0cklib.getf0cks)({ @@ -44,7 +91,7 @@ export default (router, tpl) => { const mode = +req.url.split[1]; let referertmp = req.headers.referer; let referer = ""; - + if(referertmp?.match(/f0ck\.me/)) referer = referertmp.split("/").slice(3).join("/"); diff --git a/views/user.html b/views/user.html new file mode 100644 index 0000000..10c2601 --- /dev/null +++ b/views/user.html @@ -0,0 +1,28 @@ +@include(snippets/header) +

{{ user.user }}

+ +

f0cks:

+@if('items' in f0cks) +show all f0cks +
+ @each(f0cks.items as item) +

+ @endeach +
+@else + no f0cks given +@endif + +

favs:

+@if('items' in favs) +show all favs +
+ @each(favs.items as item) +

+ @endeach +
+@else + no favorites +@endif + +@include(snippets/footer) \ No newline at end of file