This commit is contained in:
x
2025-03-16 03:04:21 +01:00
parent a905b8817e
commit 76f1a3ddbb
7 changed files with 29 additions and 23 deletions

View File

@ -221,14 +221,14 @@ export default new class {
return next();
};
async loggedin(req, res, next) {
if(!req.session) {
return res.reply({
code: 401,
body: "401 - Unauthorized"
});
}
return next();
};
// async loggedin(req, res, next) {
// if(!req.session) {
// return res.reply({
// code: 401,
// body: "401 - Unauthorized"
// });
// }
// return next();
// };
};

View File

@ -1,14 +1,17 @@
import cfg from "../../inc/config.mjs";
import lib from "../lib.mjs";
import f0cklib from "../routeinc/f0cklib.mjs";
export default (router, tpl) => {
router.get(/^\/random$/, async (req, res) => {
router.get(/^\/random$/, lib.loggedin, async (req, res) => {
let referer = req.headers.referer ?? '';
let opts = {};
if(referer.match(new RegExp(cfg.main.url.regex))) { // parse referer
referer = referer.split(cfg.main.url.domain)[1];
console.log("referer: ", referer);
const tmp = referer.match(/^\/?(?:\/tag\/(?<tag>.+?))?(?:\/user\/(?<user>.+?)\/(?<mode>f0cks|favs))?(?:\/(?<mime>image|audio|video))?(?:\/p\/(?<page>\d+))?(?:\/(?<itemid>\d+))?$/);
console.log("tmp: ", tmp);
if(tmp)
opts = tmp.groups;
}
@ -22,6 +25,8 @@ export default (router, tpl) => {
mode: req.session.mode,
session: !!req.session
});
console.log("data", data);
if(!data.success) {
return res.reply({