Compare commits

..

3 Commits

Author SHA1 Message Date
567ac07612 Merge branch 'main' of git.odit.services:kauft.es/linkylinky into main
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-14 11:50:35 +02:00
fa01864d0d
API Endpoint to get all short urls 2021-08-14 11:50:29 +02:00
91b25c22ca
Get all api endpoints 2021-08-14 11:50:03 +02:00
2 changed files with 20 additions and 2 deletions

3
.env
View File

@ -1,3 +1,4 @@
SSL=false
SSL=true
DOMAIN=kauft.es
DISABLE_PROVIDERS=false
ENABLE_REGISTER=true

View File

@ -221,7 +221,7 @@ fastify.after(() => {
});
//Get url api route
fastify.delete('/api/:shortcode', async (req, res) => {
fastify.delete('/api/:shortcode', { onRequest: fastify.basicAuth }, async (req, res) => {
const shortcode = req.params.shortcode;
//This should never happen but better safe than 500
@ -237,6 +237,23 @@ fastify.after(() => {
return true;
});
//Get all urls api route
fastify.get('/api', { onRequest: fastify.basicAuth }, async (req, res) => {
urls = await knex.select('target', 'shortcode')
.from('urls');
for (let url of urls) {
url.url = `${config.getBaseUrl()}/${url.shortcode}`
if(req.query.showVisits){
url.visits = (await knex.select('timestamp')
.from('visits')
.where('shortcode', '=', url.shortcode)).length;
}
}
return urls;
});
});