New urls can now be created with disabled preview

ref #2
This commit is contained in:
Nicolai Ort 2021-09-25 17:19:36 +02:00
parent f6b2ae523d
commit 33d7c94648
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 5 additions and 2 deletions

View File

@ -111,7 +111,7 @@ fastify.get('/:shortcode', async (req, res) => {
if (!target[0]) { if (!target[0]) {
return 404 return 404
} }
if(isBot(req.headers['user-agent']) && target[0].no_preview){ if(isBot(req.headers['user-agent']) && target[0].no_preview){
return "Bad Bot!" return "Bad Bot!"
} }
@ -127,6 +127,7 @@ const newUrlSchema = {
properties: { properties: {
target: { type: 'string' }, target: { type: 'string' },
shortcode: { type: 'string' }, shortcode: { type: 'string' },
no_preview: { type: 'boolean' },
} }
} }
}; };
@ -135,6 +136,7 @@ const newUrlSchema = {
fastify.post('/api', { newUrlSchema }, async (req, res) => { fastify.post('/api', { newUrlSchema }, async (req, res) => {
const target = req.body?.target; const target = req.body?.target;
let shortcode = req.body?.shortcode; let shortcode = req.body?.shortcode;
let no_preview = req.body?.no_preview || false;
//Check if the user provided a target //Check if the user provided a target
if (!target) { if (!target) {
@ -190,7 +192,8 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => {
return { return {
url: `${config.getBaseUrl()}/${shortcode}`, url: `${config.getBaseUrl()}/${shortcode}`,
shortcode, shortcode,
target target,
no_preview
} }
}); });