2018-07-30 23:22:02 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
const db = require('../../../models');
|
|
|
|
const getClaimId = require('../../utils/getClaimId');
|
|
|
|
|
2018-07-31 18:20:56 +02:00
|
|
|
const {
|
2019-01-28 03:45:44 +01:00
|
|
|
details: { host, title: siteTitle },
|
2018-07-31 18:20:56 +02:00
|
|
|
} = require('@config/siteConfig');
|
|
|
|
|
2018-07-30 23:22:02 +02:00
|
|
|
const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId) => {
|
|
|
|
let fileData, claimData;
|
|
|
|
let data = {
|
2019-01-28 03:45:44 +01:00
|
|
|
version: '1.0',
|
2018-07-31 18:20:56 +02:00
|
|
|
provider_name: siteTitle,
|
2019-01-28 03:45:44 +01:00
|
|
|
provider_url: host,
|
|
|
|
cache_age: 86400, // one day in seconds
|
2018-07-30 23:22:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return getClaimId(channelName, channelClaimId, claimName, claimId)
|
|
|
|
.then(fullClaimId => {
|
|
|
|
claimId = fullClaimId;
|
|
|
|
return db.Claim.findOne({
|
|
|
|
where: {
|
2019-01-28 03:45:44 +01:00
|
|
|
name: claimName,
|
2018-07-30 23:22:02 +02:00
|
|
|
claimId: fullClaimId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(claimRecord => {
|
|
|
|
claimData = claimRecord.dataValues;
|
|
|
|
return db.Blocked.isNotBlocked(claimData.outpoint);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return db.File.findOne({
|
|
|
|
where: {
|
|
|
|
name: claimName,
|
|
|
|
claimId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(fileRecord => {
|
|
|
|
fileData = fileRecord.dataValues;
|
|
|
|
logger.debug('file data:', fileData);
|
2019-01-28 03:45:44 +01:00
|
|
|
const serveUrl = `${host}/${fileData.claimId}/${fileData.name}.${fileData.fileType.substring(
|
|
|
|
fileData.fileType.indexOf('/') + 1
|
|
|
|
)}`;
|
2018-07-30 23:22:02 +02:00
|
|
|
// set the resource type
|
|
|
|
if (fileData.fileType === 'video/mp4') {
|
|
|
|
data['type'] = 'video';
|
2019-01-28 03:45:44 +01:00
|
|
|
data['html'] = `<video width="100%" controls poster="${
|
|
|
|
claimData.thumbnail
|
|
|
|
}" src="${serveUrl}"/></video>`;
|
2018-07-30 23:22:02 +02:00
|
|
|
} else {
|
|
|
|
data['type'] = 'picture';
|
2018-07-31 00:23:26 +02:00
|
|
|
data['url'] = serveUrl;
|
2018-07-30 23:22:02 +02:00
|
|
|
}
|
|
|
|
// get the data
|
|
|
|
data['title'] = claimData.title;
|
2019-01-28 03:45:44 +01:00
|
|
|
data['width'] = fileData.fileWidth || 600;
|
|
|
|
data['height'] = fileData.fileHeight || 400;
|
2018-07-31 18:20:56 +02:00
|
|
|
data['author_name'] = siteTitle;
|
|
|
|
data['author_url'] = host;
|
2018-07-30 23:22:02 +02:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getOEmbedDataForAsset;
|