Skip to content

Commit

Permalink
Add rudimentary deeplink support using nc-deeplink. Needs frontend + …
Browse files Browse the repository at this point in the history
…options, however
  • Loading branch information
NavidK0 committed Oct 8, 2020
1 parent e675f70 commit bc9e9f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 23 additions & 13 deletions server/functions/Analytics/link.js
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 13 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
}

0 comments on commit bc9e9f1

Please sign in to comment.