From 155d496592d408324d9d10473e54e0cae310c10f Mon Sep 17 00:00:00 2001 From: Flummi Date: Fri, 6 May 2022 17:29:55 +0200 Subject: [PATCH] fix random & search --- src/inc/routes/random.mjs | 7 ++++--- src/inc/routes/search.mjs | 5 +++-- src/inc/trigger/f0ckgag.mjs | 2 +- src/inc/trigger/f0ckrand.mjs | 2 +- src/inc/trigger/parser.mjs | 6 +++--- src/inc/trigger/tags.mjs | 12 ++++++------ views/search.html | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/inc/routes/random.mjs b/src/inc/routes/random.mjs index 07e390a..c4917ae 100644 --- a/src/inc/routes/random.mjs +++ b/src/inc/routes/random.mjs @@ -1,3 +1,4 @@ +import cfg from "../../inc/config.mjs"; import f0cklib from "../routeinc/f0cklib.mjs"; export default (router, tpl) => { @@ -5,8 +6,8 @@ export default (router, tpl) => { let referer = req.headers.referer ?? ''; let opts = {}; - if(referer.match(/f0ck\.me/)) { // parse referer - referer = referer.split("f0ck.me")[1]; + if(referer.match(new RegExp(cfg.main.url.regex))) { // parse referer + referer = referer.split(cfg.main.url.domain)[1]; const tmp = referer.match(/^\/?(?:\/tag\/(?.+?))?(?:\/user\/(?.+?)\/(?f0cks|favs))?(?:\/(?image|audio|video))?(?:\/p\/(?\d+))?(?:\/(?\d+))?$/); if(tmp) opts = tmp.groups; @@ -31,7 +32,7 @@ export default (router, tpl) => { }); } - res.redirect(`/${data.link}${data.link.length != 0 ? "/" : ""}${data.itemid}`); + res.redirect(`${data.link.main}${data.link.path}${data.itemid}`); }); return router; }; diff --git a/src/inc/routes/search.mjs b/src/inc/routes/search.mjs index 2fe2d65..41259e4 100644 --- a/src/inc/routes/search.mjs +++ b/src/inc/routes/search.mjs @@ -18,7 +18,7 @@ export default (router, tpl) => { select count(*) as total from "items" where src ilike ${'%' + tag.substring(4) + '%'} - group by "items".id, "tags".tag + group by "items".id `).length; } else { @@ -41,7 +41,8 @@ export default (router, tpl) => { select * from "items" where src ilike ${'%' + tag.substring(4) + '%'} - group by "items".id, "tags".tag + group by "items".id + order by "items".id desc offset ${offset} limit ${_eps} `; diff --git a/src/inc/trigger/f0ckgag.mjs b/src/inc/trigger/f0ckgag.mjs index 98e0f50..1eb253a 100644 --- a/src/inc/trigger/f0ckgag.mjs +++ b/src/inc/trigger/f0ckgag.mjs @@ -25,7 +25,7 @@ export default async bot => { return e.reply("no f0cks given! lol D:"); e.reply([ - `${cfg.main.url}/${rows[0].id}`, + `${cfg.main.url.full}/${rows[0].id}`, `user: ${rows[0].username} @ ${rows[0].usernetwork} ${rows[0].userchannel}`, `~${lib.formatSize(rows[0].size)}`, rows[0].mime, diff --git a/src/inc/trigger/f0ckrand.mjs b/src/inc/trigger/f0ckrand.mjs index 27f37d9..ca337cc 100644 --- a/src/inc/trigger/f0ckrand.mjs +++ b/src/inc/trigger/f0ckrand.mjs @@ -24,7 +24,7 @@ export default async bot => { if(rows.length === 0) return e.reply("nothing found, f0cker"); - return e.reply(`f0ckrnd: ${cfg.main.url}/${rows[0].id} by: ${rows[0].username} (${rows[0].mime}, ~${lib.formatSize(rows[0].size)})`); + return e.reply(`f0ckrnd: ${cfg.main.url.full}/${rows[0].id} by: ${rows[0].username} (${rows[0].mime}, ~${lib.formatSize(rows[0].size)})`); } }]; }; diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 46ecf26..9a91c17 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -51,7 +51,7 @@ export default async bot => { where src = ${link} `; if(q_repost.length > 0) - return e.reply(`repost motherf0cker (link): ${cfg.main.url}/${q_repost[0].id}`); + return e.reply(`repost motherf0cker (link): ${cfg.main.url.full}/${q_repost[0].id}`); // generate uuid const uuid = (await db` @@ -120,7 +120,7 @@ export default async bot => { where checksum = ${checksum} `; if(q_repostc.length > 0) - return e.reply(`repost motherf0cker (checksum): ${cfg.main.url}/${q_repostc[0].id}`); + return e.reply(`repost motherf0cker (checksum): ${cfg.main.url.full}/${q_repostc[0].id}`); await fs.promises.copyFile(`./tmp/${filename}`, `./public/b/${filename}`); await fs.promises.unlink(`./tmp/${filename}`).catch(_=>{}); @@ -241,7 +241,7 @@ export default async bot => { } e.reply([ - `[f0cked] link: ${cfg.main.url}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}` + (tags.length > 0 ? ` | tags: ${tags.join(', ')}` : '') + `[f0cked] link: ${cfg.main.url.full}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}` + (tags.length > 0 ? ` | tags: ${tags.join(', ')}` : '') ]); }); diff --git a/src/inc/trigger/tags.mjs b/src/inc/trigger/tags.mjs index 32b3b01..baa17b6 100644 --- a/src/inc/trigger/tags.mjs +++ b/src/inc/trigger/tags.mjs @@ -15,8 +15,8 @@ export default async bot => { return e.reply("lol no"); const tags = (await lib.getTags(id)).map(t => t.tag); if(tags.length === 0) - return e.reply(`item ${cfg.main.url}/${id} has no tags!`); - return e.reply(`item ${cfg.main.url}/${id} is tagged as: ${tags.join(', ')}`); + return e.reply(`item ${cfg.main.url.full}/${id} has no tags!`); + return e.reply(`item ${cfg.main.url.full}/${id} is tagged as: ${tags.join(', ')}`); } }, { name: "tags add", @@ -73,8 +73,8 @@ export default async bot => { const ntags = (await lib.getTags(id)).map(t => t.tag); if(ntags.length === 0) - return e.reply(`item ${cfg.main.url}/${id} has no tags!`); - return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`); + return e.reply(`item ${cfg.main.url.full}/${id} has no tags!`); + return e.reply(`item ${cfg.main.url.full}/${id} is now tagged as: ${ntags.join(', ')}`); } }, { name: "tags remove", @@ -126,8 +126,8 @@ export default async bot => { const ntags = (await lib.getTags(id)).map(t => t.tag); if(ntags.length === 0) - return e.reply(`item ${cfg.main.url}/${id} has no tags!`); - return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`); + return e.reply(`item ${cfg.main.url.full}/${id} has no tags!`); + return e.reply(`item ${cfg.main.url.full}/${id} is now tagged as: ${ntags.join(', ')}`); } }] }; diff --git a/views/search.html b/views/search.html index 668f423..ab1b870 100644 --- a/views/search.html +++ b/views/search.html @@ -25,7 +25,7 @@ {!! line.tag !!} {{ line.mime }} {!! line.username !!} - {{ line.score.toFixed(2) }} + {{ line.score?.toFixed(2) }} @endeach