From 87acd65d2df0a0aaacf4ef9f195855bf9546e0ae Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 22 Jun 2018 15:28:35 -0700 Subject: [PATCH 01/10] commented out social bot list check --- .../assets/utils/determineResponseType.js | 22 +++++++++++++++++++ server/routes/api/index.js | 2 +- test/test.html | 21 ++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/test.html diff --git a/server/controllers/assets/utils/determineResponseType.js b/server/controllers/assets/utils/determineResponseType.js index f32a0c5c..2592ffed 100644 --- a/server/controllers/assets/utils/determineResponseType.js +++ b/server/controllers/assets/utils/determineResponseType.js @@ -3,6 +3,22 @@ const logger = require('winston'); const SERVE = 'SERVE'; const SHOW = 'SHOW'; +function headersMatchesSocialBotList (headers) { + const socialBotList = [ + 'facebookexternalhit', + 'Twitterbot', + ]; + const userAgent = headers['user-agent']; + for (let i = 0; i < socialBotList.length; i++) { + const socialBot = socialBotList[i]; + if (userAgent.indexOf(socialBot) >= 0) { + logger.debug('headers on request matched this bot:', socialBot); + return true; + } + } + return false; +} + function clientAcceptsHtml ({accept}) { return accept && accept.match(/text\/html/); }; @@ -19,6 +35,12 @@ function clientWantsAsset ({accept, range}) { const determineResponseType = (hasFileExtension, headers) => { let responseType; + logger.debug('headers:', headers); + // return early with 'show' if headers match the list + if (headersMatchesSocialBotList(headers)) { + // return SHOW; + } + // fallback logic if not on the list if (hasFileExtension) { responseType = SERVE; // assume a serve request if file extension is present if (clientAcceptsHtml(headers)) { // if the request comes from a browser, change it to a show request diff --git a/server/routes/api/index.js b/server/routes/api/index.js index 0aabd472..97909fd8 100644 --- a/server/routes/api/index.js +++ b/server/routes/api/index.js @@ -28,7 +28,7 @@ module.exports = (app) => { app.get('/api/claim/data/:claimName/:claimId', claimData); app.get('/api/claim/get/:name/:claimId', claimGet); app.get('/api/claim/list/:name', claimList); - app.post('/api/claim/long-id', claimLongId); + app.post('/api/claim/long-id', claimLongId); // should be a get app.post('/api/claim/publish', multipartMiddleware, claimPublish); app.get('/api/claim/resolve/:name/:claimId', claimResolve); app.get('/api/claim/short-id/:longId/:name', claimShortId); diff --git a/test/test.html b/test/test.html new file mode 100644 index 00000000..01a5d622 --- /dev/null +++ b/test/test.html @@ -0,0 +1,21 @@ + + + + + + + Document + + + test embed +

no identifier, no ending

+ no identifier, no ending +

no identifier, yes ending

+ no identifier, yes ending +

yes identifier, no ending

+ yes identifier, no ending +

yes identifier, yes ending

+ yes identifier, yes ending + + From 1b1ebb1b7c9f0930f4509bf85ab5f0727db7db0e Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 15:01:50 -0700 Subject: [PATCH 02/10] updated the constants used for determining request type --- .../assets/constants/request_types.js | 9 ++++++ .../assets/serveByIdentifierAndClaim/index.js | 13 ++++---- ...esponseType.js => determineRequestType.js} | 30 ++++++++++--------- 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 server/controllers/assets/constants/request_types.js rename server/controllers/assets/utils/{determineResponseType.js => determineRequestType.js} (65%) diff --git a/server/controllers/assets/constants/request_types.js b/server/controllers/assets/constants/request_types.js new file mode 100644 index 00000000..22f0d0ce --- /dev/null +++ b/server/controllers/assets/constants/request_types.js @@ -0,0 +1,9 @@ +const EMBED = 'EMBED'; +const BROWSER = 'BROWSER'; +const SOCIAL = 'SOCIAL'; + +module.exports = { + EMBED, + BROWSER, + SOCIAL, +}; diff --git a/server/controllers/assets/serveByIdentifierAndClaim/index.js b/server/controllers/assets/serveByIdentifierAndClaim/index.js index e493e01e..0caf3a76 100644 --- a/server/controllers/assets/serveByIdentifierAndClaim/index.js +++ b/server/controllers/assets/serveByIdentifierAndClaim/index.js @@ -3,12 +3,12 @@ const handleShowRender = require('../../../render/build/handleShowRender.js'); const lbryUri = require('../utils/lbryUri.js'); -const determineResponseType = require('../utils/determineResponseType.js'); +const determineRequestType = require('../utils/determineRequestType.js'); const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); const flipClaimNameAndId = require('../utils/flipClaimNameAndId.js'); const logRequestData = require('../utils/logRequestData.js'); -const SERVE = 'SERVE'; +const { BROWSER, SOCIAL } = require('../constants/request_types.js'); /* @@ -25,10 +25,13 @@ const serverAssetByIdentifierAndClaim = (req, res) => { } catch (error) { return res.status(400).json({success: false, message: error.message}); } - let responseType = determineResponseType(hasFileExtension, headers); - if (responseType !== SERVE) { + let requestType = determineRequestType(hasFileExtension, headers); + if (requestType == BROWSER) { return handleShowRender(req, res); } + if (requestType == SOCIAL) { + return handleSocialRequest(req, res); + } // handle serve request // send google analytics sendGAServeEvent(headers, ip, originalUrl); @@ -51,7 +54,7 @@ const serverAssetByIdentifierAndClaim = (req, res) => { [claimId, claimName] = flipClaimNameAndId(claimId, claimName); } // log the request data for debugging - logRequestData(responseType, claimName, channelName, claimId); + logRequestData(requestType, claimName, channelName, claimId); // get the claim Id and then serve the asset getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res); }; diff --git a/server/controllers/assets/utils/determineResponseType.js b/server/controllers/assets/utils/determineRequestType.js similarity index 65% rename from server/controllers/assets/utils/determineResponseType.js rename to server/controllers/assets/utils/determineRequestType.js index 2592ffed..c268380f 100644 --- a/server/controllers/assets/utils/determineResponseType.js +++ b/server/controllers/assets/utils/determineRequestType.js @@ -1,7 +1,5 @@ const logger = require('winston'); - -const SERVE = 'SERVE'; -const SHOW = 'SHOW'; +const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js'); function headersMatchesSocialBotList (headers) { const socialBotList = [ @@ -33,27 +31,31 @@ function clientWantsAsset ({accept, range}) { return imageIsWanted || videoIsWanted; }; -const determineResponseType = (hasFileExtension, headers) => { +const determineRequestType = (hasFileExtension, headers) => { let responseType; logger.debug('headers:', headers); // return early with 'show' if headers match the list if (headersMatchesSocialBotList(headers)) { - // return SHOW; + return SOCIAL; } - // fallback logic if not on the list + // if request is not from a social bot... if (hasFileExtension) { - responseType = SERVE; // assume a serve request if file extension is present - if (clientAcceptsHtml(headers)) { // if the request comes from a browser, change it to a show request - responseType = SHOW; + // assume embed, + responseType = EMBED; + // but change to browser if client accepts html. + if (clientAcceptsHtml(headers)) { + responseType = BROWSER; } + // if request does not have file extentsion... } else { - responseType = SHOW; - if (clientWantsAsset(headers) && requestIsFromBrowser(headers)) { // this is in case someone embeds a show url - logger.debug('Show request came from browser but wants an image/video. Changing response to serve...'); - responseType = SERVE; + // assume browser, + responseType = BROWSER; + // but change to embed if someone embeded a show url... + if (clientWantsAsset(headers) && requestIsFromBrowser(headers)) { + responseType = EMBED; } } return responseType; }; -module.exports = determineResponseType; +module.exports = determineRequestType; From a8cfbd3c9e2d0cf816752cc8fe05f83d3bf0c244 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 18:42:30 -0700 Subject: [PATCH 03/10] added a direct serve route --- server/controllers/assets/serveAsset/index.js | 20 +++++++++++++++++++ .../controllers/assets/serveByClaim/index.js | 20 +++++++++---------- .../assets/serveByIdentifierAndClaim/index.js | 19 ++++++++---------- server/routes/assets/index.js | 12 ++++++----- server/routes/pages/index.js | 4 ++-- 5 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 server/controllers/assets/serveAsset/index.js diff --git a/server/controllers/assets/serveAsset/index.js b/server/controllers/assets/serveAsset/index.js new file mode 100644 index 00000000..677ea8be --- /dev/null +++ b/server/controllers/assets/serveAsset/index.js @@ -0,0 +1,20 @@ +const { sendGAServeEvent } = require('../../../utils/googleAnalytics'); +const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); +const logRequestData = require('../utils/logRequestData.js'); + +/* + + route to serve an asset directly + +*/ + +const serveAsset = ({ headers, ip, originalUrl, params: { claimName, claimId } }, res) => { + // send google analytics + sendGAServeEvent(headers, ip, originalUrl); + // log the request data for debugging + logRequestData(null, claimName, null, claimId); + // get the claim Id and then serdve the asset + getClaimIdAndServeAsset(null, null, claimName, claimId, originalUrl, ip, res); +}; + +module.exports = serveAsset; diff --git a/server/controllers/assets/serveByClaim/index.js b/server/controllers/assets/serveByClaim/index.js index a561754e..93645561 100644 --- a/server/controllers/assets/serveByClaim/index.js +++ b/server/controllers/assets/serveByClaim/index.js @@ -3,11 +3,11 @@ const handleShowRender = require('../../../render/build/handleShowRender.js'); const lbryUri = require('../utils/lbryUri.js'); -const determineResponseType = require('../utils/determineResponseType.js'); +const determineRequestType = require('../utils/determineRequestType.js'); const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); const logRequestData = require('../utils/logRequestData.js'); -const SERVE = 'SERVE'; +const { EMBED } = require('../constants/request_types.js'); /* @@ -15,7 +15,7 @@ const SERVE = 'SERVE'; */ -const serverAssetByClaim = (req, res) => { +const serveByClaim = (req, res) => { const { headers, ip, originalUrl, params } = req; // decide if this is a show request let hasFileExtension; @@ -24,13 +24,11 @@ const serverAssetByClaim = (req, res) => { } catch (error) { return res.status(400).json({success: false, message: error.message}); } - let responseType = determineResponseType(hasFileExtension, headers); - if (responseType !== SERVE) { + // determine request type + let requestType = determineRequestType(hasFileExtension, headers); + if (requestType !== EMBED) { return handleShowRender(req, res); } - // handle serve request - // send google analytics - sendGAServeEvent(headers, ip, originalUrl); // parse the claim let claimName; try { @@ -38,10 +36,12 @@ const serverAssetByClaim = (req, res) => { } catch (error) { return res.status(400).json({success: false, message: error.message}); } + // send google analytics + sendGAServeEvent(headers, ip, originalUrl); // log the request data for debugging - logRequestData(responseType, claimName, null, null); + logRequestData(requestType, claimName, null, null); // get the claim Id and then serve the asset getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res); }; -module.exports = serverAssetByClaim; +module.exports = serveByClaim; diff --git a/server/controllers/assets/serveByIdentifierAndClaim/index.js b/server/controllers/assets/serveByIdentifierAndClaim/index.js index 0caf3a76..a2d67cfa 100644 --- a/server/controllers/assets/serveByIdentifierAndClaim/index.js +++ b/server/controllers/assets/serveByIdentifierAndClaim/index.js @@ -8,7 +8,7 @@ const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); const flipClaimNameAndId = require('../utils/flipClaimNameAndId.js'); const logRequestData = require('../utils/logRequestData.js'); -const { BROWSER, SOCIAL } = require('../constants/request_types.js'); +const { EMBED } = require('../constants/request_types.js'); /* @@ -16,25 +16,20 @@ const { BROWSER, SOCIAL } = require('../constants/request_types.js'); */ -const serverAssetByIdentifierAndClaim = (req, res) => { +const serverByIdentifierAndClaim = (req, res) => { const { headers, ip, originalUrl, params } = req; - // decide if this is a show request + // parse request let hasFileExtension; try { ({ hasFileExtension } = lbryUri.parseModifier(params.claim)); } catch (error) { return res.status(400).json({success: false, message: error.message}); } + // determine request type let requestType = determineRequestType(hasFileExtension, headers); - if (requestType == BROWSER) { + if (requestType !== EMBED) { return handleShowRender(req, res); } - if (requestType == SOCIAL) { - return handleSocialRequest(req, res); - } - // handle serve request - // send google analytics - sendGAServeEvent(headers, ip, originalUrl); // parse the claim let claimName; try { @@ -53,10 +48,12 @@ const serverAssetByIdentifierAndClaim = (req, res) => { if (!isChannel) { [claimId, claimName] = flipClaimNameAndId(claimId, claimName); } + // send google analytics + sendGAServeEvent(headers, ip, originalUrl); // log the request data for debugging logRequestData(requestType, claimName, channelName, claimId); // get the claim Id and then serve the asset getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res); }; -module.exports = serverAssetByIdentifierAndClaim; +module.exports = serverByIdentifierAndClaim; diff --git a/server/routes/assets/index.js b/server/routes/assets/index.js index 4e87d2dd..5d4f92d1 100644 --- a/server/routes/assets/index.js +++ b/server/routes/assets/index.js @@ -1,7 +1,9 @@ -const serveAssetByClaim = require('../../controllers/assets/serveByClaim'); -const serveAssetByIdentifierAndClaim = require('../../controllers/assets/serveByIdentifierAndClaim'); +const serveByClaim = require('../../controllers/assets/serveByClaim'); +const serveByIdentifierAndClaim = require('../../controllers/assets/serveByIdentifierAndClaim'); +const serveAsset = require('../../controllers/assets/serveAsset'); -module.exports = (app, db) => { - app.get('/:identifier/:claim', serveAssetByIdentifierAndClaim); - app.get('/:claim', serveAssetByClaim); +module.exports = (app) => { + app.get('/asset/:claimName/:claimId/', serveAsset); + app.get('/:identifier/:claim', serveByIdentifierAndClaim); + app.get('/:claim', serveByClaim); }; diff --git a/server/routes/pages/index.js b/server/routes/pages/index.js index 2c62b1aa..225fa725 100644 --- a/server/routes/pages/index.js +++ b/server/routes/pages/index.js @@ -1,5 +1,5 @@ const handlePageRequest = require('../../controllers/pages/sendReactApp'); -const handleEmbedRequest = require('../../controllers/pages/sendEmbedPage'); +// const handleEmbedRequest = require('../../controllers/pages/sendEmbedPage'); const redirect = require('../../controllers/utils/redirect'); module.exports = (app) => { @@ -10,5 +10,5 @@ module.exports = (app) => { app.get('/popular', handlePageRequest); app.get('/new', handlePageRequest); app.get('/multisite', handlePageRequest); - app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter) + // app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter) }; From 6ee72dabbbdaa6085e166c072a6ef823759178a8 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 18:51:54 -0700 Subject: [PATCH 04/10] commented out logs --- server/controllers/assets/serveAsset/index.js | 4 ++-- server/controllers/assets/serveByClaim/index.js | 2 +- server/controllers/assets/serveByIdentifierAndClaim/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/controllers/assets/serveAsset/index.js b/server/controllers/assets/serveAsset/index.js index 677ea8be..cb629a76 100644 --- a/server/controllers/assets/serveAsset/index.js +++ b/server/controllers/assets/serveAsset/index.js @@ -12,8 +12,8 @@ const serveAsset = ({ headers, ip, originalUrl, params: { claimName, claimId } } // send google analytics sendGAServeEvent(headers, ip, originalUrl); // log the request data for debugging - logRequestData(null, claimName, null, claimId); - // get the claim Id and then serdve the asset + // logRequestData(null, claimName, null, claimId); + // get the claim Id and then serve the asset getClaimIdAndServeAsset(null, null, claimName, claimId, originalUrl, ip, res); }; diff --git a/server/controllers/assets/serveByClaim/index.js b/server/controllers/assets/serveByClaim/index.js index 93645561..2ec698b4 100644 --- a/server/controllers/assets/serveByClaim/index.js +++ b/server/controllers/assets/serveByClaim/index.js @@ -39,7 +39,7 @@ const serveByClaim = (req, res) => { // send google analytics sendGAServeEvent(headers, ip, originalUrl); // log the request data for debugging - logRequestData(requestType, claimName, null, null); + // logRequestData(requestType, claimName, null, null); // get the claim Id and then serve the asset getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res); }; diff --git a/server/controllers/assets/serveByIdentifierAndClaim/index.js b/server/controllers/assets/serveByIdentifierAndClaim/index.js index a2d67cfa..0089610d 100644 --- a/server/controllers/assets/serveByIdentifierAndClaim/index.js +++ b/server/controllers/assets/serveByIdentifierAndClaim/index.js @@ -51,7 +51,7 @@ const serverByIdentifierAndClaim = (req, res) => { // send google analytics sendGAServeEvent(headers, ip, originalUrl); // log the request data for debugging - logRequestData(requestType, claimName, channelName, claimId); + // logRequestData(requestType, claimName, channelName, claimId); // get the claim Id and then serve the asset getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res); }; From 824b5b4c827101e81f18d52b06fc789437225ab1 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 19:04:17 -0700 Subject: [PATCH 05/10] updated seo tags to match routes --- client/src/utils/metaTags.js | 6 +++--- .../pages/{sendEmbedPage.js => sendVideoEmbedPage.js} | 4 ++-- server/routes/pages/index.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename server/controllers/pages/{sendEmbedPage.js => sendVideoEmbedPage.js} (73%) diff --git a/client/src/utils/metaTags.js b/client/src/utils/metaTags.js index cd11b853..2210e5de 100644 --- a/client/src/utils/metaTags.js +++ b/client/src/utils/metaTags.js @@ -46,9 +46,9 @@ const createChannelMetaTags = ({siteHost, siteTitle, siteTwitter, channel}) => { const createAssetMetaTags = ({siteHost, siteTitle, siteTwitter, asset, defaultDescription, defaultThumbnail}) => { const { claimData } = asset; const { contentType } = claimData; - const embedUrl = `${siteHost}/${claimData.claimId}/${claimData.name}`; + const videoEmbedUrl = `${siteHost}/video-embed/${claimData.name}/${claimData.claimId}`; const showUrl = `${siteHost}/${claimData.claimId}/${claimData.name}`; - const source = `${siteHost}/${claimData.claimId}/${claimData.name}.${claimData.fileExt}`; + const source = `${siteHost}/asset/${claimData.name}/${claimData.claimId}}`; const ogTitle = claimData.title || claimData.name; const ogDescription = claimData.description || defaultDescription; const ogThumbnailContentType = determineOgThumbnailContentType(claimData.thumbnail); @@ -70,7 +70,7 @@ const createAssetMetaTags = ({siteHost, siteTitle, siteTwitter, asset, defaultDe metaTags.push({property: 'og:image:type', content: ogThumbnailContentType}); metaTags.push({property: 'og:type', content: 'video'}); metaTags.push({property: 'twitter:card', content: 'player'}); - metaTags.push({property: 'twitter:player', content: embedUrl}); + metaTags.push({property: 'twitter:player', content: videoEmbedUrl}); metaTags.push({property: 'twitter:player:width', content: 600}); metaTags.push({property: 'twitter:text:player_width', content: 600}); metaTags.push({property: 'twitter:player:height', content: 337}); diff --git a/server/controllers/pages/sendEmbedPage.js b/server/controllers/pages/sendVideoEmbedPage.js similarity index 73% rename from server/controllers/pages/sendEmbedPage.js rename to server/controllers/pages/sendVideoEmbedPage.js index d4bef437..01f6b1f4 100644 --- a/server/controllers/pages/sendEmbedPage.js +++ b/server/controllers/pages/sendVideoEmbedPage.js @@ -1,10 +1,10 @@ const { details: { host } } = require('@config/siteConfig'); -const sendEmbedPage = ({ params }, res) => { +const sendVideoEmbedPage = ({ params }, res) => { const claimId = params.claimId; const name = params.name; // get and render the content res.status(200).render('embed', { layout: 'embed', host, claimId, name }); }; -module.exports = sendEmbedPage; +module.exports = sendVideoEmbedPage; diff --git a/server/routes/pages/index.js b/server/routes/pages/index.js index 225fa725..2dff606b 100644 --- a/server/routes/pages/index.js +++ b/server/routes/pages/index.js @@ -1,5 +1,5 @@ const handlePageRequest = require('../../controllers/pages/sendReactApp'); -// const handleEmbedRequest = require('../../controllers/pages/sendEmbedPage'); +const handleVideoEmbedRequest = require('../../controllers/pages/sendVideoEmbedPage'); const redirect = require('../../controllers/utils/redirect'); module.exports = (app) => { @@ -10,5 +10,5 @@ module.exports = (app) => { app.get('/popular', handlePageRequest); app.get('/new', handlePageRequest); app.get('/multisite', handlePageRequest); - // app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter) + app.get('/video-embed/:name/:claimId', handleVideoEmbedRequest); // for twitter }; From 8f626168943a1234b37de2e8471d30e987389256 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 19:06:10 -0700 Subject: [PATCH 06/10] rebuilt client code --- client/build/utils/metaTags.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/build/utils/metaTags.js b/client/build/utils/metaTags.js index 34daa9e0..473150c1 100644 --- a/client/build/utils/metaTags.js +++ b/client/build/utils/metaTags.js @@ -101,9 +101,9 @@ var createAssetMetaTags = function createAssetMetaTags(_ref3) { defaultThumbnail = _ref3.defaultThumbnail; var claimData = asset.claimData; var contentType = claimData.contentType; - var embedUrl = "".concat(siteHost, "/").concat(claimData.claimId, "/").concat(claimData.name); + var videoEmbedUrl = "".concat(siteHost, "/video-embed/").concat(claimData.name, "/").concat(claimData.claimId); var showUrl = "".concat(siteHost, "/").concat(claimData.claimId, "/").concat(claimData.name); - var source = "".concat(siteHost, "/").concat(claimData.claimId, "/").concat(claimData.name, ".").concat(claimData.fileExt); + var source = "".concat(siteHost, "/asset/").concat(claimData.name, "/").concat(claimData.claimId, "}"); var ogTitle = claimData.title || claimData.name; var ogDescription = claimData.description || defaultDescription; var ogThumbnailContentType = determineOgThumbnailContentType(claimData.thumbnail); @@ -162,7 +162,7 @@ var createAssetMetaTags = function createAssetMetaTags(_ref3) { }); metaTags.push({ property: 'twitter:player', - content: embedUrl + content: videoEmbedUrl }); metaTags.push({ property: 'twitter:player:width', From ca22bbb0ccf762f84cf7fb66aca912b6fef897f2 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 23:30:21 -0700 Subject: [PATCH 07/10] fixed extra semicolon in meta tags --- client/build/utils/metaTags.js | 2 +- client/src/utils/metaTags.js | 2 +- server/controllers/assets/serveAsset/index.js | 3 --- server/controllers/assets/serveByClaim/index.js | 3 --- server/controllers/assets/serveByIdentifierAndClaim/index.js | 3 --- server/controllers/assets/utils/getClaimIdAndServeAsset.js | 1 + 6 files changed, 3 insertions(+), 11 deletions(-) diff --git a/client/build/utils/metaTags.js b/client/build/utils/metaTags.js index 473150c1..eee75ef8 100644 --- a/client/build/utils/metaTags.js +++ b/client/build/utils/metaTags.js @@ -103,7 +103,7 @@ var createAssetMetaTags = function createAssetMetaTags(_ref3) { var contentType = claimData.contentType; var videoEmbedUrl = "".concat(siteHost, "/video-embed/").concat(claimData.name, "/").concat(claimData.claimId); var showUrl = "".concat(siteHost, "/").concat(claimData.claimId, "/").concat(claimData.name); - var source = "".concat(siteHost, "/asset/").concat(claimData.name, "/").concat(claimData.claimId, "}"); + var source = "".concat(siteHost, "/asset/").concat(claimData.name, "/").concat(claimData.claimId); var ogTitle = claimData.title || claimData.name; var ogDescription = claimData.description || defaultDescription; var ogThumbnailContentType = determineOgThumbnailContentType(claimData.thumbnail); diff --git a/client/src/utils/metaTags.js b/client/src/utils/metaTags.js index 2210e5de..b658db30 100644 --- a/client/src/utils/metaTags.js +++ b/client/src/utils/metaTags.js @@ -48,7 +48,7 @@ const createAssetMetaTags = ({siteHost, siteTitle, siteTwitter, asset, defaultDe const { contentType } = claimData; const videoEmbedUrl = `${siteHost}/video-embed/${claimData.name}/${claimData.claimId}`; const showUrl = `${siteHost}/${claimData.claimId}/${claimData.name}`; - const source = `${siteHost}/asset/${claimData.name}/${claimData.claimId}}`; + const source = `${siteHost}/asset/${claimData.name}/${claimData.claimId}`; const ogTitle = claimData.title || claimData.name; const ogDescription = claimData.description || defaultDescription; const ogThumbnailContentType = determineOgThumbnailContentType(claimData.thumbnail); diff --git a/server/controllers/assets/serveAsset/index.js b/server/controllers/assets/serveAsset/index.js index cb629a76..3f0149a8 100644 --- a/server/controllers/assets/serveAsset/index.js +++ b/server/controllers/assets/serveAsset/index.js @@ -1,6 +1,5 @@ const { sendGAServeEvent } = require('../../../utils/googleAnalytics'); const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); -const logRequestData = require('../utils/logRequestData.js'); /* @@ -11,8 +10,6 @@ const logRequestData = require('../utils/logRequestData.js'); const serveAsset = ({ headers, ip, originalUrl, params: { claimName, claimId } }, res) => { // send google analytics sendGAServeEvent(headers, ip, originalUrl); - // log the request data for debugging - // logRequestData(null, claimName, null, claimId); // get the claim Id and then serve the asset getClaimIdAndServeAsset(null, null, claimName, claimId, originalUrl, ip, res); }; diff --git a/server/controllers/assets/serveByClaim/index.js b/server/controllers/assets/serveByClaim/index.js index 2ec698b4..6e0e9e40 100644 --- a/server/controllers/assets/serveByClaim/index.js +++ b/server/controllers/assets/serveByClaim/index.js @@ -5,7 +5,6 @@ const lbryUri = require('../utils/lbryUri.js'); const determineRequestType = require('../utils/determineRequestType.js'); const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); -const logRequestData = require('../utils/logRequestData.js'); const { EMBED } = require('../constants/request_types.js'); @@ -38,8 +37,6 @@ const serveByClaim = (req, res) => { } // send google analytics sendGAServeEvent(headers, ip, originalUrl); - // log the request data for debugging - // logRequestData(requestType, claimName, null, null); // get the claim Id and then serve the asset getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res); }; diff --git a/server/controllers/assets/serveByIdentifierAndClaim/index.js b/server/controllers/assets/serveByIdentifierAndClaim/index.js index 0089610d..609a1256 100644 --- a/server/controllers/assets/serveByIdentifierAndClaim/index.js +++ b/server/controllers/assets/serveByIdentifierAndClaim/index.js @@ -6,7 +6,6 @@ const lbryUri = require('../utils/lbryUri.js'); const determineRequestType = require('../utils/determineRequestType.js'); const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js'); const flipClaimNameAndId = require('../utils/flipClaimNameAndId.js'); -const logRequestData = require('../utils/logRequestData.js'); const { EMBED } = require('../constants/request_types.js'); @@ -50,8 +49,6 @@ const serverByIdentifierAndClaim = (req, res) => { } // send google analytics sendGAServeEvent(headers, ip, originalUrl); - // log the request data for debugging - // logRequestData(requestType, claimName, channelName, claimId); // get the claim Id and then serve the asset getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res); }; diff --git a/server/controllers/assets/utils/getClaimIdAndServeAsset.js b/server/controllers/assets/utils/getClaimIdAndServeAsset.js index e391383d..83c4c770 100644 --- a/server/controllers/assets/utils/getClaimIdAndServeAsset.js +++ b/server/controllers/assets/utils/getClaimIdAndServeAsset.js @@ -17,6 +17,7 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId getClaimId(channelName, channelClaimId, claimName, claimId) .then(fullClaimId => { claimId = fullClaimId; + logger.debug('FULL CLAIM ID:', fullClaimId); return db.Blocked.isNotBlocked(fullClaimId, claimName); }) .then(() => { From 7b6454792b840a8ca732d474aeae01c26086bf54 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Jun 2018 23:47:14 -0700 Subject: [PATCH 08/10] 465-social-share-with-extensions --- client/build/utils/metaTags.js | 2 +- client/src/utils/metaTags.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/build/utils/metaTags.js b/client/build/utils/metaTags.js index eee75ef8..9713f663 100644 --- a/client/build/utils/metaTags.js +++ b/client/build/utils/metaTags.js @@ -154,7 +154,7 @@ var createAssetMetaTags = function createAssetMetaTags(_ref3) { }); metaTags.push({ property: 'og:type', - content: 'video' + content: 'video.other' }); metaTags.push({ property: 'twitter:card', diff --git a/client/src/utils/metaTags.js b/client/src/utils/metaTags.js index b658db30..c5b9df34 100644 --- a/client/src/utils/metaTags.js +++ b/client/src/utils/metaTags.js @@ -68,7 +68,7 @@ const createAssetMetaTags = ({siteHost, siteTitle, siteTwitter, asset, defaultDe metaTags.push({property: 'og:video:type', content: contentType}); metaTags.push({property: 'og:image', content: ogThumbnail}); metaTags.push({property: 'og:image:type', content: ogThumbnailContentType}); - metaTags.push({property: 'og:type', content: 'video'}); + metaTags.push({property: 'og:type', content: 'video.other'}); metaTags.push({property: 'twitter:card', content: 'player'}); metaTags.push({property: 'twitter:player', content: videoEmbedUrl}); metaTags.push({property: 'twitter:player:width', content: 600}); From 88097ab151924461da145e5f53c7e56ea3c82c33 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 27 Jun 2018 09:45:09 -0700 Subject: [PATCH 09/10] used object pattern over array --- .../assets/utils/determineRequestType.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server/controllers/assets/utils/determineRequestType.js b/server/controllers/assets/utils/determineRequestType.js index c268380f..56bfc1ca 100644 --- a/server/controllers/assets/utils/determineRequestType.js +++ b/server/controllers/assets/utils/determineRequestType.js @@ -2,19 +2,17 @@ const logger = require('winston'); const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js'); function headersMatchesSocialBotList (headers) { - const socialBotList = [ - 'facebookexternalhit', - 'Twitterbot', - ]; const userAgent = headers['user-agent']; - for (let i = 0; i < socialBotList.length; i++) { - const socialBot = socialBotList[i]; - if (userAgent.indexOf(socialBot) >= 0) { - logger.debug('headers on request matched this bot:', socialBot); - return true; - } + const socialBotList = { + 'facebookexternalhit': 1, + 'Twitterbot' : 1, + }; + if (socialBotList[userAgent]) { + logger.debug('headers on request matched a social bot.'); + return true; + } else { + return false; } - return false; } function clientAcceptsHtml ({accept}) { From b2053a219e57492a09a5293f1d54cc145d8a28f1 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 27 Jun 2018 09:48:18 -0700 Subject: [PATCH 10/10] simplified if statement --- server/controllers/assets/utils/determineRequestType.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/server/controllers/assets/utils/determineRequestType.js b/server/controllers/assets/utils/determineRequestType.js index 56bfc1ca..4d3ce450 100644 --- a/server/controllers/assets/utils/determineRequestType.js +++ b/server/controllers/assets/utils/determineRequestType.js @@ -7,12 +7,7 @@ function headersMatchesSocialBotList (headers) { 'facebookexternalhit': 1, 'Twitterbot' : 1, }; - if (socialBotList[userAgent]) { - logger.debug('headers on request matched a social bot.'); - return true; - } else { - return false; - } + return socialBotList[userAgent]; } function clientAcceptsHtml ({accept}) {