Undefined og description #261

Merged
bones7242 merged 4 commits from undefined-og-description into master 2017-11-14 21:40:37 +01:00
2 changed files with 54 additions and 54 deletions

View file

@ -204,7 +204,7 @@ module.exports = {
} else {
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
}
// add stats table
// add a record to the stats table
postToStats(method, originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
// serve or show
switch (method) {
@ -213,8 +213,17 @@ module.exports = {
sendGoogleAnalytics(method, headers, ip, originalUrl);
return fileInfo;
case SHOWLITE:
showFileLite(fileInfo, res);
return fileInfo;
return db.Claim.resolveClaim(fileInfo.name, fileInfo.claimId)
.then(claimRecord => {
fileInfo['title'] = claimRecord.title;
fileInfo['description'] = claimRecord.description;
showFileLite(fileInfo, res);
return fileInfo;
})
.catch(error => {
logger.error('throwing serverOrShowAsset SHOWLITE error...');
throw error;
});
case SHOW:
return db.Claim
.getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name)
@ -233,7 +242,7 @@ module.exports = {
return fileInfo;
})
.catch(error => {
logger.error('throwing serve/show error...');
logger.error('throwing serverOrShowAsset SHOW error...');
throw error;
});
default:

View file

@ -2,71 +2,62 @@ const Handlebars = require('handlebars');
const config = require('../config/speechConfig.js');
module.exports = {
// define any extra helpers you may need
googleAnalytics () {
const googleApiKey = config.analytics.googleId;
return new Handlebars.SafeString(
`<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
const gaCode = `<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '${googleApiKey}', 'auto');
ga('send', 'pageview');
</script>`
);
ga('send', 'pageview');</script>`;
return new Handlebars.SafeString(gaCode);
},
addOpenGraph (title, mimeType, showUrl, source, description, thumbnail) {
let basicTags = `<meta property="og:title" content="${title}">
<meta property="og:url" content="${showUrl}" >
<meta property="og:site_name" content="Spee.ch" >
<meta property="og:description" content="${description}">`;
if (title === null || title.trim() === '') {
kauffj commented 2017-11-10 18:22:33 +01:00 (Migrated from github.com)
Review

Is there a fallback value for this when it is not set?

Is there a fallback value for this when it is not set?
bones7242 commented 2017-11-10 18:27:08 +01:00 (Migrated from github.com)
Review

no there isn't, and you are correct that should be added

no there isn't, and you are correct that should be added
title = 'Spee.ch';
}
if (description === null || description.trim() === '') {
description = 'Open-source, decentralized image and video sharing.';
}
const ogTitle = `<meta property="og:title" content="${title}" >`;
const ogUrl = `<meta property="og:url" content="${showUrl}" >`;
const ogSiteName = `<meta property="og:site_name" content="Spee.ch" >`;
const ogDescription = `<meta property="og:description" content="${description}" >`;
const ogImageWidth = '<meta property="og:image:width" content="600" >';
const ogImageHeight = '<meta property="og:image:height" content="315" >';
const basicTags = `${ogTitle} ${ogUrl} ${ogSiteName} ${ogDescription} ${ogImageWidth} ${ogImageHeight}`;
let ogImage = `<meta property="og:image" content="${source}" >`;
let ogImageType = `<meta property="og:image:type" content="${mimeType}" >`;
let ogType = `<meta property="og:type" content="article" >`;
if (mimeType === 'video/mp4') {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="${thumbnail}" >
<meta property="og:image:type" content="image/png" >
<meta property="og:image:width" content="600" >
<meta property="og:image:height" content="315" >
<meta property="og:type" content="video" >
<meta property="og:video" content="${source}" >
<meta property="og:video:secure_url" content="${source}" >
<meta property="og:video:type" content="${mimeType}" >`
);
} else if (mimeType === 'image/gif') {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="${source}" >
<meta property="og:image:type" content="${mimeType}" >
<meta property="og:image:width" content="600" >
<meta property="og:image:height" content="315" >
<meta property="og:type" content="video.other" >`
);
const ogVideo = `<meta property="og:video" content="${source}" >`;
const ogVideoSecureUrl = `<meta property="og:video:secure_url" content="${source}" >`;
const ogVideoType = `<meta property="og:video:type" content="${mimeType}" >`;
ogImage = `<meta property="og:image" content="${thumbnail}" >`;
ogImageType = `<meta property="og:image:type" content="image/png" >`;
ogType = `<meta property="og:type" content="video" >`;
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType} ${ogVideo} ${ogVideoSecureUrl} ${ogVideoType}`);
} else {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="${source}" >
<meta property="og:image:type" content="${mimeType}" >
<meta property="og:image:width" content="600" >
<meta property="og:image:height" content="315" >
<meta property="og:type" content="article" >`
);
if (mimeType === 'image/gif') {
ogType = `<meta property="og:type" content="video.other" >`;
};
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType}`);
}
},
addTwitterCard (mimeType, source, embedUrl, directFileUrl) {
let basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
const basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
if (mimeType === 'video/mp4') {
return new Handlebars.SafeString(
`${basicTwitterTags} <meta name="twitter:card" content="player" >
<meta name="twitter:player" content="${embedUrl}>
<meta name="twitter:player:width" content="600" >
<meta name="twitter:text:player_width" content="600" >
<meta name="twitter:player:height" content="337" >
<meta name="twitter:player:stream" content="${directFileUrl}" >
<meta name="twitter:player:stream:content_type" content="video/mp4" >
`
);
const twitterName = '<meta name="twitter:card" content="player" >';
const twitterPlayer = `<meta name="twitter:player" content="${embedUrl}" >`;
const twitterPlayerWidth = '<meta name="twitter:player:width" content="600" >';
const twitterTextPlayerWidth = '<meta name="twitter:text:player_width" content="600" >';
const twitterPlayerHeight = '<meta name="twitter:player:height" content="337" >';
const twitterPlayerStream = `<meta name="twitter:player:stream" content="${directFileUrl}" >`;
const twitterPlayerStreamContentType = '<meta name="twitter:player:stream:content_type" content="video/mp4" >';
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterName} ${twitterPlayer} ${twitterPlayerWidth} ${twitterTextPlayerWidth} ${twitterPlayerHeight} ${twitterPlayerStream} ${twitterPlayerStreamContentType}`);
} else {
return new Handlebars.SafeString(
`${basicTwitterTags} <meta name="twitter:card" content="summary_large_image" >`
);
const twitterCard = '<meta name="twitter:card" content="summary_large_image" >';
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterCard}`);
}
},
ifConditional (varOne, operator, varTwo, options) {