diff --git a/helpers/serveHelpers.js b/helpers/serveHelpers.js index 2d2aaed8..017d485c 100644 --- a/helpers/serveHelpers.js +++ b/helpers/serveHelpers.js @@ -60,6 +60,15 @@ function checkLocalDbForClaims (name, shortUrl) { }); } +function createOpenGraphInfo ({ fileType, claimId, name, fileName, fileExt }) { + return { + twitterPlayerUrl: `https://spee.ch/twitterPlayer/${claimId}/${name}`, + showUrl : `https://spee.ch/${claimId}/${name}`, + source : `https://spee.ch/${claimId}/${name}${fileExt}`, + directFileUrl : `https://spee.ch/media/${fileName}`, + }; +} + module.exports = { serveFile ({ fileName, fileType, filePath }, res) { logger.info(`serving file ${fileName}`); @@ -86,11 +95,12 @@ module.exports = { res.status(200).sendFile(filePath, options); }, showFile (fileInfo, res) { - res.status(200).render('show', { layout: 'show', fileInfo }); + const openGraphInfo = createOpenGraphInfo(fileInfo); + res.status(200).render('show', { layout: 'show', fileInfo, openGraphInfo }); }, showFileLite (fileInfo, res) { - logger.debug('showing file lite'); - res.status(200).render('showLite', { layout: 'show', fileInfo }); + const openGraphInfo = createOpenGraphInfo(fileInfo); + res.status(200).render('showLite', { layout: 'show', fileInfo, openGraphInfo }); }, getClaimIdFromShortUrl (shortUrl, name) { return new Promise((resolve, reject) => { diff --git a/public/assets/img/content-freedom-large.png b/public/assets/img/content-freedom-large.png new file mode 100644 index 00000000..a352c3c8 Binary files /dev/null and b/public/assets/img/content-freedom-large.png differ diff --git a/routes/page-routes.js b/routes/page-routes.js index d037658f..7907e907 100644 --- a/routes/page-routes.js +++ b/routes/page-routes.js @@ -36,6 +36,14 @@ module.exports = (app) => { }); }); // route to display all free public claims at a given name + app.get('/twitterPlayer/:claimId/:fileName', ({ params }, res) => { + const claimId = params.claimId; + const fileName = params.fileName; + const fileExtension = '.mp4'; + // get and render the content + res.status(200).render('twitterPlayer', { layout: 'twitterPlayer', claimId, fileName, fileExtension }); + }); + // route to display all free public claims at a given name app.get('/:name/all', ({ ip, originalUrl, params }, res) => { // get and render the content getAllFreePublicClaims(params.name) diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 3dd3d8a7..f42bd1c5 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -93,11 +93,7 @@ module.exports = (app) => { method = SERVE; } } else { - if (headers['accept'] && !headers['accept'].split(',').includes('text/html')) { - method = SERVE; - } else { - method = SHOW; - } + method = SHOW; } /* start: temporary patch for backwards compatability spee.ch/name/claim_id */ if (isValidShortUrlOrClaimId(name) && !isValidShortUrlOrClaimId(identifier)) { diff --git a/speech.js b/speech.js index c042e8ea..cc2f0d4b 100644 --- a/speech.js +++ b/speech.js @@ -48,6 +48,58 @@ const hbs = expressHandlebars.create({ ` ); }, + addOpenGraph (title, mimeType, showUrl, source) { + let basicTags = ` + + + `; + if (mimeType === 'video/mp4') { + return new Handlebars.SafeString( + `${basicTags} + + + + + + + ` + ); + } else if (mimeType === 'image/gif') { + return new Handlebars.SafeString( + `${basicTags} + + + + ` + ); + } else { + return new Handlebars.SafeString( + `${basicTags} + + + + ` + ); + } + }, + addTwitterCard (mimeType, source, twitterPlayerUrl, directFileUrl) { + let basicTwitterTags = ``; + if (mimeType === 'video/mp4') { + return new Handlebars.SafeString( + `${basicTwitterTags} + + + + + ` + ); + } else { + return new Handlebars.SafeString( + `${basicTwitterTags} ` + ); + } + }, ifConditional (varOne, operator, varTwo, options) { switch (operator) { case '===': diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index dc6c235c..b972443b 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -1,5 +1,5 @@ - + @@ -7,7 +7,14 @@ Spee.ch - {{ twitterCard }} + + + + + + + + {{{ body }}} diff --git a/views/layouts/show.handlebars b/views/layouts/show.handlebars index a62a2781..15575e9f 100644 --- a/views/layouts/show.handlebars +++ b/views/layouts/show.handlebars @@ -1,5 +1,5 @@ - + @@ -7,17 +7,17 @@ Spee.ch - - - - - - - + + {{{addTwitterCard fileInfo.fileType openGraphInfo.source openGraphInfo.twitterPlayerUrl openGraphInfo.directFileUrl}}} + {{{addOpenGraph fileInfo.name fileInfo.fileType openGraphInfo.showUrl openGraphInfo.source}}} {{{ body }}} {{ googleAnalytics }} - \ No newline at end of file + + + \ No newline at end of file diff --git a/views/layouts/twitterPlayer.handlebars b/views/layouts/twitterPlayer.handlebars new file mode 100644 index 00000000..1c3f0d44 --- /dev/null +++ b/views/layouts/twitterPlayer.handlebars @@ -0,0 +1,16 @@ + + + + + + +{{{body}}} + + + \ No newline at end of file diff --git a/views/showLite.handlebars b/views/showLite.handlebars index cff1d782..a061259e 100644 --- a/views/showLite.handlebars +++ b/views/showLite.handlebars @@ -6,7 +6,7 @@ {{!--fallback--}} Your browser does not support the video element. - + {{else}} {{fileInfo.fileName}} {{/ifConditional}} diff --git a/views/twitterPlayer.handlebars b/views/twitterPlayer.handlebars new file mode 100644 index 00000000..ec88ee84 --- /dev/null +++ b/views/twitterPlayer.handlebars @@ -0,0 +1 @@ + \ No newline at end of file