diff --git a/api/models/short_links.js b/api/models/short_links.js index b994d1c..c68c43c 100644 --- a/api/models/short_links.js +++ b/api/models/short_links.js @@ -9,5 +9,10 @@ module.exports = sequelize.define('short_link', { shortcut: { type: Sequelize.TEXT, allowNull: false + }, + count: { + type: Sequelize.INTEGER, + allowNull: false, + defaultValue: 0 } }) diff --git a/s.divlo.fr/app.js b/s.divlo.fr/app.js index 250e6ea..e8d2124 100644 --- a/s.divlo.fr/app.js +++ b/s.divlo.fr/app.js @@ -51,7 +51,18 @@ app.get('/:shortcut', (req, res, next) => { return res.redirect('/error/404') } - return res.redirect(result.url) + const count = (result.count += 1) + database.query( + 'UPDATE short_links SET count = ? WHERE id = ?', + [count, result.id], + error => { + if (error != null) { + return next(error) + } + + return res.redirect(result.url) + } + ) } ) }) diff --git a/website/pages/functions/linkShortener.jsx b/website/pages/functions/linkShortener.jsx index 79adc94..48ce763 100644 --- a/website/pages/functions/linkShortener.jsx +++ b/website/pages/functions/linkShortener.jsx @@ -277,6 +277,9 @@ const LinksList = ({