hide tags from the public
This commit is contained in:
parent
d0f8cb5acb
commit
af4c48f351
|
@ -14,6 +14,7 @@
|
||||||
},
|
},
|
||||||
"allowedModes": [ "sfw", "nsfw", "untagged", "all" ],
|
"allowedModes": [ "sfw", "nsfw", "untagged", "all" ],
|
||||||
"allowedMimes": [ "audio", "image", "video" ],
|
"allowedMimes": [ "audio", "image", "video" ],
|
||||||
|
"nsfp": [],
|
||||||
"websrv": {
|
"websrv": {
|
||||||
"port": "8080",
|
"port": "8080",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
|
@ -4,8 +4,10 @@ import cfg from "../config.mjs";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import url from "url";
|
import url from "url";
|
||||||
|
|
||||||
|
const globalfilter = cfg.nsfp.map(n => `tag_id = ${n}`).join(' or ');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getf0cks: async (o = { user, tag, mime, page, mode, fav }) => {
|
getf0cks: async (o = { user, tag, mime, page, mode, fav, session }) => {
|
||||||
const user = o.user ? decodeURI(o.user) : null;
|
const user = o.user ? decodeURI(o.user) : null;
|
||||||
const tag = lib.parseTag(o.tag ?? null);
|
const tag = lib.parseTag(o.tag ?? null);
|
||||||
const mime = o.mime ?? null;
|
const mime = o.mime ?? null;
|
||||||
|
@ -29,7 +31,7 @@ export default {
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
||||||
and items.id not in (select item_id from tags_assign where item_id = items.id and tag_id = 9912) --public filter
|
${ !o.session ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db`` }
|
||||||
group by items.id, tags.tag
|
group by items.id, tags.tag
|
||||||
`)?.length || 0;
|
`)?.length || 0;
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ export default {
|
||||||
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
||||||
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
||||||
and items.id not in (select item_id from tags_assign where item_id = items.id and tag_id = 9912) --public filter
|
${ !o.session ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db`` }
|
||||||
group by items.id, tags.tag, ta.tag_id
|
group by items.id, tags.tag, ta.tag_id
|
||||||
order by items.id desc
|
order by items.id desc
|
||||||
offset ${offset}
|
offset ${offset}
|
||||||
|
@ -90,7 +92,7 @@ export default {
|
||||||
tmp
|
tmp
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getf0ck: async (o = ({ user, tag, mime, itemid, mode })) => {
|
getf0ck: async (o = ({ user, tag, mime, itemid, mode, session })) => {
|
||||||
const user = o.user ? decodeURI(o.user) : null;
|
const user = o.user ? decodeURI(o.user) : null;
|
||||||
const tag = lib.parseTag(o.tag ?? null);
|
const tag = lib.parseTag(o.tag ?? null);
|
||||||
const mime = (o.mime ?? "");
|
const mime = (o.mime ?? "");
|
||||||
|
@ -108,74 +110,25 @@ export default {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let items;
|
const items = await db`
|
||||||
|
select distinct on (items.id)
|
||||||
if(o.fav) {
|
items.*
|
||||||
items = db`
|
from items
|
||||||
select "items".*
|
left join tags_assign on tags_assign.item_id = items.id
|
||||||
from "favorites"
|
left join tags on tags.id = tags_assign.tag_id
|
||||||
left join "items" on "items".id = "favorites".item_id
|
left join favorites on favorites.item_id = items.id
|
||||||
left join "user" on "user".id = "favorites".user_id
|
left join "user" on "user".id = favorites.user_id
|
||||||
${ tag
|
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
|
||||||
? db`
|
where
|
||||||
inner join (
|
${ db.unsafe(modequery) }
|
||||||
select "tags_assign".item_id, "tags".tag
|
${ tag ? db`and tags.normalized ilike ${'%'+tag+'%'}` : db`` }
|
||||||
from "tags"
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
||||||
where "tags".tag ilike ${'%' + tag + '%'}
|
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
||||||
group by "tags_assign".item_id, "tags".tag
|
${ !o.session ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db`` }
|
||||||
) as st on st.item_id = "items".id`
|
group by items.id, tags.tag, ta.tag_id
|
||||||
: db``
|
order by items.id desc
|
||||||
}
|
|
||||||
where ${db.unsafe(modequery)}
|
|
||||||
and "user".user ilike ${user}
|
|
||||||
${ mime
|
|
||||||
? db`and "items".mime ilike ${mime + '/%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
${ tag
|
|
||||||
? db`group by st.tag, st.item_id, "items".id`
|
|
||||||
: db`group by "items".id, "favorites".user_id, "favorites".item_id, "user".id`
|
|
||||||
}
|
|
||||||
order by "items".id desc
|
|
||||||
`;
|
`;
|
||||||
}
|
|
||||||
else {
|
|
||||||
items = db`
|
|
||||||
select "items".*
|
|
||||||
from "items"
|
|
||||||
${ tag
|
|
||||||
? db`
|
|
||||||
inner join (
|
|
||||||
select "tags_assign".item_id, "tags_assign".tag_id, "tags".tag
|
|
||||||
from "tags"
|
|
||||||
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
|
||||||
where "tags".tag ilike ${'%' + tag + '%'}
|
|
||||||
group by "tags_assign".item_id, "tags".tag, "tags_assign".tag_id
|
|
||||||
) as st on st.item_id = "items".id`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
where ${db.unsafe(modequery)}
|
|
||||||
${ user
|
|
||||||
? db`and "items".username ilike ${'%' + user + '%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
${ mime
|
|
||||||
? db`and "items".mime ilike ${mime + '/%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
${ tag
|
|
||||||
? db`group by st.item_id, "items".id, st.tag_id`
|
|
||||||
: db`group by "items".id`
|
|
||||||
}
|
|
||||||
order by "items".id desc
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
items = await items;
|
|
||||||
|
|
||||||
if(tag)
|
|
||||||
items = items.filter((v, i, s) => i === s.findIndex(t => t.id === v.id));
|
|
||||||
|
|
||||||
const item = items.findIndex(i => i.id === itemid);
|
const item = items.findIndex(i => i.id === itemid);
|
||||||
const actitem = items[item];
|
const actitem = items[item];
|
||||||
|
@ -245,71 +198,33 @@ export default {
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
getRandom: async (o = ({ user, tag, mime, mode })) => {
|
getRandom: async (o = ({ user, tag, mime, mode, session })) => {
|
||||||
const user = o.user ? decodeURI(o.user) : null;
|
const user = o.user ? decodeURI(o.user) : null;
|
||||||
const tag = lib.parseTag(o.tag ?? null);
|
const tag = lib.parseTag(o.tag ?? null);
|
||||||
const mime = (o.mime ?? "");
|
const mime = (o.mime ?? "");
|
||||||
|
const smime = cfg.allowedMimes.includes(mime) ? mime + "/%" : mime === "" ? "%" : "%";
|
||||||
|
|
||||||
const modequery = mime == "audio" ? lib.getMode(0) : lib.getMode(o.mode ?? 0);
|
const modequery = mime == "audio" ? lib.getMode(0) : lib.getMode(o.mode ?? 0);
|
||||||
|
|
||||||
let item;
|
const item = await db`
|
||||||
if(o.fav) { // dood lol
|
select
|
||||||
item = db`
|
items.id
|
||||||
select "items".*
|
from items
|
||||||
from "favorites"
|
left join tags_assign on tags_assign.item_id = items.id
|
||||||
left join "items" on "items".id = "favorites".item_id
|
left join tags on tags.id = tags_assign.tag_id
|
||||||
left join "user" on "user".id = "favorites".user_id
|
left join favorites on favorites.item_id = items.id
|
||||||
${ tag
|
left join "user" on "user".id = favorites.user_id
|
||||||
? db`
|
where
|
||||||
inner join (
|
${ db.unsafe(modequery) }
|
||||||
select "tags_assign".item_id, "tags".tag
|
${ tag ? db`and tags.normalized ilike ${'%'+tag+'%'}` : db`` }
|
||||||
from "tags"
|
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
|
||||||
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
${ user ? db`and items.username ilike ${'%'+user+'%'}` : db`` }
|
||||||
where "tags".tag ilike ${'%' + tag + '%'}
|
${ mime ? db`and items.mime ilike ${smime}` : db`` }
|
||||||
group by "tags_assign".item_id, "tags".tag
|
${ !o.session ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db`` }
|
||||||
) as st on st.item_id = "items".id`
|
group by items.id, tags.tag
|
||||||
: db``
|
|
||||||
}
|
|
||||||
where ${db.unsafe(modequery)}
|
|
||||||
and "user".user ilike ${user}
|
|
||||||
${ mime
|
|
||||||
? db`and "items".mime ilike ${mime + '/%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
order by random()
|
order by random()
|
||||||
limit 1
|
limit 1
|
||||||
`;
|
`;
|
||||||
}
|
|
||||||
else {
|
|
||||||
item = db`
|
|
||||||
select *
|
|
||||||
from "items"
|
|
||||||
${ tag
|
|
||||||
? db`
|
|
||||||
inner join (
|
|
||||||
select "tags_assign".item_id, "tags".tag
|
|
||||||
from "tags"
|
|
||||||
left join "tags_assign" on "tags_assign".tag_id = "tags".id
|
|
||||||
where "tags".tag ilike ${'%' + tag + '%'}
|
|
||||||
group by "tags_assign".item_id, "tags".tag
|
|
||||||
) as st on st.item_id = "items".id`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
where ${db.unsafe(modequery)}
|
|
||||||
${ user
|
|
||||||
? db`and "items".username ilike ${'%' + user + '%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
${ mime
|
|
||||||
? db`and "items".mime ilike ${mime + '/%'}`
|
|
||||||
: db``
|
|
||||||
}
|
|
||||||
order by random()
|
|
||||||
limit 1
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
item = await item;
|
|
||||||
|
|
||||||
if(item.length === 0) {
|
if(item.length === 0) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -34,12 +34,14 @@ export default (router, tpl) => {
|
||||||
const f0cks = await f0cklib.getf0cks({
|
const f0cks = await f0cklib.getf0cks({
|
||||||
user: user,
|
user: user,
|
||||||
mode: req.session.mode,
|
mode: req.session.mode,
|
||||||
fav: false
|
fav: false,
|
||||||
|
session: !!req.session
|
||||||
});
|
});
|
||||||
const favs = await f0cklib.getf0cks({
|
const favs = await f0cklib.getf0cks({
|
||||||
user: user,
|
user: user,
|
||||||
mode: req.session.mode,
|
mode: req.session.mode,
|
||||||
fav: true
|
fav: true,
|
||||||
|
session: !!req.session
|
||||||
});
|
});
|
||||||
|
|
||||||
if('items' in f0cks)
|
if('items' in f0cks)
|
||||||
|
@ -66,7 +68,8 @@ export default (router, tpl) => {
|
||||||
page: req.params.page,
|
page: req.params.page,
|
||||||
itemid: req.params.itemid,
|
itemid: req.params.itemid,
|
||||||
fav: req.params.mode == 'favs',
|
fav: req.params.mode == 'favs',
|
||||||
mode: req.session.mode
|
mode: req.session.mode,
|
||||||
|
session: !!req.session
|
||||||
});
|
});
|
||||||
if(!data.success) {
|
if(!data.success) {
|
||||||
return res.reply({
|
return res.reply({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user