fix(#83): add method to verify if alias being use is blacklisted or not. (#87)

This commit is contained in:
Himanshu Sanecha 2022-03-25 12:27:08 +05:30 committed by GitHub
parent 0c1a632cec
commit 49d97f6108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,12 @@ const Minfy = require('../models/minifed_urls')
const base_url = 'https://minfy.xyz/'
const { nanoid } = require('nanoid')
const blackListedAliases = ['404','dashboard','qr','credits','github','admin','geo','all','me','go','upload','download','link','about','tos','faqs']
function verifyAlias(alias) {
const boolean = blackListedAliases.find(element => element===alias);
return boolean;
}
module.exports.getAllData = async (req, res) => {
Minfy.find({})
.then((data) => {
@ -111,6 +117,12 @@ module.exports.updateUrlData = async (req, res) => {
module.exports.addURLAuthed = async (req, res) => {
const { alias, originalUrl } = req.body
if(verifyAlias(alias))
{
res.sendStatus(500);
throw new Error('This alias cannot be used, try some another.');
}
var createdBy = req.user.data.email
// console.log(req.user);
const minifiedUrl = base_url + alias