From debf79e6fc7982826699938aabbb1db8100e0e86 Mon Sep 17 00:00:00 2001 From: b1ek Date: Sat, 4 Mar 2023 12:45:02 +1000 Subject: [PATCH] librebin url compatibility --- routes/index.js | 3 +++ routes/librebin.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 routes/librebin.js diff --git a/routes/index.js b/routes/index.js index cd5f10a..108c33e 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,4 +5,7 @@ router.use(require('./main')); router.use(require('./upload')); router.use(require('./view')); +// librebin url compatibility +router.use(require('./librebin')); + module.exports = router; \ No newline at end of file diff --git a/routes/librebin.js b/routes/librebin.js new file mode 100644 index 0000000..14ac9ad --- /dev/null +++ b/routes/librebin.js @@ -0,0 +1,26 @@ +const express = require('express'); +const router = express.Router(); +const handler = require('express-async-handler'); + +async function indexphp(req, res) { + if (req.query.p) { + res.redirect('/view?id=' + req.query.p); + return; + } + res.status(400).send('Bad request'); + rerturn; +} + +async function p(req, res) { + if (!req.params.id) { + res.status(400).send('Bad request'); + return; + } + res.redirect('/view?id=' + req.params.id + "&raw=true"); + return; +} + +router.use('/index.php', handler(indexphp)); +router.use('/p/:id', handler(p)); + +module.exports = router; \ No newline at end of file