Other sharing changes to pull from json

test
dan 2020-03-30 19:10:41 -06:00
parent 8b3fafd7f0
commit ea85959a14
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,6 @@
var express = require('express');
var router = express.Router();
var http = require('https');
var dbSermons = require('../../database/sermons');
var dbEvents = require('../../database/events');
@ -9,6 +10,7 @@ const eventUrl = '/api2/share/e';
const sermonImageUrl = '/assets/images/tiny/facebookplay.png';
const sermonUrl = '/api2/share/s';
const otherUrl = '/api2/share/o';
const shareFolder = '/assets/share/';
router.get("/:shareCode",function(req,res){
@ -31,8 +33,13 @@ router.get("/:shareCode",function(req,res){
});
function getOther(req, res, param) {
param = decodeURIComponent(param);
var params = JSON.parse(param);
const jsonPath = req.protocol + '://' + req.hostname + shareFolder + param + '.json';
http.get(jsonPath, resp => {
processOtherJson(req, res, JSON.parse(resp));
});
}
function processOtherJson(req, res, json) {
var userAgent = req.headers['user-agent'];
var userAgentOverride = req.headers['user-agent-override'];
var referrer = req.headers['referer'] || "";
@ -41,9 +48,9 @@ function getOther(req, res, param) {
userAgent === 'Facebot' ||
userAgent.startsWith('Twitterbot') ||
referrer.startsWith('http://opengraphcheck.com')) {
getOtherMeta(req, res, params.title, params.description, params.imageUrl, params.imageWidth, params.imageHeight);
getOtherMeta(req, res, json.title, json.description, json.imageUrl, json.imageWidth, json.imageHeight);
} else {
var url = params.url || (req.protocol + "://" + req.hostname + req.originalUrl);
var url = json.url || (req.protocol + "://" + req.hostname + req.originalUrl);
res.redirect(url);
}
}