diff --git a/client/package-lock.json b/client/package-lock.json index 5c478fcd..b4a79f07 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,6 +1,6 @@ { "name": "singlelink-client", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/server/functions/Analytics/link.js b/server/functions/Analytics/link.js index e5682831..e465b4fc 100644 --- a/server/functions/Analytics/link.js +++ b/server/functions/Analytics/link.js @@ -1,19 +1,29 @@ +import {DeepLinker} from "nc-deeplink"; + const mongoose = require('mongoose'); const Link = mongoose.model('Link'); const Visit = mongoose.model('Visit'); module.exports = async (req, res) => { - let link, visit; - try { - link = await Link.findOne({_id: req.params._id }); - visit = new Visit({ - type: 'Link', - referral: req.params._id - }); - visit = await visit.save(); - } catch(err) { - return res.send(err.message); - } finally { - return res.redirect(link.url); - } + let link, visit; + try { + link = await Link.findOne({_id: req.params._id}); + visit = new Visit({ + type: 'Link', + referral: req.params._id + }); + await visit.save(); + } catch (err) { + return res.send(err.message); + } + + if (link.useDeepLink) { + const userAgent = req.get('user-agent'); + const deepLink = DeepLinker.parseDeepLink(link.url, userAgent); + + return res.redirect(deepLink); + } else { + return res.redirect(link.url); + } + } diff --git a/server/package-lock.json b/server/package-lock.json index 1b638ce7..5f20c9a4 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -554,6 +554,14 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "nc-deeplink": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nc-deeplink/-/nc-deeplink-1.0.5.tgz", + "integrity": "sha512-PwiO6K66gtawWiJVVOlQr7t7ld1PcamridGRgPZSRawvd9ugPwgWsje/X1jTAOOu1DVdKtDvIV17t3WdvM3QfA==", + "requires": { + "ua-parser-js": "^0.7.22" + } + }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", @@ -778,6 +786,11 @@ "mime-types": "~2.1.24" } }, + "ua-parser-js": { + "version": "0.7.22", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.22.tgz", + "integrity": "sha512-YUxzMjJ5T71w6a8WWVcMGM6YWOTX27rCoIQgLXiWaxqXSx9D7DNjiGWn1aJIRSQ5qr0xuhra77bSIh6voR/46Q==" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/server/package.json b/server/package.json index a2d2c630..18acb710 100644 --- a/server/package.json +++ b/server/package.json @@ -11,7 +11,7 @@ "url": "git+/~https://github.com/Neutron-Creative/SingleLink.git" }, "author": "Neutron Creative Inc.", - "license": "GPL-V3", + "license": "GPL-3.0-or-later", "bugs": { "url": "/~https://github.com/Neutron-Creative/SingleLink/issues" }, @@ -28,6 +28,7 @@ "https": "^1.0.0", "jsonwebtoken": "^8.5.1", "md5": "^2.3.0", - "mongoose": "^5.10.0" + "mongoose": "^5.10.0", + "nc-deeplink": "^1.0.5" } }