userprofiles test
This commit is contained in:
parent
ba821b81fa
commit
f57a8b4320
|
@ -65,7 +65,7 @@ export default {
|
|||
and "user".user ilike ${user}
|
||||
group by "items".id
|
||||
`;
|
||||
total = total[0].total;
|
||||
total = total[0]?.total ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,53 @@ const auth = async (req, res, next) => {
|
|||
};
|
||||
|
||||
export default (router, tpl) => {
|
||||
router.get(/\/user\/(?<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\/(?<tag>.+?))?(?:\/user\/(?<user>.+?)\/(?<mode>f0cks|favs))?(?:\/(?<mime>image|audio|video))?(?:\/p\/(?<page>\d+))?(?:\/(?<itemid>\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("/");
|
||||
|
||||
|
|
28
views/user.html
Normal file
28
views/user.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
@include(snippets/header)
|
||||
<h1>{{ user.user }}</h1>
|
||||
|
||||
<h2>f0cks:</h2>
|
||||
@if('items' in f0cks)
|
||||
<a href="{{ f0cks.link.main }}">show all f0cks</a>
|
||||
<div id="posts">
|
||||
@each(f0cks.items as item)
|
||||
<a href="{{ f0cks.link.main }}{{ item.id }}" data-mime="{{ item.mime }}" data-mode="{{ item.tag_id ? ['','sfw','nsfw'][item.tag_id] : 'null' }}" style="background-image: url('/t/{{ item.id }}.webp')"><p></p></a>
|
||||
@endeach
|
||||
</div>
|
||||
@else
|
||||
no f0cks given
|
||||
@endif
|
||||
|
||||
<h2>favs:</h2>
|
||||
@if('items' in favs)
|
||||
<a href="{{ favs.link.main }}">show all favs</a>
|
||||
<div id="posts">
|
||||
@each(favs.items as item)
|
||||
<a href="{{ favs.link.main }}{{ item.id }}" data-mime="{{ item.mime }}" data-mode="{{ item.tag_id ? ['','sfw','nsfw'][item.tag_id] : 'null' }}" style="background-image: url('/t/{{ item.id }}.webp')"><p></p></a>
|
||||
@endeach
|
||||
</div>
|
||||
@else
|
||||
no favorites
|
||||
@endif
|
||||
|
||||
@include(snippets/footer)
|
Loading…
Reference in New Issue
Block a user