From 57558111bc82baaeb2ed72fcf9a4838163bbb7dd Mon Sep 17 00:00:00 2001 From: Shawn Date: Fri, 2 Nov 2018 03:45:35 -0500 Subject: [PATCH 1/3] Make configurable embeds --- .../controllers/pages/sendVideoEmbedPage.js | 84 +++++++++++++++++-- server/routes/pages/index.js | 2 +- server/views/embed.handlebars | 7 +- server/views/layouts/embed.handlebars | 46 +++++++--- server/views/partials/logo.handlebars | 5 ++ 5 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 server/views/partials/logo.handlebars diff --git a/server/controllers/pages/sendVideoEmbedPage.js b/server/controllers/pages/sendVideoEmbedPage.js index 79d7eefa..78424d11 100644 --- a/server/controllers/pages/sendVideoEmbedPage.js +++ b/server/controllers/pages/sendVideoEmbedPage.js @@ -1,13 +1,87 @@ -const { details: { host } } = require('@config/siteConfig'); +const { + assetDefaults: { thumbnail }, + details: { host }, +} = require('@config/siteConfig'); + +const padSizes = { + small: 'padSmall', + medium: 'padMedium', + large: 'padLarge', +}; + +const argumentProcessors = { + 'bottom': async (config) => { + config.classNames.push('bottom'); + return; + }, + 'right': async (config) => { + config.classNames.push('right'); + return; + }, + 'pad': async (config, val) => { + config.classNames.push(padSizes[val]); + return; + }, + 'logoClaim': async (config, val) => { + config.logoUrl = `${host}/${val}`; + return; + }, + 'link': async (config, val) => { + config.logoLink = val; + return; + } +}; + +const parseLogoConfigParam = async (rawConfig) => { + if(rawConfig) { + let parsedConfig = { + classNames: ['logoLink'], + logoUrl: thumbnail, + }; + let splitConfig; + try { + splitConfig = rawConfig.split(','); + } catch(e) { } + + if(!splitConfig) { + return false; + } + + for(let i = 0; i < splitConfig.length; i++) { + let currentArgument = splitConfig[i]; + + if(argumentProcessors[currentArgument]) { + await argumentProcessors[currentArgument](parsedConfig); + } else { + const splitArgument = currentArgument.split(':'); + if(argumentProcessors[splitArgument[0]]) { + await argumentProcessors[splitArgument[0]](parsedConfig, splitArgument[1]); + } + } + } + + parsedConfig.classNames = parsedConfig.classNames.join(' '); + + return parsedConfig; + } + + return false; +} + +const sendVideoEmbedPage = async ({ params }, res) => { + const { + claimId, + config, + name, + } = params; + + const logoConfig = await parseLogoConfigParam(config); -const sendVideoEmbedPage = ({ params }, res) => { - const claimId = params.claimId; - const name = params.name; // test setting response headers console.log('removing x-frame-options'); res.removeHeader('X-Frame-Options'); // get and render the content - res.status(200).render('embed', { host, claimId, name }); + res.status(200).render('embed', { host, claimId, name, logoConfig }); }; module.exports = sendVideoEmbedPage; diff --git a/server/routes/pages/index.js b/server/routes/pages/index.js index 30f84a32..fc742b42 100644 --- a/server/routes/pages/index.js +++ b/server/routes/pages/index.js @@ -16,5 +16,5 @@ module.exports = { '/popular': { controller: handlePageRequest }, '/new': { controller: handlePageRequest }, '/multisite': { controller: handlePageRequest }, - '/video-embed/:name/:claimId': { controller: handleVideoEmbedRequest }, // for twitter + '/video-embed/:name/:claimId/:config?': { controller: handleVideoEmbedRequest }, // for twitter }; diff --git a/server/views/embed.handlebars b/server/views/embed.handlebars index 6b1a4ed6..5dd2f283 100644 --- a/server/views/embed.handlebars +++ b/server/views/embed.handlebars @@ -1,4 +1,7 @@ -`} + value={``} /> ) : (