itemroute fix
This commit is contained in:
parent
d5eada1814
commit
37789979c4
@ -66,6 +66,8 @@ export default new class {
|
|||||||
return link.join("/");
|
return link.join("/");
|
||||||
};
|
};
|
||||||
parseTag(tag) {
|
parseTag(tag) {
|
||||||
|
if(!tag)
|
||||||
|
return null;
|
||||||
return tag
|
return tag
|
||||||
.replace(/%20/g, " ");
|
.replace(/%20/g, " ");
|
||||||
}
|
}
|
||||||
@ -95,5 +97,13 @@ export default new class {
|
|||||||
const derivedKey = await scrypt(str, salt, 64);
|
const derivedKey = await scrypt(str, salt, 64);
|
||||||
return crypto.timingSafeEqual(keyBuffer, derivedKey);
|
return crypto.timingSafeEqual(keyBuffer, derivedKey);
|
||||||
};
|
};
|
||||||
|
async getTags(itemid) {
|
||||||
|
const tags = await sql("tags_assign")
|
||||||
|
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
||||||
|
.where("tags_assign.item_id", itemid);
|
||||||
|
for(let t = 0; t < tags.length; t++)
|
||||||
|
tags[t].tag = tags[t].tag.replace(/[\u00A0-\u9999<>\&]/g, i => '&#'+i.charCodeAt(0)+';');
|
||||||
|
return tags;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -12,18 +12,14 @@ const auth = async (req, res, next) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default (router, tpl) => {
|
export default (router, tpl) => {
|
||||||
//router.get(/^\/?(?:user\/(?<user>[a-zA-Z0-9\[\]\-\_\{\}\\`\|]+))?(?:\/(?<mime>image|audio|video))?(?:\/p\/(?<page>\d+))?(?:\/(?<itemid>\d+))?$/, async (req, res) => {
|
|
||||||
router.get(/^\/?(?:tag\/(?<tag>.+?))?(?:user\/(?<user>.+?))?(?:\/(?<mime>image|audio|video))?(?:\/p\/(?<page>\d+))?(?:\/(?<itemid>\d+))?$/, async (req, res) => {
|
router.get(/^\/?(?:tag\/(?<tag>.+?))?(?:user\/(?<user>.+?))?(?:\/(?<mime>image|audio|video))?(?:\/p\/(?<page>\d+))?(?:\/(?<itemid>\d+))?$/, async (req, res) => {
|
||||||
const user = req.params.user ?? null;
|
const user = req.params.user ?? null;
|
||||||
let tag = req.params.tag ?? null;
|
const tag = lib.parseTag(req.params.tag ?? null);
|
||||||
const mime = (req.params.mime ?? "");
|
const mime = (req.params.mime ?? "");
|
||||||
const smime = allowedMimes.includes(mime) ? mime + "/%" : mime === "" ? "%" : "%";
|
const smime = allowedMimes.includes(mime) ? mime + "/%" : mime === "" ? "%" : "%";
|
||||||
const page = +(req.params.page ?? 1);
|
const page = +(req.params.page ?? 1);
|
||||||
const itemid = +(req.params.itemid ?? null);
|
const itemid = +(req.params.itemid ?? null);
|
||||||
|
|
||||||
if(tag)
|
|
||||||
tag = lib.parseTag(tag);
|
|
||||||
|
|
||||||
const output = {
|
const output = {
|
||||||
user, tag, mime, smime, page, itemid
|
user, tag, mime, smime, page, itemid
|
||||||
};
|
};
|
||||||
@ -36,104 +32,65 @@ export default (router, tpl) => {
|
|||||||
return res.end("200 - user not found lol");
|
return res.end("200 - user not found lol");
|
||||||
|
|
||||||
if(mode === "item") { // item!
|
if(mode === "item") { // item!
|
||||||
if(itemid == 404)
|
if(itemid === 404)
|
||||||
return res.end("404 - lol");
|
return res.end("404 - lol");
|
||||||
|
|
||||||
let query = (await sql("items")
|
let items = sql("items").select("*").orderBy("items.id", "desc").whereRaw(modequery);
|
||||||
.whereRaw(modequery)
|
if(tag) {
|
||||||
.andWhere("id", itemid)
|
items = items.innerJoin(
|
||||||
.andWhere("mime", "like", smime)
|
sql("tags")
|
||||||
.andWhere("username", "like", user ? user : "%")
|
.select("tags_assign.item_id", "tags.tag")
|
||||||
.limit(1))[0];
|
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
|
||||||
|
.where("tags.tag", "like", "%"+tag+"%")
|
||||||
if(!query?.id) { // same query with sfw-mode
|
.groupBy("tags_assign.item_id")
|
||||||
query = (await sql("items")
|
.as("st"),
|
||||||
.whereRaw(lib.getMode(0))
|
"st.item_id", "items.id"
|
||||||
.andWhere("id", itemid)
|
);
|
||||||
.andWhere("mime", "like", smime)
|
|
||||||
.andWhere("username", "like", user ? user : "%")
|
|
||||||
.limit(1)
|
|
||||||
)[0];
|
|
||||||
|
|
||||||
if(!query?.id)
|
|
||||||
return res.end("Sorry, this f0ck either doesn't exist (yet) or hasn't been tagged yet, please remain patient, a support assistant will be shortly with you.");
|
|
||||||
}
|
}
|
||||||
|
if(user)
|
||||||
|
items = items.andWhere("username", "like", "%" + user + "%");
|
||||||
|
if(mime)
|
||||||
|
items = items.andWhere("mime", "like", mime + "/%");
|
||||||
|
|
||||||
const tags = await sql("tags_assign")
|
items = await items;
|
||||||
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
|
||||||
.where("tags_assign.item_id", itemid);
|
|
||||||
|
|
||||||
const qmin = await sql("items")
|
const item = items.findIndex(i => i.id === itemid);
|
||||||
.select("id")
|
const actitem = items[item];
|
||||||
.whereRaw(modequery)
|
|
||||||
.andWhere("mime", "like", smime)
|
|
||||||
.andWhere("username", "like", user ? user : "%")
|
|
||||||
.orderBy("id")
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
const qmax = await sql("items")
|
if(!actitem) // sfw-check!
|
||||||
.select("id")
|
return res.end("Sorry, this f0ck either doesn't exist (yet) or hasn't been tagged yet, please remain patient, a support assistant will be shortly with you.");
|
||||||
.whereRaw(modequery)
|
|
||||||
.andWhere("mime", "like", smime)
|
|
||||||
.andWhere("username", "like", user ? user : "%")
|
|
||||||
.orderBy("id", "desc")
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
const qnext = (await sql("items")
|
const tags = await lib.getTags(itemid);
|
||||||
.select("id")
|
const cheat = items.slice(Math.max(0, item - 3), item + 4).map(i => i.id);
|
||||||
.whereRaw(modequery)
|
const link = lib.genLink({ user, tag, mime, act_page: itemid });
|
||||||
.andWhere("id", ">", itemid)
|
|
||||||
.andWhere("mime", "like", smime)
|
|
||||||
.andWhere("username", "like", user ? user : "%")
|
|
||||||
.orderBy("id")
|
|
||||||
.limit(3)
|
|
||||||
).reverse();
|
|
||||||
|
|
||||||
const qprev = await sql("items")
|
|
||||||
.select("id")
|
|
||||||
.whereRaw(modequery)
|
|
||||||
.andWhere("id", "<", itemid)
|
|
||||||
.andWhere("mime", "like", smime)
|
|
||||||
.andWhere("username", "like", user ? user : "%")
|
|
||||||
.orderBy("id", "desc")
|
|
||||||
.limit(3);
|
|
||||||
|
|
||||||
const cheat = qnext.concat([{ id: itemid }].concat(qprev)).map(e => +e.id);
|
|
||||||
const next = qnext[qnext.length - 1] ? qnext[qnext.length - 1].id : false;
|
|
||||||
const prev = qprev[0] ? qprev[0].id : false;
|
|
||||||
|
|
||||||
const link = lib.genLink({ user, mime, act_page: query.id });
|
|
||||||
|
|
||||||
for(let t = 0; t < tags.length; t++)
|
|
||||||
tags[t].tag = tags[t].tag.replace(/[\u00A0-\u9999<>\&]/g, i => '&#'+i.charCodeAt(0)+';');
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
user: {
|
user: {
|
||||||
name: query.username,
|
name: actitem.username,
|
||||||
channel: query.usernetwork == "Telegram" && query.userchannel !== "f0ck.me" ? "anonymous" : query.userchannel,
|
channel: actitem.usernetwork == "Telegram" && actitem.userchannel !== "f0ck.me" ? "anonymous" : actitem.userchannel,
|
||||||
network: query.usernetwork
|
network: actitem.usernetwork
|
||||||
},
|
},
|
||||||
item: {
|
item: {
|
||||||
id: query.id,
|
id: actitem.id,
|
||||||
src: {
|
src: {
|
||||||
long: query.src,
|
long: actitem.src,
|
||||||
short: url.parse(query.src).hostname,
|
short: url.parse(actitem.src).hostname,
|
||||||
},
|
},
|
||||||
thumbnail: `${cfg.websrv.paths.thumbnails}/${query.id}.png`,
|
thumbnail: `${cfg.websrv.paths.thumbnails}/${actitem.id}.png`,
|
||||||
coverart: `${cfg.websrv.paths.coverarts}/${query.id}.png`,
|
coverart: `${cfg.websrv.paths.coverarts}/${actitem.id}.png`,
|
||||||
dest: `${cfg.websrv.paths.images}/${query.dest}`,
|
dest: `${cfg.websrv.paths.images}/${actitem.dest}`,
|
||||||
mime: query.mime,
|
mime: actitem.mime,
|
||||||
size: lib.formatSize(query.size),
|
size: lib.formatSize(actitem.size),
|
||||||
timestamp: lib.timeAgo(new Date(query.stamp * 1e3).toISOString()),
|
timestamp: lib.timeAgo(new Date(actitem.stamp * 1e3).toISOString()),
|
||||||
tags: tags
|
tags: tags
|
||||||
},
|
},
|
||||||
title: `${query.id} - f0ck.me`,
|
title: `${actitem.id} - f0ck.me`,
|
||||||
pagination: {
|
pagination: {
|
||||||
start: qmax[0].id,
|
end: items[items.length - 1]?.id,
|
||||||
end: qmin[0].id,
|
start: items[0]?.id,
|
||||||
prev: next,
|
next: items[item + 1]?.id,
|
||||||
next: prev,
|
prev: items[item - 1]?.id,
|
||||||
page: query.id,
|
page: actitem.id,
|
||||||
cheat: cheat,
|
cheat: cheat,
|
||||||
link: link,
|
link: link,
|
||||||
uff: true
|
uff: true
|
||||||
@ -146,13 +103,20 @@ export default (router, tpl) => {
|
|||||||
let total, rows;
|
let total, rows;
|
||||||
|
|
||||||
if(tag) {
|
if(tag) {
|
||||||
total = (await sql("tags")
|
if(tag.match(/sfw/) || tag.length <= 2)
|
||||||
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
|
return res.end("f0ck you!");
|
||||||
.leftJoin("items", "items.id", "tags_assign.item_id")
|
total = (await sql("items")
|
||||||
|
.select("items.id", "items.mime", "st.tag")
|
||||||
|
.innerJoin(
|
||||||
|
sql("tags")
|
||||||
|
.select("tags_assign.item_id", "tags.tag")
|
||||||
|
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
|
||||||
|
.where("tags.tag", "like", "%"+tag+"%")
|
||||||
|
.groupBy("tags_assign.item_id")
|
||||||
|
.as("st"),
|
||||||
|
"st.item_id", "items.id"
|
||||||
|
)
|
||||||
.whereRaw(modequery)
|
.whereRaw(modequery)
|
||||||
.andWhere("items.mime", "like", smime)
|
|
||||||
.andWhere("tags.tag", "like", '%'+tag+'%')
|
|
||||||
.groupBy("items.id")
|
|
||||||
.count("* as total")
|
.count("* as total")
|
||||||
)[0]?.total;
|
)[0]?.total;
|
||||||
}
|
}
|
||||||
@ -173,15 +137,20 @@ export default (router, tpl) => {
|
|||||||
const offset = Math.max(0, (act_page - 1) * cfg.websrv.eps);
|
const offset = Math.max(0, (act_page - 1) * cfg.websrv.eps);
|
||||||
|
|
||||||
if(tag) {
|
if(tag) {
|
||||||
rows = await sql("tags")
|
rows = await sql("items")
|
||||||
.select("items.id", "items.mime", "tags_assign.tag_id")
|
.select("items.id", "items.mime", "st.tag", "tags_assign.tag_id")
|
||||||
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
|
.joinRaw("left join tags_assign on tags_assign.item_id = items.id and (tags_assign.tag_id = 1 or tags_assign.tag_id = 2)")
|
||||||
.leftJoin("items", "items.id", "tags_assign.item_id")
|
.innerJoin(
|
||||||
|
sql("tags")
|
||||||
|
.select("tags_assign.item_id", "tags.tag")
|
||||||
|
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
|
||||||
|
.where("tags.tag", "like", "%"+tag+"%")
|
||||||
|
.groupBy("tags_assign.item_id")
|
||||||
|
.as("st"),
|
||||||
|
"st.item_id", "items.id"
|
||||||
|
)
|
||||||
.whereRaw(modequery)
|
.whereRaw(modequery)
|
||||||
.andWhere("items.mime", "like", smime)
|
|
||||||
.andWhere("tags.tag", "like", '%'+tag+'%')
|
|
||||||
.orderBy("items.id", "desc")
|
.orderBy("items.id", "desc")
|
||||||
.groupBy("items.id")
|
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(cfg.websrv.eps);
|
.limit(cfg.websrv.eps);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user