Merge pull request #886 from lbryio/fix-oembed-data
Fix oEmbed data, remove bad og: data
This commit is contained in:
commit
02774bb958
3 changed files with 51 additions and 40 deletions
|
@ -4,22 +4,15 @@ import createMetaTagsArray from './createMetaTagsArray';
|
||||||
import createCanonicalLink from '@globalutils/createCanonicalLink';
|
import createCanonicalLink from '@globalutils/createCanonicalLink';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
details: {
|
details: { host, title: siteTitle, twitter },
|
||||||
host,
|
assetDefaults: { description: defaultDescription, thumbnail: defaultThumbnail },
|
||||||
title: siteTitle,
|
|
||||||
twitter,
|
|
||||||
},
|
|
||||||
assetDefaults: {
|
|
||||||
description: defaultDescription,
|
|
||||||
thumbnail: defaultThumbnail,
|
|
||||||
},
|
|
||||||
} = siteConfig;
|
} = siteConfig;
|
||||||
|
|
||||||
const VIDEO = 'VIDEO';
|
const VIDEO = 'VIDEO';
|
||||||
const IMAGE = 'IMAGE';
|
const IMAGE = 'IMAGE';
|
||||||
const GIF = 'GIF';
|
const GIF = 'GIF';
|
||||||
|
|
||||||
const determineMediaType = (contentType) => {
|
const determineMediaType = contentType => {
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'image/jpg':
|
case 'image/jpg':
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
|
@ -35,10 +28,12 @@ const determineMediaType = (contentType) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createAssetMetaTags = (asset) => {
|
const createAssetMetaTags = asset => {
|
||||||
const { claimData } = asset;
|
const { claimData } = asset;
|
||||||
const { contentType } = claimData;
|
const { contentType } = claimData;
|
||||||
const canonicalLink = createCanonicalLink({ asset: { ...asset.claimData, shortId: asset.shortId }});
|
const canonicalLink = createCanonicalLink({
|
||||||
|
asset: { ...asset.claimData, shortId: asset.shortId },
|
||||||
|
});
|
||||||
const showUrl = `${host}${canonicalLink}`;
|
const showUrl = `${host}${canonicalLink}`;
|
||||||
const serveUrl = `${showUrl}.${claimData.fileExt}`;
|
const serveUrl = `${showUrl}.${claimData.fileExt}`;
|
||||||
|
|
||||||
|
@ -46,16 +41,19 @@ const createAssetMetaTags = (asset) => {
|
||||||
const ogDescription = claimData.description || defaultDescription;
|
const ogDescription = claimData.description || defaultDescription;
|
||||||
const ogThumbnailContentType = determineContentTypeFromExtension(claimData.thumbnail);
|
const ogThumbnailContentType = determineContentTypeFromExtension(claimData.thumbnail);
|
||||||
const ogThumbnail = claimData.thumbnail || defaultThumbnail;
|
const ogThumbnail = claimData.thumbnail || defaultThumbnail;
|
||||||
|
|
||||||
|
console.log('asset.claimData', asset.claimData);
|
||||||
|
|
||||||
// {property: 'og:title'] = ogTitle},
|
// {property: 'og:title'] = ogTitle},
|
||||||
const metaTags = {
|
const metaTags = {
|
||||||
'og:title' : ogTitle,
|
'og:title': ogTitle,
|
||||||
'twitter:title' : ogTitle,
|
'twitter:title': ogTitle,
|
||||||
'og:description' : ogDescription,
|
'og:description': ogDescription,
|
||||||
'twitter:description': ogDescription,
|
'twitter:description': ogDescription,
|
||||||
'og:url' : showUrl,
|
'og:url': showUrl,
|
||||||
'og:site_name' : siteTitle,
|
'og:site_name': siteTitle,
|
||||||
'twitter:site' : twitter,
|
'twitter:site': twitter,
|
||||||
'fb:app_id' : '1371961932852223',
|
'fb:app_id': '1371961932852223',
|
||||||
};
|
};
|
||||||
if (determineMediaType(contentType) === VIDEO) {
|
if (determineMediaType(contentType) === VIDEO) {
|
||||||
const videoEmbedUrl = `${host}/video-embed${canonicalLink}`;
|
const videoEmbedUrl = `${host}/video-embed${canonicalLink}`;
|
||||||
|
@ -85,8 +83,6 @@ const createAssetMetaTags = (asset) => {
|
||||||
// image tags
|
// image tags
|
||||||
metaTags['og:image'] = serveUrl;
|
metaTags['og:image'] = serveUrl;
|
||||||
metaTags['og:image'] = serveUrl;
|
metaTags['og:image'] = serveUrl;
|
||||||
metaTags['og:image:width'] = 600;
|
|
||||||
metaTags['og:image:height'] = 315;
|
|
||||||
metaTags['og:image:type'] = contentType;
|
metaTags['og:image:type'] = contentType;
|
||||||
metaTags['twitter:image'] = serveUrl;
|
metaTags['twitter:image'] = serveUrl;
|
||||||
}
|
}
|
||||||
|
|
28
package-lock.json
generated
28
package-lock.json
generated
|
@ -5620,12 +5620,14 @@
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
|
@ -5640,17 +5642,20 @@
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
|
@ -5767,7 +5772,8 @@
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
|
@ -5779,6 +5785,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
@ -5793,6 +5800,7 @@
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
|
@ -5800,12 +5808,14 @@
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.1",
|
"safe-buffer": "^5.1.1",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "^3.0.0"
|
||||||
|
@ -5824,6 +5834,7 @@
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
|
@ -5904,7 +5915,8 @@
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
|
@ -5916,6 +5928,7 @@
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
|
@ -6037,6 +6050,7 @@
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
|
|
|
@ -3,19 +3,16 @@ const db = require('../../../models');
|
||||||
const getClaimId = require('../../utils/getClaimId');
|
const getClaimId = require('../../utils/getClaimId');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
details: {
|
details: { host, title: siteTitle },
|
||||||
host,
|
|
||||||
title: siteTitle,
|
|
||||||
},
|
|
||||||
} = require('@config/siteConfig');
|
} = require('@config/siteConfig');
|
||||||
|
|
||||||
const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId) => {
|
const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId) => {
|
||||||
let fileData, claimData;
|
let fileData, claimData;
|
||||||
let data = {
|
let data = {
|
||||||
version : '1.0',
|
version: '1.0',
|
||||||
provider_name: siteTitle,
|
provider_name: siteTitle,
|
||||||
provider_url : host,
|
provider_url: host,
|
||||||
cache_age : 86400, // one day in seconds
|
cache_age: 86400, // one day in seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
return getClaimId(channelName, channelClaimId, claimName, claimId)
|
return getClaimId(channelName, channelClaimId, claimName, claimId)
|
||||||
|
@ -23,7 +20,7 @@ const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId)
|
||||||
claimId = fullClaimId;
|
claimId = fullClaimId;
|
||||||
return db.Claim.findOne({
|
return db.Claim.findOne({
|
||||||
where: {
|
where: {
|
||||||
name : claimName,
|
name: claimName,
|
||||||
claimId: fullClaimId,
|
claimId: fullClaimId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -43,19 +40,23 @@ const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId)
|
||||||
.then(fileRecord => {
|
.then(fileRecord => {
|
||||||
fileData = fileRecord.dataValues;
|
fileData = fileRecord.dataValues;
|
||||||
logger.debug('file data:', fileData);
|
logger.debug('file data:', fileData);
|
||||||
const serveUrl = `${host}/${fileData.claimId}/${fileData.name}.${fileData.fileType.substring(fileData.fileType.indexOf('/') + 1)}`;
|
const serveUrl = `${host}/${fileData.claimId}/${fileData.name}.${fileData.fileType.substring(
|
||||||
|
fileData.fileType.indexOf('/') + 1
|
||||||
|
)}`;
|
||||||
// set the resource type
|
// set the resource type
|
||||||
if (fileData.fileType === 'video/mp4') {
|
if (fileData.fileType === 'video/mp4') {
|
||||||
data['type'] = 'video';
|
data['type'] = 'video';
|
||||||
data['html'] = `<video width="100%" controls poster="${claimData.thumbnail}" src="${serveUrl}"/></video>`;
|
data['html'] = `<video width="100%" controls poster="${
|
||||||
|
claimData.thumbnail
|
||||||
|
}" src="${serveUrl}"/></video>`;
|
||||||
} else {
|
} else {
|
||||||
data['type'] = 'picture';
|
data['type'] = 'picture';
|
||||||
data['url'] = serveUrl;
|
data['url'] = serveUrl;
|
||||||
}
|
}
|
||||||
// get the data
|
// get the data
|
||||||
data['title'] = claimData.title;
|
data['title'] = claimData.title;
|
||||||
data['width'] = fileData.width || 600;
|
data['width'] = fileData.fileWidth || 600;
|
||||||
data['height'] = fileData.height || 400;
|
data['height'] = fileData.fileHeight || 400;
|
||||||
data['author_name'] = siteTitle;
|
data['author_name'] = siteTitle;
|
||||||
data['author_url'] = host;
|
data['author_url'] = host;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue