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

90 lines
2 KiB
JavaScript
Raw Normal View History

2018-11-02 09:45:35 +01:00
const {
assetDefaults: { thumbnail },
details: { host },
} = require('@config/siteConfig');
const padSizes = {
2018-11-11 01:11:12 +01:00
small : 'padSmall',
2018-11-02 09:45:35 +01:00
medium: 'padMedium',
2018-11-11 01:11:12 +01:00
large : 'padLarge',
2018-11-02 09:45:35 +01:00
};
const argumentProcessors = {
'bottom': async (config) => {
config.classNames.push('bottom');
},
'right': async (config) => {
config.classNames.push('right');
},
'pad': async (config, val) => {
config.classNames.push(padSizes[val]);
},
'logoClaim': async (config, val) => {
config.logoUrl = `${host}/${val}`;
},
'link': async (config, val) => {
config.logoLink = val;
2018-11-11 01:11:12 +01:00
},
2018-11-02 09:45:35 +01:00
};
const parseLogoConfigParam = async (rawConfig) => {
2018-11-11 01:11:12 +01:00
if (rawConfig) {
2018-11-02 09:45:35 +01:00
let parsedConfig = {
classNames: ['logoLink'],
2018-11-11 01:11:12 +01:00
logoUrl : thumbnail,
2018-11-02 09:45:35 +01:00
};
let splitConfig;
try {
splitConfig = rawConfig.split(',');
2018-11-11 01:11:12 +01:00
} catch (e) { }
2018-11-02 09:45:35 +01:00
2018-11-11 01:11:12 +01:00
if (!splitConfig) {
2018-11-02 09:45:35 +01:00
return false;
}
2018-11-11 01:11:12 +01:00
for (let i = 0; i < splitConfig.length; i++) {
2018-11-02 09:45:35 +01:00
let currentArgument = splitConfig[i];
2018-11-11 01:11:12 +01:00
if (argumentProcessors[currentArgument]) {
2018-11-02 09:45:35 +01:00
await argumentProcessors[currentArgument](parsedConfig);
} else {
const splitArgument = currentArgument.split(':');
2018-11-11 01:11:12 +01:00
if (argumentProcessors[splitArgument[0]]) {
2018-11-02 09:45:35 +01:00
await argumentProcessors[splitArgument[0]](parsedConfig, splitArgument[1]);
}
}
}
parsedConfig.classNames = parsedConfig.classNames.join(' ');
return parsedConfig;
}
return false;
2018-11-11 01:11:12 +01:00
};
2018-11-02 09:45:35 +01:00
const sendVideoEmbedPage = async ({ params }, res) => {
2018-11-05 16:26:59 +01:00
let {
2018-11-02 09:45:35 +01:00
claimId,
config,
name,
} = params;
2018-11-05 16:26:59 +01:00
// if channel then swap name and claimId for order
if (name[0] === '@' && name.includes(':')) {
const temp = name;
name = claimId;
claimId = temp;
}
2018-11-02 09:45:35 +01:00
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;