Add other share option

test
dan 2020-03-29 15:04:42 -06:00
parent 1e422fa9d8
commit d4598d76c0
1 changed files with 41 additions and 0 deletions

View File

@ -24,9 +24,28 @@ router.get("/:shareCode",function(req,res){
return getSermon(req, res, param);
case "e":
return getEvent(req,res,param);
case "o":
return getOther(req, res)
}
});
function getOther(req, res,) {
console.log(req.headers);
var userAgent = req.headers['user-agent'];
var userAgentOverride = req.headers['user-agent-override'];
var referrer = req.headers['referer'] || "";
userAgent = userAgentOverride || userAgent;
if (userAgent.startsWith('facebookexternalhit/1.1') ||
userAgent === 'Facebot' ||
userAgent.startsWith('Twitterbot') ||
referrer.startsWith('http://opengraphcheck.com')) {
getOtherMeta(req, res, req.query.title, req.query.description, req.query.imageUrl, req.query.imageWidth, req.query.imageHeight, req.query.url);
} else {
var url = req.query.url;
res.redirect(url);
}
}
function getSermon(req, res, id){
console.log(req.headers);
var userAgent = req.headers['user-agent'];
@ -44,6 +63,28 @@ function getSermon(req, res, id){
}
}
function getOtherMeta(req, res, title, description, imageUrl, imageWidth, imageHeight, url) {
var result = `<html>
<head>
<title>Old Fashion Baptist Church</title>
<!-- You can use Open Graph tags to customize link previews.
Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
<meta property="og:url" content="`+ url +`"/>
<meta property="og:type" content="website" />
<meta property="og:title" content="` + title + `" />
<meta property="og:description" content="` + description + `" />
<meta property="og:image" content="` + imageUrl + `" />
<meta property="og:image:width" content="`+ imageWidth || '200' +`" />
<meta property="og:image:height" content="`+ imageHeight || '200' +`" />
</head>
<body>
</body>
</html>`;
res.set('Content-Type', 'text/html');
res.send(new Buffer(result));
}
function getSermonMeta(req, res, id){
dbSermons.getSermon(id,function(error,sermon){
if (error){