spee.ch/server/controllers/pages/sendVideoEmbedPage.js

88 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-11-02 09:45:35 +01:00
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);
2018-03-29 18:48:32 +02:00
// test setting response headers
console.log('removing x-frame-options');
res.removeHeader('X-Frame-Options');
2018-03-29 20:40:47 +02:00
// get and render the content
2018-11-02 09:45:35 +01:00
res.status(200).render('embed', { host, claimId, name, logoConfig });
2018-03-29 18:48:32 +02:00
};
2018-06-26 04:04:17 +02:00
module.exports = sendVideoEmbedPage;