Added bot check for native short urls

ref #2
This commit is contained in:
Nicolai Ort 2021-09-25 17:17:42 +02:00
parent 0a500f16cd
commit f6b2ae523d
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 4 additions and 3 deletions

View File

@ -104,17 +104,18 @@ fastify.get('/:shortcode', async (req, res) => {
if (!shortcode) { if (!shortcode) {
return 404; return 404;
} }
const target = await knex.select('target') const target = await knex.select('target', 'no_preview')
.from('urls') .from('urls')
.where('shortcode', '=', shortcode) .where('shortcode', '=', shortcode)
.limit(1); .limit(1);
if (!target[0]) { if (!target[0]) {
return 404 return 404
} }
if(isBot(req.headers['user-agent'])){
if(isBot(req.headers['user-agent']) && target[0].no_preview){
return "Bad Bot!" return "Bad Bot!"
} }
res.redirect(302, target[0].target); res.redirect(302, target[0].target);
await knex('visits').insert({ shortcode, provider: 'native' }); await knex('visits').insert({ shortcode, provider: 'native' });
}) })