From d6d11ea80748b445d61dc919a719c617203682ab Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 13 Dec 2017 18:30:09 -0800 Subject: [PATCH] added check for browser request --- helpers/handlebarsHelpers.js | 32 ++++++++++++++++---------------- routes/serve-routes.js | 12 +++++++----- views/layouts/channel.handlebars | 12 ++++++------ views/layouts/main.handlebars | 12 ++++++------ 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js index d2258e03..a2118b61 100644 --- a/helpers/handlebarsHelpers.js +++ b/helpers/handlebarsHelpers.js @@ -17,27 +17,27 @@ module.exports = { return new Handlebars.SafeString(gaCode); }, addOpenGraph ({ ogTitle, contentType, ogDescription, thumbnail, showUrl, source, ogThumbnailContentType }) { - const ogTitleTag = ``; - const ogUrlTag = ``; - const ogSiteNameTag = ``; - const ogDescriptionTag = ``; - const ogImageWidthTag = ''; - const ogImageHeightTag = ''; + const ogTitleTag = ``; + const ogUrlTag = ``; + const ogSiteNameTag = ``; + const ogDescriptionTag = ``; + const ogImageWidthTag = ''; + const ogImageHeightTag = ''; const basicTags = `${ogTitleTag} ${ogUrlTag} ${ogSiteNameTag} ${ogDescriptionTag} ${ogImageWidthTag} ${ogImageHeightTag}`; - let ogImageTag = ``; - let ogImageTypeTag = ``; - let ogTypeTag = ``; + let ogImageTag = ``; + let ogImageTypeTag = ``; + let ogTypeTag = ``; if (contentType === 'video/mp4') { - const ogVideoTag = ``; - const ogVideoSecureUrlTag = ``; - const ogVideoTypeTag = ``; - ogImageTag = ``; - ogImageTypeTag = ``; - ogTypeTag = ``; + const ogVideoTag = ``; + const ogVideoSecureUrlTag = ``; + const ogVideoTypeTag = ``; + ogImageTag = ``; + ogImageTypeTag = ``; + ogTypeTag = ``; return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag} ${ogVideoTag} ${ogVideoSecureUrlTag} ${ogVideoTypeTag}`); } else { if (contentType === 'image/gif') { - ogTypeTag = ``; + ogTypeTag = ``; }; return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag}`); } diff --git a/routes/serve-routes.js b/routes/serve-routes.js index cbefd64c..9098d6da 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -48,11 +48,13 @@ function clientAcceptsHtml ({accept}) { return accept && accept.match(/text\/html/); } +function requestIsFromBrowser (headers) { + return headers['user-agent'] && headers['user-agent'].match(/Mozilla/); +}; + function clientWantsAsset ({accept, range}) { const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); - const videoIsWanted = false; // accept && range; - logger.debug('image is wanted:', imageIsWanted); - logger.debug('video is wanted:', videoIsWanted); + const videoIsWanted = accept && range; return imageIsWanted || videoIsWanted; } @@ -65,8 +67,8 @@ function determineResponseType (isServeRequest, headers) { } } else { responseType = SHOW; - if (clientWantsAsset(headers)) { // this is in case someone embeds a show url - logger.debug('Show request actually want\'s an asset!'); + if (clientWantsAsset(headers) && requestIsFromBrowser(headers)) { // this is in case someone embeds a show url + logger.debug('Show request actually wants an asset!'); responseType = SERVE; } } diff --git a/views/layouts/channel.handlebars b/views/layouts/channel.handlebars index c2832136..1088d728 100644 --- a/views/layouts/channel.handlebars +++ b/views/layouts/channel.handlebars @@ -4,12 +4,12 @@ {{ placeCommonHeaderTags }} - - - - - - + + + + + + diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 782143fe..276b0033 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -4,12 +4,12 @@ {{ placeCommonHeaderTags }} - - - - - - + + + + + +