From ba8a0c6b6884fc4e63e10e2559a1da473a4135d3 Mon Sep 17 00:00:00 2001 From: Flummi Date: Fri, 24 Dec 2021 11:16:11 +0100 Subject: [PATCH] error pages --- src/inc/routes/index.mjs | 55 ++++++++++++++++++++++++++++++++++------ views/error.html | 3 +++ 2 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 views/error.html diff --git a/src/inc/routes/index.mjs b/src/inc/routes/index.mjs index ebb074b..d8f308a 100644 --- a/src/inc/routes/index.mjs +++ b/src/inc/routes/index.mjs @@ -29,11 +29,24 @@ export default (router, tpl) => { let data; if(user && (await sql("items").where("username", "like", user).count("* as total"))[0].total === 0) - return res.end("200 - user not found lol"); + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "404 - user not found", + tmp: null + }, req) + }); if(mode === "item") { // item! - if(itemid === 404) - return res.end("404 - lol"); + if(itemid === 404) { + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "404 - f0ck not found", + tmp: null + }, req) + }); + } let items = sql("items").select("*").orderBy("items.id", "desc").whereRaw(modequery); if(tag) { @@ -57,8 +70,15 @@ export default (router, tpl) => { const item = items.findIndex(i => i.id === itemid); const actitem = items[item]; - if(!actitem) // sfw-check! - 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(!actitem) { // sfw-check! + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "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.", + tmp: null + }, req) + }); + } const tags = await lib.getTags(itemid); const cheat = items.slice(Math.max(0, item - 3), item + 4).map(i => i.id); @@ -104,7 +124,14 @@ export default (router, tpl) => { if(tag) { if(tag.match(/sfw/) || tag.length <= 2) - return res.end("f0ck you!"); + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "nope.", + tmp: null + }, req) + }); + total = (await sql("items") .select("items.id", "items.mime", "st.tag") .innerJoin( @@ -130,7 +157,13 @@ export default (router, tpl) => { } if(!total || total.length === 0) - return res.end("no f0cks given lol"); + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "404 - no f0cks given", + tmp: null + }, req) + }); const pages = +Math.ceil(total / cfg.websrv.eps); const act_page = Math.min(pages, page || 1); @@ -167,7 +200,13 @@ export default (router, tpl) => { } if(rows.length === 0) - return res.end("oops"); + return res.reply({ + code: 404, + body: tpl.render('error', { + message: "oopsi woopsi", + tmp: null + }, req) + }); rows.forEach(e => { if(!fs.existsSync(`public/t/${e.id}.png`)) diff --git a/views/error.html b/views/error.html new file mode 100644 index 0000000..53b05d5 --- /dev/null +++ b/views/error.html @@ -0,0 +1,3 @@ +@include(main/header) +

{{ message }}

+@include(main/footer)