parent
e5b8557e4c
commit
75adbf73cf
|
@ -112,6 +112,7 @@ fastify.get('/:shortcode', async (req, res) => {
|
|||
return 404
|
||||
}
|
||||
|
||||
console.log({ua: req.headers['user-agent'], bot: isBot(req.headers['user-agent']), prev: target[0].no_preview})
|
||||
if(isBot(req.headers['user-agent']) && target[0].no_preview){
|
||||
return "Bad Bot!"
|
||||
}
|
||||
|
@ -156,7 +157,7 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => {
|
|||
return response;
|
||||
}
|
||||
}
|
||||
const exists = await knex.select('shortcode')
|
||||
const exists = await knex.select('shortcode', 'no_preview')
|
||||
.from('urls')
|
||||
.where('target', '=', target)
|
||||
.limit(1);
|
||||
|
@ -165,7 +166,8 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => {
|
|||
return {
|
||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||
shortcode,
|
||||
target
|
||||
target,
|
||||
no_preview: exists[0].no_preview
|
||||
}
|
||||
}
|
||||
shortcode = uniqid();
|
||||
|
@ -187,7 +189,7 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => {
|
|||
}
|
||||
|
||||
//Create a new db entry
|
||||
await knex('urls').insert({ target, shortcode });
|
||||
await knex('urls').insert({ target, shortcode, no_preview });
|
||||
|
||||
return {
|
||||
url: `${config.getBaseUrl()}/${shortcode}`,
|
||||
|
|
Loading…
Reference in New Issue