feat: add redirection route

makes using quetre more convenient
This commit is contained in:
zyachel 2023-01-15 22:22:10 +05:30
parent 595b720ee1
commit 4199bb38c3
3 changed files with 32 additions and 4 deletions

View file

@ -147,7 +147,7 @@ From [their privacy policy](https://www.quora.com/about/privacy)
- How do I use this?
Replace 'www.quora.com' in any URL with 'quetre.iket.me'. So, 'https://www.quora.com/Are-Nubians-nilotes' becomes 'https://quetre.iket.me/Are-Nubians-nilotes'.
Replace 'www.quora.com' in any URL with 'quetre.iket.me'(or any other instance). So, 'https://www.quora.com/Are-Nubians-nilotes' becomes 'https://quetre.iket.me/Are-Nubians-nilotes'.
- I don't want to edit the URLs manually!
@ -239,10 +239,10 @@ Following extensions can be used to automatically redirect Quora URLs to Quetre:
```
Description: Quora to Quetre
Example URL: https://www.quora.com/What-is-Linux-4?share=1
Include pattern: https?:\/\/(www\.)?quora\.com\/([^\?]*)
Redirect to: https://quetre.iket.me/$2
Include pattern: (https:\/\/.{2,}\.quora\.com\/.*)
Redirect to: https://quetre.iket.me/redirect/$1
Pattern type: Regular Expression
Pattern description: redirects all Quora urls(excluding language-specific and spaces) to Quetre
Pattern description: redirects all Quora urls to Quetre
```
This config should output:
@ -251,6 +251,13 @@ Following extensions can be used to automatically redirect Quora URLs to Quetre:
- [LibRedirect](https://github.com/libredirect/libredirect/)
Redirects many popular services to their alternative front-ends. Has a ton of features and an active community. Quetre is supported by default. So, no need to do anything.
- [Privacy Redirector](https://github.com/dybdeskarphet/privacy-redirector)
A userscript that redirects popular social media platforms to their privacy respecting frontends.
- Other addons with similar functionality:
- [Dynamic Privacy Redirect](https://github.com/PrivacyDevel/DPR-addon)
- [Alter](https://github.com/w3bdev1/alter)
### Other alternative front-ends
- [digitalblossom/alternative-frontends](https://github.com/digitalblossom/alternative-frontends): contains other alternative front-ends.

View file

@ -108,6 +108,25 @@ export const search = catchAsyncErrors(async (req, res, next) => {
});
});
const regex = /^https:\/\/(.{2,})\.quora\.com(\/.*)$/; // local helper constant
export const redirect = (req, res, next) => {
const url = req.originalUrl.replace('/redirect/', ''); // removing `/redirect/` part.
const match = regex.exec(url);
if (!match) return res.redirect('/');
const [_, subdomain, rest] = match; // eg: subdomain: 'es', rest: '/topic/linux?share=1'
let link;
if (acceptedLanguages.includes(subdomain))
// adding lang param
link = `${rest}${rest.includes('?') ? '&' : '?'}lang=${subdomain}`;
else if (subdomain === 'www') link = rest; // doing nothing
else link = `/space/${subdomain}${rest}`; // gotta be a space url.
return res.redirect(link);
};
export const unimplemented = (req, res, next) => {
const data = {
message: "This route isn't yet implemented. Check back sometime later!",

View file

@ -7,6 +7,7 @@ import {
unimplemented,
profile,
search,
redirect,
} from '../controllers/viewController.js';
const viewRouter = express.Router();
@ -20,5 +21,6 @@ viewRouter.get('/unanswered/:slug', answers);
viewRouter.get('/space/:name', unimplemented);
viewRouter.get('/space/:name/:slug', unimplemented);
viewRouter.get('/:slug', answers);
viewRouter.get('/redirect/*', redirect); // eg: /redirect/https://www.quora.com/topic/linux
export default viewRouter;