fix user profiles if no f0cks or favs exist
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 21s

This commit is contained in:
Flummi 2024-06-28 05:37:05 +02:00
parent befc8e8e75
commit e20e9899f9
2 changed files with 35 additions and 26 deletions

View File

@ -31,33 +31,42 @@ export default (router, tpl) => {
}); });
} }
const f0cks = await f0cklib.getf0cks({ let f0cks, favs;
user: user,
mode: req.session.mode,
fav: false,
session: !!req.session,
limit: 99999999
});
const favs = await f0cklib.getf0cks({
user: user,
mode: req.session.mode,
fav: true,
session: !!req.session,
limit: 99999999
});
const count = { const count = {
f0cks: 0, f0cks: 0,
favs: 0 favs: 0
}; };
try {
if('items' in f0cks) { f0cks = await f0cklib.getf0cks({
count.f0cks = f0cks.items.length; user: user,
f0cks.items = f0cks.items.slice(0, 50); mode: req.session.mode,
fav: false,
session: !!req.session,
limit: 99999999
});
if('items' in f0cks) {
count.f0cks = f0cks.items.length;
f0cks.items = f0cks.items.slice(0, 50);
}
} catch(err) {
f0cks = false;
count.f0cks = 0;
} }
if('items' in favs) { try {
count.favs = favs.items.length; favs = await f0cklib.getf0cks({
favs.items = favs.items.slice(0, 50); user: user,
mode: req.session.mode,
fav: true,
session: !!req.session,
limit: 99999999
});
if('items' in favs) {
count.favs = favs.items.length;
favs.items = favs.items.slice(0, 50);
}
} catch(err) {
favs = false;
count.favs = 0;
} }
const data = { const data = {

View File

@ -18,9 +18,9 @@
<div class="user_content_wrapper"> <div class="user_content_wrapper">
<div class="f0cks"> <div class="f0cks">
<div class="f0cks-header"> <div class="f0cks-header">
f0ck{{ count.f0cks == 1 ? '' : 's' }}: {{ count.f0cks }} <a href="{{ f0cks.link.main }}">view all</a> f0ck{{ count.f0cks == 1 ? '' : 's' }}: {{ count.f0cks }} <a href="{{ f0cks.link?.main }}">view all</a>
</div> </div>
@if('items' in f0cks) @if(count.f0cks)
<div class="posts"> <div class="posts">
@each(f0cks.items as item) @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> <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>
@ -32,9 +32,9 @@
</div> </div>
<div class="favs"> <div class="favs">
<div class="favs-header"> <div class="favs-header">
fav{{ count.favs == 1 ? '' : 's' }}: {{ count.favs }} <a href="{{ favs.link.main }}">view all</a> fav{{ count.favs == 1 ? '' : 's' }}: {{ count.favs }} <a href="{{ favs.link?.main }}">view all</a>
</div> </div>
@if('items' in favs) @if(count.favs)
<div class="posts"> <div class="posts">
@each(favs.items as item) @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> <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>